@@ -16,6 +16,7 @@ import { useCallbackRef } from '@radix-ui/react-use-callback-ref';
16
16
import * as VisuallyHiddenPrimitive from '@radix-ui/react-visually-hidden' ;
17
17
18
18
import type { Scope } from '@radix-ui/react-context' ;
19
+ import { getDeepActiveElement } from '@radix-ui/deep-active-element'
19
20
20
21
type Orientation = 'vertical' | 'horizontal' ;
21
22
type Direction = 'ltr' | 'rtl' ;
@@ -875,7 +876,7 @@ const NavigationMenuContentImpl = React.forwardRef<
875
876
const handleClose = ( ) => {
876
877
onItemDismiss ( ) ;
877
878
onRootContentClose ( ) ;
878
- if ( content . contains ( document . activeElement ) ) triggerRef . current ?. focus ( ) ;
879
+ if ( content . contains ( getDeepActiveElement ( ) ) ) triggerRef . current ?. focus ( ) ;
879
880
} ;
880
881
content . addEventListener ( ROOT_CONTENT_DISMISS , handleClose ) ;
881
882
return ( ) => content . removeEventListener ( ROOT_CONTENT_DISMISS , handleClose ) ;
@@ -946,7 +947,7 @@ const NavigationMenuContentImpl = React.forwardRef<
946
947
const isTabKey = event . key === 'Tab' && ! isMetaKey ;
947
948
if ( isTabKey ) {
948
949
const candidates = getTabbableCandidates ( event . currentTarget ) ;
949
- const focusedElement = document . activeElement ;
950
+ const focusedElement = getDeepActiveElement ( ) ;
950
951
const index = candidates . findIndex ( ( candidate ) => candidate === focusedElement ) ;
951
952
const isMovingBackwards = event . shiftKey ;
952
953
const nextCandidates = isMovingBackwards
@@ -1175,12 +1176,12 @@ function getTabbableCandidates(container: HTMLElement) {
1175
1176
}
1176
1177
1177
1178
function focusFirst ( candidates : HTMLElement [ ] ) {
1178
- const previouslyFocusedElement = document . activeElement ;
1179
+ const previouslyFocusedElement = getDeepActiveElement ( ) ;
1179
1180
return candidates . some ( ( candidate ) => {
1180
1181
// if focus is already where we want to go, we don't want to keep going through the candidates
1181
1182
if ( candidate === previouslyFocusedElement ) return true ;
1182
1183
candidate . focus ( ) ;
1183
- return document . activeElement !== previouslyFocusedElement ;
1184
+ return getDeepActiveElement ( ) !== previouslyFocusedElement ;
1184
1185
} ) ;
1185
1186
}
1186
1187
0 commit comments