Skip to content

Commit 304cd54

Browse files
authored
✨ Allow user to skip default styles (#416)
* ✨ Allow user to skip default styles * 🔖 v3.1.0
1 parent 6084e4a commit 304cd54

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,13 @@ const handlePaste: React.ClipboardEventHandler<HTMLDivElement> = (event) => {
145145
<td>false</td>
146146
<td>Auto focuses input on initial page load.</td>
147147
</tr>
148+
<tr>
149+
<td>skipDefaultStyles</td>
150+
<td>boolean</td>
151+
<td>false</td>
152+
<td>false</td>
153+
<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>
154+
</tr>
148155
</table>
149156

150157
### ⚠️ Warning

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-otp-input",
3-
"version": "3.0.4",
3+
"version": "3.1.0",
44
"description": "A fully customizable, one-time password input component for the web built with React",
55
"main": "lib/index.js",
66
"module": "lib/index.esm.js",

src/index.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ interface OTPInputProps {
4848
inputStyle?: React.CSSProperties | string;
4949
/** The type that will be passed to the input being rendered */
5050
inputType?: AllowedInputTypes;
51+
/** Do not apply the default styles to the inputs, will be removed in future versions */
52+
skipDefaultStyles?: boolean; // TODO: Remove in next major release
5153
}
5254

5355
const isStyleObject = (obj: unknown) => typeof obj === 'object' && obj !== null;
@@ -64,6 +66,7 @@ const OTPInput = ({
6466
placeholder,
6567
containerStyle,
6668
inputStyle,
69+
skipDefaultStyles = false,
6770
}: OTPInputProps) => {
6871
const [activeInput, setActiveInput] = React.useState(0);
6972
const inputRefs = React.useRef<Array<HTMLInputElement | null>>([]);
@@ -238,8 +241,8 @@ const OTPInput = ({
238241
maxLength: 1,
239242
'aria-label': `Please enter OTP character ${index + 1}`,
240243
style: Object.assign(
241-
{ width: '1em', textAlign: 'center' } as const,
242-
isStyleObject(inputStyle) && inputStyle
244+
!skipDefaultStyles ? ({ width: '1em', textAlign: 'center' } as const) : {},
245+
isStyleObject(inputStyle) ? inputStyle : {}
243246
),
244247
className: typeof inputStyle === 'string' ? inputStyle : undefined,
245248
type: inputType,

0 commit comments

Comments
 (0)