File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed
Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -70,6 +70,7 @@ export const MENU_PANEL_TOP_PADDING = 8;
7070 selector : `[mat-menu-trigger-for], [matMenuTriggerFor]` ,
7171 host : {
7272 'aria-haspopup' : 'true' ,
73+ '[attr.aria-expanded]' : 'menuOpen || null' ,
7374 '(mousedown)' : '_handleMousedown($event)' ,
7475 '(keydown)' : '_handleKeydown($event)' ,
7576 '(click)' : '_handleClick($event)' ,
Original file line number Diff line number Diff line change @@ -388,6 +388,24 @@ describe('MatMenu', () => {
388388 expect ( items [ 2 ] . classList ) . toContain ( 'cdk-keyboard-focused' ) ;
389389 } ) ) ;
390390
391+ it ( 'should toggle the aria-expanded attribute on the trigger' , ( ) => {
392+ const fixture = createComponent ( SimpleMenu , [ ] , [ FakeIcon ] ) ;
393+ fixture . detectChanges ( ) ;
394+ const triggerEl = fixture . componentInstance . triggerEl . nativeElement ;
395+
396+ expect ( triggerEl . hasAttribute ( 'aria-expanded' ) ) . toBe ( false ) ;
397+
398+ fixture . componentInstance . trigger . openMenu ( ) ;
399+ fixture . detectChanges ( ) ;
400+
401+ expect ( triggerEl . getAttribute ( 'aria-expanded' ) ) . toBe ( 'true' ) ;
402+
403+ fixture . componentInstance . trigger . closeMenu ( ) ;
404+ fixture . detectChanges ( ) ;
405+
406+ expect ( triggerEl . hasAttribute ( 'aria-expanded' ) ) . toBe ( false ) ;
407+ } ) ;
408+
391409 describe ( 'lazy rendering' , ( ) => {
392410 it ( 'should be able to render the menu content lazily' , fakeAsync ( ( ) => {
393411 const fixture = createComponent ( SimpleLazyMenu ) ;
You can’t perform that action at this time.
0 commit comments