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 = () => {
5959 const [ responsive , setResponsive ] = React . useState ( true ) ;
6060 const [ inputValue , setInputValue ] = React . useState ( '' ) ;
6161 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 > ( ) ;
6364 const measureRef = React . useRef < HTMLDivElement > ( ) ;
6465
6566 React . useLayoutEffect ( ( ) => {
6667 setInputWidth ( measureRef . current . offsetWidth ) ;
6768 } , [ inputValue ] ) ;
6869
70+ React . useEffect ( ( ) => {
71+ inputRef . current . focus ( ) ;
72+ } , [ ] ) ;
73+
6974 return (
7075 < div style = { { padding : 32 } } >
7176 < button
@@ -117,9 +122,10 @@ const Demo = () => {
117122 maxWidth : '100%' ,
118123 } }
119124 value = { inputValue }
120- onChange = { ( e ) => {
125+ onChange = { e => {
121126 setInputValue ( e . target . value ) ;
122127 } }
128+ ref = { inputRef }
123129 />
124130 < div
125131 style = { {
You can’t perform that action at this time.
0 commit comments