File tree Expand file tree Collapse file tree 3 files changed +17
-7
lines changed Expand file tree Collapse file tree 3 files changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -46,12 +46,13 @@ export default function App() {
46
46
47
47
### Props
48
48
49
- | Key | Type | Default | Required | Description |
50
- | ----------- | ---------- | ------- | -------- | --------------------------------------------------------- |
51
- | length | ` number ` | ` 4 ` | false | How many items will be rendered |
52
- | onChange | ` function ` | | true | Function called when the value changes |
53
- | placeholder | ` string ` | ` · ` | false | String rendered in each item when no value has been typed |
54
- | value | ` string ` | | false | Control internal input value |
49
+ | Key | Type | Default | Required | Description |
50
+ | ----------- | ---------- | ---------- | -------- | --------------------------------------------------------- |
51
+ | autoFocus | ` boolean ` | false | false | Focus on render |
52
+ | length | ` number ` | ` 4 ` | false | How many items will be rendered |
53
+ | onChange | ` function ` | ` () => {} ` | true | Function called when the value changes |
54
+ | placeholder | ` string ` | ` · ` | false | String rendered in each item when no value has been typed |
55
+ | value | ` string ` | ` () => {} ` | false | Control internal input value |
55
56
56
57
### CSS Properties
57
58
Original file line number Diff line number Diff line change @@ -5,6 +5,6 @@ import ReactInputVerificationCode from 'react-input-verification-code';
5
5
import './index.css' ;
6
6
7
7
ReactDOM . render (
8
- < ReactInputVerificationCode onChange = { console . log } /> ,
8
+ < ReactInputVerificationCode autoFocus onChange = { console . log } /> ,
9
9
document . getElementById ( 'root' )
10
10
) ;
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ const KEY_CODE = {
10
10
} ;
11
11
12
12
type Props = {
13
+ autoFocus ?: boolean ;
13
14
length ?: number ;
14
15
onChange ?: ( data : string ) => any ;
15
16
onCompleted ?: ( data : string ) => any ;
@@ -18,6 +19,7 @@ type Props = {
18
19
} ;
19
20
20
21
const ReactInputVerificationCode = ( {
22
+ autoFocus = false ,
21
23
length = 4 ,
22
24
onChange = ( ) => { } ,
23
25
onCompleted = ( ) => { } ,
@@ -119,6 +121,13 @@ const ReactInputVerificationCode = ({
119
121
setActiveIndex ( - 1 ) ;
120
122
} ;
121
123
124
+ // autoFocus
125
+ React . useEffect ( ( ) => {
126
+ if ( autoFocus && itemsRef [ 0 ] . current ) {
127
+ itemsRef [ 0 ] . current . focus ( ) ;
128
+ }
129
+ } , [ ] ) ;
130
+
122
131
// handle pasting
123
132
React . useEffect ( ( ) => {
124
133
const codeInput = codeInputRef . current ;
You can’t perform that action at this time.
0 commit comments