@@ -21,6 +21,7 @@ import { hideOthers } from 'aria-hidden';
21
21
import { RemoveScroll } from 'react-remove-scroll' ;
22
22
23
23
import type { Scope } from '@radix-ui/react-context' ;
24
+ import { getDeepActiveElement } from '@radix-ui/deep-active-element'
24
25
25
26
type Direction = 'ltr' | 'rtl' ;
26
27
@@ -397,7 +398,7 @@ const MenuContentImpl = React.forwardRef<MenuContentImplElement, MenuContentImpl
397
398
const handleTypeaheadSearch = ( key : string ) => {
398
399
const search = searchRef . current + key ;
399
400
const items = getItems ( ) . filter ( ( item ) => ! item . disabled ) ;
400
- const currentItem = document . activeElement ;
401
+ const currentItem = getDeepActiveElement ( ) ;
401
402
const currentMatch = items . find ( ( item ) => item . ref . current === currentItem ) ?. textValue ;
402
403
const values = items . map ( ( item ) => item . textValue ) ;
403
404
const nextMatch = getNextMatch ( values , search , currentMatch ) ;
@@ -1238,12 +1239,12 @@ function getCheckedState(checked: CheckedState) {
1238
1239
}
1239
1240
1240
1241
function focusFirst ( candidates : HTMLElement [ ] ) {
1241
- const PREVIOUSLY_FOCUSED_ELEMENT = document . activeElement ;
1242
+ const PREVIOUSLY_FOCUSED_ELEMENT = getDeepActiveElement ( ) ;
1242
1243
for ( const candidate of candidates ) {
1243
1244
// if focus is already where we want to go, we don't want to keep going through the candidates
1244
1245
if ( candidate === PREVIOUSLY_FOCUSED_ELEMENT ) return ;
1245
1246
candidate . focus ( ) ;
1246
- if ( document . activeElement !== PREVIOUSLY_FOCUSED_ELEMENT ) return ;
1247
+ if ( getDeepActiveElement ( ) !== PREVIOUSLY_FOCUSED_ELEMENT ) return ;
1247
1248
}
1248
1249
}
1249
1250
0 commit comments