Skip to content

Commit dec59cf

Browse files
committed
refactor(menu): hide from screen readers while animating
1 parent b9a256c commit dec59cf

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

core/src/components/menu/menu.scss

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,10 @@
3737

3838

3939
.menu-inner {
40+
@include transform(translateX(-9999px));
41+
4042
display: flex;
4143
position: absolute;
42-
right: unset;
43-
/* stylelint-disable property-disallowed-list */
44-
left: -100%; /* Hide offscreen for left-sided menu */
4544

4645
flex-direction: column;
4746
justify-content: space-between;
@@ -54,8 +53,6 @@
5453
min-height: var(--min-height);
5554
max-height: var(--max-height);
5655

57-
transform: none; /* Avoid using transform */
58-
5956
background: var(--background);
6057

6158
contain: strict;

core/src/components/menu/menu.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,9 @@ export class Menu implements ComponentInterface, MenuI {
631631
private beforeAnimation(shouldOpen: boolean, role?: string) {
632632
assert(!this.isAnimating, '_before() should not be called while animating');
633633

634+
// add aria-hidden to the menu
635+
this.el.setAttribute('aria-hidden', 'true');
636+
634637
// this places the menu into the correct location before it animates in
635638
// this css class doesn't actually kick off any animations
636639
this.el.classList.add(SHOW_MENU);
@@ -690,6 +693,9 @@ export class Menu implements ComponentInterface, MenuI {
690693
// emit open event
691694
this.ionDidOpen.emit();
692695

696+
// remove aria-hidden from menu
697+
this.el.removeAttribute('aria-hidden');
698+
693699
/**
694700
* Move focus to the menu to prepare focus trapping, as long as
695701
* it isn't already focused. Use the host element instead of the
@@ -703,6 +709,8 @@ export class Menu implements ComponentInterface, MenuI {
703709
// start focus trapping
704710
document.addEventListener('focus', this.handleFocus, true);
705711
} else {
712+
this.el.removeAttribute('aria-hidden');
713+
706714
// remove css classes and unhide content from screen readers
707715
this.el.classList.remove(SHOW_MENU);
708716

core/src/utils/menu-controller/animations/overlay.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const menuOverlayAnimation = (menu: MenuI): Animation => {
2727
openedX = '0px';
2828
}
2929

30-
menuAnimation.addElement(menu.menuInnerEl!).fromTo('left', `${closedX}`, `${openedX}`);
30+
menuAnimation.addElement(menu.menuInnerEl!).fromTo('transform', `translateX(${closedX})`, `translateX(${openedX})`);
3131

3232
const mode = getIonMode(menu);
3333
const isIos = mode === 'ios';

0 commit comments

Comments
 (0)