Skip to content

Commit 4bc8a44

Browse files
authored
Merge pull request #1615 from dxc-technology/gomezivann/focus-lock-fix
Focus Lock selectors update
2 parents 56a07ae + 561b594 commit 4bc8a44

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

lib/src/utils/FocusLock.tsx

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

33
const not = {
4-
inert: ":not([inert]):not([inert] *)",
54
negTabIndex: ':not([tabindex^="-"])',
65
disabled: ":not(:disabled)",
76
};
87
const focusableQuery = [
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}`,
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}`,
2120
].join(",");
2221

2322
const getFocusableElements = (container: HTMLElement): HTMLElement[] =>
@@ -44,7 +43,7 @@ const attempFocus = (element: HTMLElement): boolean => {
4443

4544
/**
4645
* @param element: HTMLElement
47-
* @returns boolean: true if element is contained inside a Radix Portal, false otherwise.
46+
* @returns boolean: true if element is contained inside a Radix Portal, false otherwise.
4847
*/
4948
const radixPortalContains = (activeElement: Element): boolean => {
5049
const radixPortals = document.querySelectorAll("[data-radix-portal]");
@@ -76,7 +75,6 @@ const useFocusableElements = (ref: React.MutableRefObject<HTMLDivElement>): HTML
7675
return focusableElements;
7776
};
7877

79-
8078
/**
8179
* Traps the focus inside the children of the component. It will focus the first focusable element when the component is mounted.
8280
* 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)