Skip to content

Commit

Permalink
✨ Allow user to skip default styles (#416)
Browse files Browse the repository at this point in the history
* ✨ Allow user to skip default styles

* 🔖 v3.1.0
  • Loading branch information
prateek3255 authored Sep 26, 2023
1 parent 6084e4a commit 304cd54
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ const handlePaste: React.ClipboardEventHandler<HTMLDivElement> = (event) => {
<td>false</td>
<td>Auto focuses input on initial page load.</td>
</tr>
<tr>
<td>skipDefaultStyles</td>
<td>boolean</td>
<td>false</td>
<td>false</td>
<td>The component comes with default styles for legacy reasons. Pass <code>true</code> to skip those styles. This prop will be removed in the next major release.</td>
</tr>
</table>

### ⚠️ Warning
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-otp-input",
"version": "3.0.4",
"version": "3.1.0",
"description": "A fully customizable, one-time password input component for the web built with React",
"main": "lib/index.js",
"module": "lib/index.esm.js",
Expand Down
7 changes: 5 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ interface OTPInputProps {
inputStyle?: React.CSSProperties | string;
/** The type that will be passed to the input being rendered */
inputType?: AllowedInputTypes;
/** Do not apply the default styles to the inputs, will be removed in future versions */
skipDefaultStyles?: boolean; // TODO: Remove in next major release
}

const isStyleObject = (obj: unknown) => typeof obj === 'object' && obj !== null;
Expand All @@ -64,6 +66,7 @@ const OTPInput = ({
placeholder,
containerStyle,
inputStyle,
skipDefaultStyles = false,
}: OTPInputProps) => {
const [activeInput, setActiveInput] = React.useState(0);
const inputRefs = React.useRef<Array<HTMLInputElement | null>>([]);
Expand Down Expand Up @@ -238,8 +241,8 @@ const OTPInput = ({
maxLength: 1,
'aria-label': `Please enter OTP character ${index + 1}`,
style: Object.assign(
{ width: '1em', textAlign: 'center' } as const,
isStyleObject(inputStyle) && inputStyle
!skipDefaultStyles ? ({ width: '1em', textAlign: 'center' } as const) : {},
isStyleObject(inputStyle) ? inputStyle : {}
),
className: typeof inputStyle === 'string' ? inputStyle : undefined,
type: inputType,
Expand Down

0 comments on commit 304cd54

Please sign in to comment.