@@ -14,6 +14,7 @@ import { useLayoutEffect } from '@radix-ui/react-use-layout-effect';
1414import { VisuallyHidden } from '@radix-ui/react-visually-hidden' ;
1515
1616import type { Scope } from '@radix-ui/react-context' ;
17+ import { getDeepActiveElement } from '@radix-ui/deep-active-element'
1718
1819/* -------------------------------------------------------------------------------------------------
1920 * ToastProvider
@@ -193,7 +194,7 @@ const ToastViewport = React.forwardRef<ToastViewportElement, ToastViewportProps>
193194 } ;
194195
195196 const handlePointerLeaveResume = ( ) => {
196- const isFocusInside = wrapper . contains ( document . activeElement ) ;
197+ const isFocusInside = wrapper . contains ( getDeepActiveElement ( ) ) ;
197198 if ( ! isFocusInside ) handleResume ( ) ;
198199 } ;
199200
@@ -243,7 +244,7 @@ const ToastViewport = React.forwardRef<ToastViewportElement, ToastViewportProps>
243244 const isTabKey = event . key === 'Tab' && ! isMetaKey ;
244245
245246 if ( isTabKey ) {
246- const focusedElement = document . activeElement ;
247+ const focusedElement = getDeepActiveElement ( ) ;
247248 const isTabbingBackwards = event . shiftKey ;
248249 const targetIsViewport = event . target === viewport ;
249250
@@ -491,7 +492,7 @@ const ToastImpl = React.forwardRef<ToastImplElement, ToastImplProps>(
491492 const handleClose = useCallbackRef ( ( ) => {
492493 // focus viewport if focus is within toast to read the remaining toast
493494 // count to SR users and ensure focus isn't lost
494- const isFocusInToast = node ?. contains ( document . activeElement ) ;
495+ const isFocusInToast = node ?. contains ( getDeepActiveElement ( ) ) ;
495496 if ( isFocusInToast ) context . viewport ?. focus ( ) ;
496497 onClose ( ) ;
497498 } ) ;
@@ -935,12 +936,12 @@ function getTabbableCandidates(container: HTMLElement) {
935936}
936937
937938function focusFirst ( candidates : HTMLElement [ ] ) {
938- const previouslyFocusedElement = document . activeElement ;
939+ const previouslyFocusedElement = getDeepActiveElement ( ) ;
939940 return candidates . some ( ( candidate ) => {
940941 // if focus is already where we want to go, we don't want to keep going through the candidates
941942 if ( candidate === previouslyFocusedElement ) return true ;
942943 candidate . focus ( ) ;
943- return document . activeElement !== previouslyFocusedElement ;
944+ return getDeepActiveElement ( ) !== previouslyFocusedElement ;
944945 } ) ;
945946}
946947
0 commit comments