11import React , { useCallback , useEffect , useRef , useState } from "react" ;
22
33const not = {
4+ inert : ":not([inert]):not([inert] *)" ,
45 negTabIndex : ':not([tabindex^="-"])' ,
56 disabled : ":not(:disabled)" ,
67} ;
78const focusableQuery = [
8- `a[href]${ not . negTabIndex } ` ,
9- `area[href]${ not . negTabIndex } ` ,
10- `input:not([type="hidden"])${ not . negTabIndex } ${ not . disabled } ` ,
11- `select${ not . negTabIndex } ${ not . disabled } ` ,
12- `textarea${ not . negTabIndex } ${ not . disabled } ` ,
13- `button${ not . negTabIndex } ${ not . disabled } ` ,
14- `details > summary:first-of-type${ not . negTabIndex } ` ,
15- `iframe${ not . negTabIndex } ` ,
16- `audio[controls]${ not . negTabIndex } ` ,
17- `video[controls]${ not . negTabIndex } ` ,
18- `[contenteditable]${ not . negTabIndex } ` ,
19- `[tabindex]${ not . negTabIndex } ${ not . disabled } ` ,
9+ `a[href]${ not . inert } ${ not . negTabIndex } ` ,
10+ `area[href]${ not . inert } ${ not . negTabIndex } ` ,
11+ `input:not([type="hidden"])${ not . inert } ${ not . negTabIndex } ${ not . disabled } ` ,
12+ `select${ not . inert } ${ not . negTabIndex } ${ not . disabled } ` ,
13+ `textarea${ not . inert } ${ not . negTabIndex } ${ not . disabled } ` ,
14+ `button${ not . inert } ${ not . negTabIndex } ${ not . disabled } ` ,
15+ `details${ not . inert } > summary:first-of-type${ not . negTabIndex } ` ,
16+ `iframe${ not . inert } ${ not . negTabIndex } ` ,
17+ `audio[controls]${ not . inert } ${ not . negTabIndex } ` ,
18+ `video[controls]${ not . inert } ${ not . negTabIndex } ` ,
19+ `[contenteditable]${ not . inert } ${ not . negTabIndex } ` ,
20+ `[tabindex]${ not . inert } ${ not . negTabIndex } ${ not . disabled } ` ,
2021] . join ( "," ) ;
2122
2223const getFocusableElements = ( container : HTMLElement ) : HTMLElement [ ] =>
@@ -43,7 +44,7 @@ const attempFocus = (element: HTMLElement): boolean => {
4344
4445/**
4546 * @param element: HTMLElement
46- * @returns boolean: true if element is contained inside a Radix Portal, false otherwise.
47+ * @returns boolean: true if element is contained inside a Radix Portal, false otherwise.
4748 */
4849const radixPortalContains = ( activeElement : Element ) : boolean => {
4950 const radixPortals = document . querySelectorAll ( "[data-radix-portal]" ) ;
@@ -75,6 +76,7 @@ const useFocusableElements = (ref: React.MutableRefObject<HTMLDivElement>): HTML
7576 return focusableElements ;
7677} ;
7778
79+
7880/**
7981 * Traps the focus inside the children of the component. It will focus the first focusable element when the component is mounted.
8082 * When the focus is on the last focusable element and the user tries to focus the next element, it will focus the first element.
0 commit comments