Skip to content

Commit 7c20ca4

Browse files
committed
(overlay): fixing issues by readapting logic
1 parent b7f9d37 commit 7c20ca4

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

core/src/utils/overlays.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import { isPlatform } from './platform';
3636

3737
let lastOverlayIndex = 0;
3838
let lastId = 0;
39-
let previousElement: HTMLElement | null;
4039

4140
export const activeAnimations = new WeakMap<OverlayInterface, Animation[]>();
4241

@@ -514,15 +513,6 @@ export const present = async <OverlayPresentOptions>(
514513
return;
515514
}
516515

517-
// Set the responsible element for the action of presenting the overlay
518-
previousElement = document.activeElement as HTMLElement | null;
519-
520-
/**
521-
* Blur the active element to prevent it from being kept focused, since during the overlay opening process a11y
522-
* attributes such as `aria-hidden` and `inert` are applied to the activeElement parent container
523-
*/
524-
(document.activeElement as HTMLElement)?.blur();
525-
526516
/**
527517
* Due to accessibility guidelines, toasts do not have
528518
* focus traps.
@@ -603,6 +593,7 @@ export const present = async <OverlayPresentOptions>(
603593
* opened the overlay.
604594
*/
605595
const restoreElementFocus = async (overlayEl: any) => {
596+
let previousElement = document.activeElement as HTMLElement | null;
606597
if (!previousElement) {
607598
return;
608599
}
@@ -639,7 +630,7 @@ const restoreElementFocus = async (overlayEl: any) => {
639630
* action sheet) then don't restore focus to
640631
* previous element
641632
*/
642-
if (previousElement !== null) {
633+
if (document.activeElement === null || document.activeElement === document.body) {
643634
previousElement.focus();
644635
}
645636
};
@@ -1075,4 +1066,4 @@ const revealOverlaysToScreenReaders = () => {
10751066
}
10761067
};
10771068

1078-
export const FOCUS_TRAP_DISABLE_CLASS = 'ion-disable-focus-trap';
1069+
export const FOCUS_TRAP_DISABLE_CLASS = 'ion-disable-focus-trap';

0 commit comments

Comments
 (0)