File tree Expand file tree Collapse file tree 1 file changed +9
-6
lines changed
Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -2,16 +2,19 @@ import { useEffect } from 'react'
22
33function useAutoFocusFirstInput ( ) : void {
44 useEffect ( ( ) => {
5- const focusFirstInput = ( element = document ) : void => {
5+ const focusFirstInput = ( element : Document ) : void => {
66 const firstInput = element . querySelector ( 'form input, form textarea, form select' )
77 firstInput ?. focus ( )
88 }
9- setTimeout ( ( ) => focusFirstInput ( ) , 0 )
109
11- const handleClick = ( ) : void => {
12- setTimeout ( ( ) => {
13- focusFirstInput ( document )
14- } , 100 )
10+ const handleClick = ( event : MouseEvent ) : void => {
11+ const target = event . target as HTMLElement
12+
13+ if ( target . tagName !== 'INPUT' && target . tagName !== 'TEXTAREA' && target . tagName !== 'SELECT' ) {
14+ setTimeout ( ( ) => {
15+ focusFirstInput ( document )
16+ } , 100 )
17+ }
1518 }
1619
1720 document . addEventListener ( 'click' , handleClick )
You can’t perform that action at this time.
0 commit comments