mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-17 18:54:11 +08:00
fix(overlay): do not try to trap focus on hidden inputs (#21799)
This commit is contained in:
@ -63,14 +63,16 @@ export const createOverlay = <T extends HTMLIonOverlayElement>(tagName: string,
|
|||||||
return Promise.resolve() as any;
|
return Promise.resolve() as any;
|
||||||
};
|
};
|
||||||
|
|
||||||
const focusableQueryString = '[tabindex]:not([tabindex^="-"]), input, textarea, button, select, .ion-focusable';
|
const focusableQueryString = '[tabindex]:not([tabindex^="-"]), input:not([type=hidden]), textarea, button, select, .ion-focusable';
|
||||||
|
const innerFocusableQueryString = 'input:not([type=hidden]), textarea, button, select';
|
||||||
|
|
||||||
const focusFirstDescendant = (ref: Element, overlay: HTMLIonOverlayElement) => {
|
const focusFirstDescendant = (ref: Element, overlay: HTMLIonOverlayElement) => {
|
||||||
let firstInput = ref.querySelector(focusableQueryString) as HTMLElement | null;
|
let firstInput = ref.querySelector(focusableQueryString) as HTMLElement | null;
|
||||||
|
|
||||||
const shadowRoot = firstInput && firstInput.shadowRoot;
|
const shadowRoot = firstInput && firstInput.shadowRoot;
|
||||||
if (shadowRoot) {
|
if (shadowRoot) {
|
||||||
firstInput = shadowRoot.querySelector('input, textarea, button, select');
|
// If there are no inner focusable elements, just focus the host element.
|
||||||
|
firstInput = shadowRoot.querySelector(innerFocusableQueryString) || firstInput;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (firstInput) {
|
if (firstInput) {
|
||||||
@ -87,7 +89,8 @@ const focusLastDescendant = (ref: Element, overlay: HTMLIonOverlayElement) => {
|
|||||||
|
|
||||||
const shadowRoot = lastInput && lastInput.shadowRoot;
|
const shadowRoot = lastInput && lastInput.shadowRoot;
|
||||||
if (shadowRoot) {
|
if (shadowRoot) {
|
||||||
lastInput = shadowRoot.querySelector('input, textarea, button, select');
|
// If there are no inner focusable elements, just focus the host element.
|
||||||
|
lastInput = shadowRoot.querySelector(innerFocusableQueryString) || lastInput;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastInput) {
|
if (lastInput) {
|
||||||
|
Reference in New Issue
Block a user