@@ -14,6 +14,7 @@ import { useLayoutEffect } from '@radix-ui/react-use-layout-effect';
14
14
import { VisuallyHidden } from '@radix-ui/react-visually-hidden' ;
15
15
16
16
import type { Scope } from '@radix-ui/react-context' ;
17
+ import { getDeepActiveElement } from '@radix-ui/deep-active-element'
17
18
18
19
/* -------------------------------------------------------------------------------------------------
19
20
* ToastProvider
@@ -193,7 +194,7 @@ const ToastViewport = React.forwardRef<ToastViewportElement, ToastViewportProps>
193
194
} ;
194
195
195
196
const handlePointerLeaveResume = ( ) => {
196
- const isFocusInside = wrapper . contains ( document . activeElement ) ;
197
+ const isFocusInside = wrapper . contains ( getDeepActiveElement ( ) ) ;
197
198
if ( ! isFocusInside ) handleResume ( ) ;
198
199
} ;
199
200
@@ -243,7 +244,7 @@ const ToastViewport = React.forwardRef<ToastViewportElement, ToastViewportProps>
243
244
const isTabKey = event . key === 'Tab' && ! isMetaKey ;
244
245
245
246
if ( isTabKey ) {
246
- const focusedElement = document . activeElement ;
247
+ const focusedElement = getDeepActiveElement ( ) ;
247
248
const isTabbingBackwards = event . shiftKey ;
248
249
const targetIsViewport = event . target === viewport ;
249
250
@@ -491,7 +492,7 @@ const ToastImpl = React.forwardRef<ToastImplElement, ToastImplProps>(
491
492
const handleClose = useCallbackRef ( ( ) => {
492
493
// focus viewport if focus is within toast to read the remaining toast
493
494
// count to SR users and ensure focus isn't lost
494
- const isFocusInToast = node ?. contains ( document . activeElement ) ;
495
+ const isFocusInToast = node ?. contains ( getDeepActiveElement ( ) ) ;
495
496
if ( isFocusInToast ) context . viewport ?. focus ( ) ;
496
497
onClose ( ) ;
497
498
} ) ;
@@ -935,12 +936,12 @@ function getTabbableCandidates(container: HTMLElement) {
935
936
}
936
937
937
938
function focusFirst ( candidates : HTMLElement [ ] ) {
938
- const previouslyFocusedElement = document . activeElement ;
939
+ const previouslyFocusedElement = getDeepActiveElement ( ) ;
939
940
return candidates . some ( ( candidate ) => {
940
941
// if focus is already where we want to go, we don't want to keep going through the candidates
941
942
if ( candidate === previouslyFocusedElement ) return true ;
942
943
candidate . focus ( ) ;
943
- return document . activeElement !== previouslyFocusedElement ;
944
+ return getDeepActiveElement ( ) !== previouslyFocusedElement ;
944
945
} ) ;
945
946
}
946
947
0 commit comments