Skip to content

Commit 56a07ae

Browse files
committed
Revert "Focus Lock selectors updated"
This reverts commit 456a6f5.
1 parent 456a6f5 commit 56a07ae

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

app/package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/utils/FocusLock.tsx

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
import React, { useCallback, useEffect, useRef, useState } from "react";
22

33
const not = {
4+
inert: ":not([inert]):not([inert] *)",
45
negTabIndex: ':not([tabindex^="-"])',
56
disabled: ":not(:disabled)",
67
};
78
const 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

2223
const 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
*/
4849
const 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

Comments
 (0)