Skip to content

Commit 590642e

Browse files
authored
Merge pull request #30 from LukeWlodarczyk/feature/hidden-input
feat: add type prop
2 parents c381a0a + 63e655f commit 590642e

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ export default function App() {
4848
| onCompleted | `function` | `() => {}` | false | Function called when the code is completed |
4949
| placeholder | `string` | `·` | false | String rendered in each item when no value has been typed |
5050
| value | `string` | `() => {}` | false | Control internal input value |
51+
| type | `text` or `password` | `text` | false | Display the item value or a password mask |
52+
| passwordMask | `string` | `` | false | Password mask |
5153

5254
### CSS Properties
5355

src/index.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ type Props = {
1717
placeholder?: string;
1818
value?: string;
1919
dataCy?: string;
20+
type?: 'text' | 'password';
21+
passwordMask?: string;
2022
};
2123

2224
const ReactInputVerificationCode = ({
@@ -26,7 +28,9 @@ const ReactInputVerificationCode = ({
2628
onCompleted = () => {},
2729
placeholder = '·',
2830
value: pValue,
29-
dataCy = 'verification-code'
31+
dataCy = 'verification-code',
32+
type = 'text',
33+
passwordMask = '•'
3034
}: Props) => {
3135
const emptyValue = new Array(length).fill(placeholder);
3236

@@ -167,6 +171,11 @@ const ReactInputVerificationCode = ({
167171
if (pValue !== value.join('')) setValue(pValue.split(''));
168172
}, [pValue]);
169173

174+
const renderItemText = (itemValue: string) => {
175+
if (itemValue === placeholder) return placeholder;
176+
return type === 'password' ? passwordMask : itemValue;
177+
};
178+
170179
return (
171180
<React.Fragment>
172181
<Global
@@ -214,7 +223,7 @@ const ReactInputVerificationCode = ({
214223
onFocus={onItemFocus(i)}
215224
data-cy={`${dataCy}-${i}-item`}
216225
>
217-
{value[i] || placeholder}
226+
{renderItemText(value[i])}
218227
</Item>
219228
))}
220229
</Container>

0 commit comments

Comments
 (0)