File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -59,13 +59,18 @@ const Demo = () => {
59
59
const [ responsive , setResponsive ] = React . useState ( true ) ;
60
60
const [ inputValue , setInputValue ] = React . useState ( '' ) ;
61
61
const [ inputWidth , setInputWidth ] = React . useState ( 0 ) ;
62
- const [ data , setData ] = React . useState ( createData ( 1 ) ) ;
62
+ const [ data , setData ] = React . useState ( createData ( 3 ) ) ;
63
+ const inputRef = React . useRef < HTMLInputElement > ( ) ;
63
64
const measureRef = React . useRef < HTMLDivElement > ( ) ;
64
65
65
66
React . useLayoutEffect ( ( ) => {
66
67
setInputWidth ( measureRef . current . offsetWidth ) ;
67
68
} , [ inputValue ] ) ;
68
69
70
+ React . useEffect ( ( ) => {
71
+ inputRef . current . focus ( ) ;
72
+ } , [ ] ) ;
73
+
69
74
return (
70
75
< div style = { { padding : 32 } } >
71
76
< button
@@ -117,9 +122,10 @@ const Demo = () => {
117
122
maxWidth : '100%' ,
118
123
} }
119
124
value = { inputValue }
120
- onChange = { ( e ) => {
125
+ onChange = { e => {
121
126
setInputValue ( e . target . value ) ;
122
127
} }
128
+ ref = { inputRef }
123
129
/>
124
130
< div
125
131
style = { {
You can’t perform that action at this time.
0 commit comments