fix(overlays): focus trapping no longer includes hidden elements (#25948)

This commit is contained in:
Liam DeBeasi
2022-09-15 15:36:45 -05:00
committed by GitHub
parent 8629dfa9e8
commit 5c10f98ceb
2 changed files with 38 additions and 3 deletions

View File

@ -82,8 +82,16 @@ export const createOverlay = <T extends HTMLIonOverlayElement>(
return Promise.resolve() as any;
};
/**
* This query string selects elements that
* are eligible to receive focus. We select
* interactive elements that meet the following
* criteria:
* 1. Element does not have a negative tabindex
* 2. Element does not have [hidden]
*/
const focusableQueryString =
'[tabindex]:not([tabindex^="-"]), input:not([type=hidden]):not([tabindex^="-"]), textarea:not([tabindex^="-"]), button:not([tabindex^="-"]), select:not([tabindex^="-"]), .ion-focusable:not([tabindex^="-"])';
'[tabindex]:not([tabindex^="-"]):not([hidden]), input:not([type=hidden]):not([tabindex^="-"]):not([hidden]), textarea:not([tabindex^="-"]):not([hidden]), button:not([tabindex^="-"]):not([hidden]), select:not([tabindex^="-"]):not([hidden]), .ion-focusable:not([tabindex^="-"]):not([hidden])';
export const focusFirstDescendant = (ref: Element, overlay: HTMLIonOverlayElement) => {
let firstInput = ref.querySelector(focusableQueryString) as HTMLElement | null;