Skip to content

Commit f4a5bf6

Browse files
committed
feat: add inputProps prop
1 parent 2e056ee commit f4a5bf6

File tree

3 files changed

+42
-24
lines changed

3 files changed

+42
-24
lines changed

README.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,29 @@ export default function App() {
5151

5252
### Props
5353

54-
| Key | Type | Default | Required | Description |
55-
| ----------- | ------------------------ | ------------ | -------- | -------------------------------------------------- |
56-
| autoFocus | `boolean` | false | false | Should focus on first render |
57-
| length | `number` | `4` | false | How many inputs will be rendered |
58-
| onChange | `function` | `() => null` | false | Function called when the value changes |
59-
| onCompleted | `function` | `() => null` | false | Function called when the value is completed |
60-
| placeholder | `string` | `·` | false | Inputs placeholder |
61-
| value | `string` | `""` | false | Default value |
62-
| type | `'alphanumeric, number'` | `number` | false | Should accepts alphanumeric values or only numbers |
54+
| Key | Type | Default | Required | Description |
55+
| ----------- | ---------------------------------------------- | ------------ | -------- | -------------------------------------------------- |
56+
| autoFocus | `boolean` | false | false | Should focus on first render |
57+
| inputProps | `React.InputHTMLAttributes<HTMLInputElement>;` | `undefined` | false | Allow passing custom props into the inputs |
58+
| length | `number` | `4` | false | How many inputs will be rendered |
59+
| onChange | `function` | `() => null` | false | Function called when the value changes |
60+
| onCompleted | `function` | `() => null` | false | Function called when the value is completed |
61+
| placeholder | `string` | `·` | false | Inputs placeholder |
62+
| value | `string` | `""` | false | Default value |
63+
| type | `'alphanumeric, number'` | `number` | false | Should accepts alphanumeric values or only numbers |
6364

6465
### Custom Styles
6566

6667
Simply override the styles using the following classnames
6768

6869
```css
69-
.ReactInputVerificationCode-container {}
70-
.ReactInputVerificationCode-item {}
70+
.ReactInputVerificationCode-container {
71+
/* */
72+
}
73+
74+
.ReactInputVerificationCode-item {
75+
/* */
76+
}
7177
```
7278

7379
## License

src/index.stories.tsx

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ WithDefaultValue.args = {
2828
value: '7890',
2929
};
3030

31+
export const CustomInputProps = Template.bind({});
32+
CustomInputProps.args = {
33+
placeholder: '',
34+
inputProps: {
35+
type: 'password',
36+
},
37+
};
38+
3139
export const CustomLength = Template.bind({});
3240
CustomLength.args = {
3341
length: 6,
@@ -38,19 +46,6 @@ CustomPlaceholder.args = {
3846
placeholder: '⎽',
3947
};
4048

41-
export const CustomType = Template.bind({});
42-
CustomType.args = {
43-
type: 'alphanumeric',
44-
};
45-
CustomType.argTypes = {
46-
type: {
47-
control: {
48-
type: 'select',
49-
options: ['number', 'alphanumeric'],
50-
},
51-
},
52-
};
53-
5449
const CustomStylesContainer = styled.div`
5550
position: relative;
5651
@@ -79,3 +74,16 @@ export const CustomStyles = () => (
7974
<ReactInputVerificationCode autoFocus placeholder='' />
8075
</CustomStylesContainer>
8176
);
77+
78+
export const CustomType = Template.bind({});
79+
CustomType.args = {
80+
type: 'alphanumeric',
81+
};
82+
CustomType.argTypes = {
83+
type: {
84+
control: {
85+
type: 'select',
86+
options: ['number', 'alphanumeric'],
87+
},
88+
},
89+
};

src/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, {
22
ChangeEvent,
33
ClipboardEvent,
44
createRef,
5+
InputHTMLAttributes,
56
KeyboardEvent,
67
useEffect,
78
useMemo,
@@ -12,6 +13,7 @@ import './index.css';
1213

1314
export interface ReactInputVerificationCodeProps {
1415
autoFocus?: boolean;
16+
inputProps?: InputHTMLAttributes<HTMLInputElement>;
1517
length?: number;
1618
onChange?: (data: string) => void;
1719
onCompleted?: (data: string) => void;
@@ -22,6 +24,7 @@ export interface ReactInputVerificationCodeProps {
2224

2325
const ReactInputVerificationCode = ({
2426
autoFocus = false,
27+
inputProps,
2528
length = 4,
2629
onChange = () => null,
2730
onCompleted = () => null,
@@ -222,6 +225,7 @@ const ReactInputVerificationCode = ({
222225
placeholder={placeholder}
223226
ref={ref}
224227
value={values[i]}
228+
{...inputProps}
225229
/>
226230
))}
227231
</div>

0 commit comments

Comments
 (0)