Skip to content

Commit 6fa02f2

Browse files
authored
refactor(material/menu): explicitly set aria-expanded to true/false (#19722)
In the context of a submenu trigger it is useful for a screen reader user to know whether a submenu is open or closed. By specifying the `aria-expanded` attribute as either true or false it provides an additional "collapsed" announcement to the user informing them of the state of the menu trigger when closed.
1 parent bbdadef commit 6fa02f2

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

src/material/legacy-menu/menu.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ describe('MatMenu', () => {
879879
fixture.detectChanges();
880880
const triggerEl = fixture.componentInstance.triggerEl.nativeElement;
881881

882-
expect(triggerEl.hasAttribute('aria-expanded')).toBe(false);
882+
expect(triggerEl.getAttribute('aria-expanded')).toBe('false');
883883

884884
fixture.componentInstance.trigger.openMenu();
885885
fixture.detectChanges();
@@ -891,7 +891,7 @@ describe('MatMenu', () => {
891891
fixture.detectChanges();
892892
tick(500);
893893

894-
expect(triggerEl.hasAttribute('aria-expanded')).toBe(false);
894+
expect(triggerEl.getAttribute('aria-expanded')).toBe('false');
895895
}));
896896

897897
it('should throw if assigning a menu that contains the trigger', fakeAsync(() => {

src/material/menu/menu-trigger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export const MENU_PANEL_TOP_PADDING = 8;
7878
@Directive({
7979
host: {
8080
'[attr.aria-haspopup]': 'menu ? "menu" : null',
81-
'[attr.aria-expanded]': 'menuOpen || null',
81+
'[attr.aria-expanded]': 'menuOpen',
8282
'[attr.aria-controls]': 'menuOpen ? menu.panelId : null',
8383
'(click)': '_handleClick($event)',
8484
'(mousedown)': '_handleMousedown($event)',

src/material/menu/menu.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ describe('MDC-based MatMenu', () => {
882882
fixture.detectChanges();
883883
const triggerEl = fixture.componentInstance.triggerEl.nativeElement;
884884

885-
expect(triggerEl.hasAttribute('aria-expanded')).toBe(false);
885+
expect(triggerEl.getAttribute('aria-expanded')).toBe('false');
886886

887887
fixture.componentInstance.trigger.openMenu();
888888
fixture.detectChanges();
@@ -894,7 +894,7 @@ describe('MDC-based MatMenu', () => {
894894
fixture.detectChanges();
895895
tick(500);
896896

897-
expect(triggerEl.hasAttribute('aria-expanded')).toBe(false);
897+
expect(triggerEl.getAttribute('aria-expanded')).toBe('false');
898898
}));
899899

900900
it('should throw if assigning a menu that contains the trigger', fakeAsync(() => {

0 commit comments

Comments
 (0)