@@ -32,6 +32,7 @@ import { useIsoMorphicEffect } from '../../hooks/use-iso-morphic-effect'
32
32
import { useLatestValue } from '../../hooks/use-latest-value'
33
33
import { useOutsideClick } from '../../hooks/use-outside-click'
34
34
import { useOwnerDocument } from '../../hooks/use-owner'
35
+ import { useRefocusableInput } from '../../hooks/use-refocusable-input'
35
36
import { useResolveButtonType } from '../../hooks/use-resolve-button-type'
36
37
import { useSyncRefs } from '../../hooks/use-sync-refs'
37
38
import { useTrackedPointer } from '../../hooks/use-tracked-pointer'
@@ -1381,6 +1382,8 @@ function ButtonFn<TTag extends ElementType = typeof DEFAULT_BUTTON_TAG>(
1381
1382
} = props
1382
1383
let d = useDisposables ( )
1383
1384
1385
+ let refocusInput = useRefocusableInput ( data . inputRef )
1386
+
1384
1387
let handleKeyDown = useEvent ( ( event : ReactKeyboardEvent < HTMLUListElement > ) => {
1385
1388
switch ( event . key ) {
1386
1389
// Ref: https://www.w3.org/WAI/ARIA/apg/patterns/menu/#keyboard-interaction-12
@@ -1392,7 +1395,7 @@ function ButtonFn<TTag extends ElementType = typeof DEFAULT_BUTTON_TAG>(
1392
1395
actions . openCombobox ( )
1393
1396
}
1394
1397
1395
- return d . nextFrame ( ( ) => data . inputRef . current ?. focus ( { preventScroll : true } ) )
1398
+ return d . nextFrame ( ( ) => refocusInput ( ) )
1396
1399
1397
1400
case Keys . ArrowUp :
1398
1401
event . preventDefault ( )
@@ -1405,7 +1408,7 @@ function ButtonFn<TTag extends ElementType = typeof DEFAULT_BUTTON_TAG>(
1405
1408
}
1406
1409
} )
1407
1410
}
1408
- return d . nextFrame ( ( ) => data . inputRef . current ?. focus ( { preventScroll : true } ) )
1411
+ return d . nextFrame ( ( ) => refocusInput ( ) )
1409
1412
1410
1413
case Keys . Escape :
1411
1414
if ( data . comboboxState !== ComboboxState . Open ) return
@@ -1414,7 +1417,7 @@ function ButtonFn<TTag extends ElementType = typeof DEFAULT_BUTTON_TAG>(
1414
1417
event . stopPropagation ( )
1415
1418
}
1416
1419
actions . closeCombobox ( )
1417
- return d . nextFrame ( ( ) => data . inputRef . current ?. focus ( { preventScroll : true } ) )
1420
+ return d . nextFrame ( ( ) => refocusInput ( ) )
1418
1421
1419
1422
default :
1420
1423
return
@@ -1430,7 +1433,7 @@ function ButtonFn<TTag extends ElementType = typeof DEFAULT_BUTTON_TAG>(
1430
1433
actions . openCombobox ( )
1431
1434
}
1432
1435
1433
- d . nextFrame ( ( ) => data . inputRef . current ?. focus ( { preventScroll : true } ) )
1436
+ d . nextFrame ( ( ) => refocusInput ( ) )
1434
1437
} )
1435
1438
1436
1439
let labelledBy = useLabelledBy ( [ id ] )
@@ -1629,6 +1632,8 @@ function OptionFn<
1629
1632
let data = useData ( 'Combobox.Option' )
1630
1633
let actions = useActions ( 'Combobox.Option' )
1631
1634
1635
+ let refocusInput = useRefocusableInput ( data . inputRef )
1636
+
1632
1637
let active = data . virtual
1633
1638
? data . activeOptionIndex === data . calculateIndex ( value )
1634
1639
: data . activeOptionIndex === null
@@ -1701,7 +1706,7 @@ function OptionFn<
1701
1706
// But right now this is still an experimental feature:
1702
1707
// https://developer.mozilla.org/en-US/docs/Web/API/Navigator/virtualKeyboard
1703
1708
if ( ! isMobile ( ) ) {
1704
- requestAnimationFrame ( ( ) => data . inputRef . current ?. focus ( { preventScroll : true } ) )
1709
+ requestAnimationFrame ( ( ) => refocusInput ( ) )
1705
1710
}
1706
1711
1707
1712
if ( data . mode === ValueMode . Single ) {
0 commit comments