Skip to content

Commit 9f0a5b9

Browse files
committed
(menu): blur active element to prevent a11y reported issue
1 parent 2f1090e commit 9f0a5b9

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

core/src/components/menu/menu.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,9 @@ export class Menu implements ComponentInterface, MenuI {
418418
*/
419419
@Method()
420420
setOpen(shouldOpen: boolean, animated = true, role?: string): Promise<boolean> {
421+
// Blur the active element to prevent it from being kept focused inside an element that will be set with aria-hidden="true"
422+
(document.activeElement as HTMLElement)?.blur();
423+
421424
return menuController._setOpen(this, shouldOpen, animated, role);
422425
}
423426

core/src/utils/overlays.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ export const present = async <OverlayPresentOptions>(
513513
return;
514514
}
515515

516+
// Blur the active element to prevent it from being kept focused inside a container that will be set with aria-hidden="true"
516517
(document.activeElement as HTMLElement)?.blur();
517518

518519
/**
@@ -650,6 +651,7 @@ export const dismiss = async <OverlayDismissOptions>(
650651
return false;
651652
}
652653

654+
// Blur the active element to prevent it from being kept focused inside the overlay, since it will be removed
653655
(document.activeElement as HTMLElement)?.blur();
654656

655657
const presentedOverlays = doc !== undefined ? getPresentedOverlays(doc) : [];

0 commit comments

Comments
 (0)