Skip to content

Commit 92a83d9

Browse files
authored
fix: prevent double focus rings in table when clicking on expand buttons (adobe#9861)
include visually hidden elements in preventFocus so we get the right target the browser tries to focus. this allows us to properly refocus the original element when the user presses on a preventFocusOnPress element, fixing the broken flow that useFocusRing and useFocus had when trying to update the focused state of a row when focus moves due to a click on the expand button.
1 parent 352fa19 commit 92a83d9

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

packages/react-aria/src/interactions/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export let ignoreFocusEvent = false;
109109
*/
110110
export function preventFocus(target: FocusableElement | null): (() => void) | undefined {
111111
// The browser will focus the nearest focusable ancestor of our target.
112-
while (target && !isFocusable(target)) {
112+
while (target && !isFocusable(target, {skipVisibilityCheck: true})) {
113113
target = target.parentElement;
114114
}
115115

packages/react-aria/src/utils/isFocusable.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ const FOCUSABLE_ELEMENT_SELECTOR = focusableElements.join(':not([hidden]),') + '
3434
focusableElements.push('[tabindex]:not([tabindex="-1"]):not([disabled])');
3535
const TABBABLE_ELEMENT_SELECTOR = focusableElements.join(':not([hidden]):not([tabindex="-1"]),');
3636

37-
export function isFocusable(element: Element): boolean {
38-
return element.matches(FOCUSABLE_ELEMENT_SELECTOR) && isElementVisible(element) && !isInert(element);
37+
export function isFocusable(element: Element, options?: {skipVisibilityCheck?: boolean}): boolean {
38+
return element.matches(FOCUSABLE_ELEMENT_SELECTOR) && !isInert(element) && (options?.skipVisibilityCheck || isElementVisible(element));
3939
}
4040

4141
export function isTabbable(element: Element): boolean {

0 commit comments

Comments
 (0)