Skip to content
This repository was archived by the owner on Nov 3, 2024. It is now read-only.

Commit 59fe252

Browse files
authored
Merge pull request #49 from drac94/feature/placeholder
Add placeholder prop
2 parents 472f691 + 4c9ad5e commit 59fe252

File tree

6 files changed

+96
-74
lines changed

6 files changed

+96
-74
lines changed

Diff for: dist/index.js

+6-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: dist/index.modern.js

+73-62
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: dist/index.modern.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/index.test.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ describe('AuthCode', () => {
1515
expect(inputs[0]).toHaveFocus();
1616
});
1717

18+
it('should display a placeholder if passed as prop', () => {
19+
render(<AuthCode onChange={() => null} placeholder='*' />);
20+
const inputs = screen.getAllByPlaceholderText('*');
21+
expect(inputs).toHaveLength(6);
22+
});
23+
1824
it('should render the component but not focus the first input', () => {
1925
render(<AuthCode autoFocus={false} onChange={() => null} />);
2026
const inputs = screen.getAllByRole('textbox');

Diff for: src/index.tsx

+9-6
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ import React, {
77

88
const allowedCharactersValues = ['alpha', 'numeric', 'alphanumeric'] as const;
99

10-
type Props = {
10+
export type AuthCodeProps = {
1111
allowedCharacters?: typeof allowedCharactersValues[number];
1212
ariaLabel?: string;
1313
autoFocus?: boolean;
14-
disabled?: boolean;
15-
length?: number;
1614
containerClassName?: string;
15+
disabled?: boolean;
1716
inputClassName?: string;
1817
isPassword?: boolean;
18+
length?: number;
19+
placeholder?: string;
1920
onChange: (res: string) => void;
2021
};
2122

@@ -58,17 +59,18 @@ const propsMap: { [key: string]: InputProps } = {
5859
}
5960
};
6061

61-
const AuthCode = forwardRef<AuthCodeRef, Props>(
62+
const AuthCode = forwardRef<AuthCodeRef, AuthCodeProps>(
6263
(
6364
{
6465
allowedCharacters = 'alphanumeric',
6566
ariaLabel,
6667
autoFocus = true,
67-
disabled,
68-
length = 6,
6968
containerClassName,
69+
disabled,
7070
inputClassName,
7171
isPassword = false,
72+
length = 6,
73+
placeholder,
7274
onChange
7375
},
7476
ref
@@ -204,6 +206,7 @@ const AuthCode = forwardRef<AuthCodeRef, Props>(
204206
: `Character ${i + 1}.`
205207
}
206208
disabled={disabled}
209+
placeholder={placeholder}
207210
/>
208211
);
209212
}

0 commit comments

Comments
 (0)