1010 * governing permissions and limitations under the License.
1111 */
1212
13- import { chain , getScrollParent , isFocusWithin , mergeProps , nodeContains , scrollIntoViewport , useSlotId , useSyntheticLinkProps } from '@react-aria/utils' ;
13+ import { chain , getActiveElement , getScrollParent , isFocusWithin , mergeProps , nodeContains , scrollIntoViewport , useSlotId , useSyntheticLinkProps } from '@react-aria/utils' ;
1414import { DOMAttributes , FocusableElement , Key , RefObject , Node as RSNode } from '@react-types/shared' ;
1515import { focusSafely , getFocusableTreeWalker } from '@react-aria/focus' ;
1616import { getRowId , listMap } from './utils' ;
@@ -131,14 +131,15 @@ export function useGridListItem<T>(props: AriaGridListItemOptions, state: ListSt
131131 } ) ;
132132
133133 let onKeyDownCapture = ( e : ReactKeyboardEvent ) => {
134- if ( ! nodeContains ( e . currentTarget , e . target as Element ) || ! ref . current || ! document . activeElement ) {
134+ let activeElement = getActiveElement ( ) ;
135+ if ( ! nodeContains ( e . currentTarget , e . target as Element ) || ! ref . current || ! activeElement ) {
135136 return ;
136137 }
137138
138139 let walker = getFocusableTreeWalker ( ref . current ) ;
139- walker . currentNode = document . activeElement ;
140+ walker . currentNode = activeElement ;
140141
141- if ( 'expandedKeys' in state && document . activeElement === ref . current ) {
142+ if ( 'expandedKeys' in state && activeElement === ref . current ) {
142143 if ( ( e . key === EXPANSION_KEYS [ 'expand' ] [ direction ] ) && state . selectionManager . focusedKey === node . key && hasChildRows && ! state . expandedKeys . has ( node . key ) ) {
143144 state . toggleKey ( node . key ) ;
144145 e . stopPropagation ( ) ;
@@ -244,7 +245,8 @@ export function useGridListItem<T>(props: AriaGridListItemOptions, state: ListSt
244245 } ;
245246
246247 let onKeyDown = ( e ) => {
247- if ( ! nodeContains ( e . currentTarget , e . target as Element ) || ! ref . current || ! document . activeElement ) {
248+ let activeElement = getActiveElement ( ) ;
249+ if ( ! nodeContains ( e . currentTarget , e . target as Element ) || ! ref . current || ! activeElement ) {
248250 return ;
249251 }
250252
@@ -254,7 +256,7 @@ export function useGridListItem<T>(props: AriaGridListItemOptions, state: ListSt
254256 // If there is another focusable element within this item, stop propagation so the tab key
255257 // is handled by the browser and not by useSelectableCollection (which would take us out of the list).
256258 let walker = getFocusableTreeWalker ( ref . current , { tabbable : true } ) ;
257- walker . currentNode = document . activeElement ;
259+ walker . currentNode = activeElement ;
258260 let next = e . shiftKey ? walker . previousNode ( ) : walker . nextNode ( ) ;
259261
260262 if ( next ) {
0 commit comments