@@ -24,6 +24,7 @@ import { hideOthers } from 'aria-hidden';
24
24
import { RemoveScroll } from 'react-remove-scroll' ;
25
25
26
26
import type { Scope } from '@radix-ui/react-context' ;
27
+ import { getDeepActiveElement } from '@radix-ui/deep-active-element'
27
28
28
29
type Direction = 'ltr' | 'rtl' ;
29
30
@@ -583,7 +584,7 @@ const SelectContentImpl = React.forwardRef<SelectContentImplElement, SelectConte
583
584
const [ firstItem , ...restItems ] = getItems ( ) . map ( ( item ) => item . ref . current ) ;
584
585
const [ lastItem ] = restItems . slice ( - 1 ) ;
585
586
586
- const PREVIOUSLY_FOCUSED_ELEMENT = document . activeElement ;
587
+ const PREVIOUSLY_FOCUSED_ELEMENT = getDeepActiveElement ( ) ;
587
588
for ( const candidate of candidates ) {
588
589
// if focus is already where we want to go, we don't want to keep going through the candidates
589
590
if ( candidate === PREVIOUSLY_FOCUSED_ELEMENT ) return ;
@@ -592,7 +593,7 @@ const SelectContentImpl = React.forwardRef<SelectContentImplElement, SelectConte
592
593
if ( candidate === firstItem && viewport ) viewport . scrollTop = 0 ;
593
594
if ( candidate === lastItem && viewport ) viewport . scrollTop = viewport . scrollHeight ;
594
595
candidate ?. focus ( ) ;
595
- if ( document . activeElement !== PREVIOUSLY_FOCUSED_ELEMENT ) return ;
596
+ if ( getDeepActiveElement ( ) !== PREVIOUSLY_FOCUSED_ELEMENT ) return ;
596
597
}
597
598
} ,
598
599
[ getItems , viewport ]
@@ -662,7 +663,7 @@ const SelectContentImpl = React.forwardRef<SelectContentImplElement, SelectConte
662
663
663
664
const [ searchRef , handleTypeaheadSearch ] = useTypeaheadSearch ( ( search ) => {
664
665
const enabledItems = getItems ( ) . filter ( ( item ) => ! item . disabled ) ;
665
- const currentItem = enabledItems . find ( ( item ) => item . ref . current === document . activeElement ) ;
666
+ const currentItem = enabledItems . find ( ( item ) => item . ref . current === getDeepActiveElement ( ) ) ;
666
667
const nextItem = findNextItem ( enabledItems , search , currentItem ) ;
667
668
if ( nextItem ) {
668
669
/**
@@ -1335,7 +1336,7 @@ const SelectItem = React.forwardRef<SelectItemElement, SelectItemProps>(
1335
1336
}
1336
1337
} ) }
1337
1338
onPointerLeave = { composeEventHandlers ( itemProps . onPointerLeave , ( event ) => {
1338
- if ( event . currentTarget === document . activeElement ) {
1339
+ if ( event . currentTarget === getDeepActiveElement ( ) ) {
1339
1340
contentContext . onItemLeave ?.( ) ;
1340
1341
}
1341
1342
} ) }
@@ -1559,7 +1560,7 @@ const SelectScrollButtonImpl = React.forwardRef<
1559
1560
// the viewport, potentially causing the active item to now be partially out of view.
1560
1561
// We re-run the `scrollIntoView` logic to make sure it stays within the viewport.
1561
1562
useLayoutEffect ( ( ) => {
1562
- const activeItem = getItems ( ) . find ( ( item ) => item . ref . current === document . activeElement ) ;
1563
+ const activeItem = getItems ( ) . find ( ( item ) => item . ref . current === getDeepActiveElement ( ) ) ;
1563
1564
activeItem ?. ref . current ?. scrollIntoView ( { block : 'nearest' } ) ;
1564
1565
} , [ getItems ] ) ;
1565
1566
0 commit comments