@@ -24,6 +24,7 @@ import { hideOthers } from 'aria-hidden';
2424import { RemoveScroll } from 'react-remove-scroll' ;
2525
2626import type { Scope } from '@radix-ui/react-context' ;
27+ import { getDeepActiveElement } from '@radix-ui/deep-active-element'
2728
2829type Direction = 'ltr' | 'rtl' ;
2930
@@ -583,7 +584,7 @@ const SelectContentImpl = React.forwardRef<SelectContentImplElement, SelectConte
583584 const [ firstItem , ...restItems ] = getItems ( ) . map ( ( item ) => item . ref . current ) ;
584585 const [ lastItem ] = restItems . slice ( - 1 ) ;
585586
586- const PREVIOUSLY_FOCUSED_ELEMENT = document . activeElement ;
587+ const PREVIOUSLY_FOCUSED_ELEMENT = getDeepActiveElement ( ) ;
587588 for ( const candidate of candidates ) {
588589 // if focus is already where we want to go, we don't want to keep going through the candidates
589590 if ( candidate === PREVIOUSLY_FOCUSED_ELEMENT ) return ;
@@ -592,7 +593,7 @@ const SelectContentImpl = React.forwardRef<SelectContentImplElement, SelectConte
592593 if ( candidate === firstItem && viewport ) viewport . scrollTop = 0 ;
593594 if ( candidate === lastItem && viewport ) viewport . scrollTop = viewport . scrollHeight ;
594595 candidate ?. focus ( ) ;
595- if ( document . activeElement !== PREVIOUSLY_FOCUSED_ELEMENT ) return ;
596+ if ( getDeepActiveElement ( ) !== PREVIOUSLY_FOCUSED_ELEMENT ) return ;
596597 }
597598 } ,
598599 [ getItems , viewport ]
@@ -662,7 +663,7 @@ const SelectContentImpl = React.forwardRef<SelectContentImplElement, SelectConte
662663
663664 const [ searchRef , handleTypeaheadSearch ] = useTypeaheadSearch ( ( search ) => {
664665 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 ( ) ) ;
666667 const nextItem = findNextItem ( enabledItems , search , currentItem ) ;
667668 if ( nextItem ) {
668669 /**
@@ -1335,7 +1336,7 @@ const SelectItem = React.forwardRef<SelectItemElement, SelectItemProps>(
13351336 }
13361337 } ) }
13371338 onPointerLeave = { composeEventHandlers ( itemProps . onPointerLeave , ( event ) => {
1338- if ( event . currentTarget === document . activeElement ) {
1339+ if ( event . currentTarget === getDeepActiveElement ( ) ) {
13391340 contentContext . onItemLeave ?.( ) ;
13401341 }
13411342 } ) }
@@ -1559,7 +1560,7 @@ const SelectScrollButtonImpl = React.forwardRef<
15591560 // the viewport, potentially causing the active item to now be partially out of view.
15601561 // We re-run the `scrollIntoView` logic to make sure it stays within the viewport.
15611562 useLayoutEffect ( ( ) => {
1562- const activeItem = getItems ( ) . find ( ( item ) => item . ref . current === document . activeElement ) ;
1563+ const activeItem = getItems ( ) . find ( ( item ) => item . ref . current === getDeepActiveElement ( ) ) ;
15631564 activeItem ?. ref . current ?. scrollIntoView ( { block : 'nearest' } ) ;
15641565 } , [ getItems ] ) ;
15651566
0 commit comments