@@ -503,6 +503,38 @@ describe('MDC-based MatMenu', () => {
503503 expect ( role ) . toBe ( 'menu' , 'Expected panel to have the "menu" role.' ) ;
504504 } ) ;
505505
506+ it ( 'should forward ARIA attributes to the menu panel' , ( ) => {
507+ const fixture = createComponent ( SimpleMenu , [ ] , [ FakeIcon ] ) ;
508+ const instance = fixture . componentInstance ;
509+ fixture . detectChanges ( ) ;
510+ instance . trigger . openMenu ( ) ;
511+ fixture . detectChanges ( ) ;
512+
513+ const menuPanel = overlayContainerElement . querySelector ( '.mat-mdc-menu-panel' ) ! ;
514+ expect ( menuPanel . hasAttribute ( 'aria-label' ) ) . toBe ( false ) ;
515+ expect ( menuPanel . hasAttribute ( 'aria-labelledby' ) ) . toBe ( false ) ;
516+ expect ( menuPanel . hasAttribute ( 'aria-describedby' ) ) . toBe ( false ) ;
517+
518+ // Note that setting all of these at the same time is invalid,
519+ // but it's up to the consumer to handle it correctly.
520+ instance . ariaLabel = 'Custom aria-label' ;
521+ instance . ariaLabelledby = 'custom-labelled-by' ;
522+ instance . ariaDescribedby = 'custom-described-by' ;
523+ fixture . detectChanges ( ) ;
524+
525+ expect ( menuPanel . getAttribute ( 'aria-label' ) ) . toBe ( 'Custom aria-label' ) ;
526+ expect ( menuPanel . getAttribute ( 'aria-labelledby' ) ) . toBe ( 'custom-labelled-by' ) ;
527+ expect ( menuPanel . getAttribute ( 'aria-describedby' ) ) . toBe ( 'custom-described-by' ) ;
528+
529+ // Change these to empty strings to make sure that we don't preserve empty attributes.
530+ instance . ariaLabel = instance . ariaLabelledby = instance . ariaDescribedby = '' ;
531+ fixture . detectChanges ( ) ;
532+
533+ expect ( menuPanel . hasAttribute ( 'aria-label' ) ) . toBe ( false ) ;
534+ expect ( menuPanel . hasAttribute ( 'aria-labelledby' ) ) . toBe ( false ) ;
535+ expect ( menuPanel . hasAttribute ( 'aria-describedby' ) ) . toBe ( false ) ;
536+ } ) ;
537+
506538 it ( 'should set the "menuitem" role on the items by default' , ( ) => {
507539 const fixture = createComponent ( SimpleMenu , [ ] , [ FakeIcon ] ) ;
508540 fixture . detectChanges ( ) ;
@@ -2163,7 +2195,10 @@ describe('MatMenu default overrides', () => {
21632195 #menu="matMenu"
21642196 [class]="panelClass"
21652197 (closed)="closeCallback($event)"
2166- [backdropClass]="backdropClass">
2198+ [backdropClass]="backdropClass"
2199+ [aria-label]="ariaLabel"
2200+ [aria-labelledby]="ariaLabelledby"
2201+ [aria-describedby]="ariaDescribedby">
21672202
21682203 <button mat-menu-item> Item </button>
21692204 <button mat-menu-item disabled> Disabled </button>
@@ -2185,6 +2220,9 @@ class SimpleMenu {
21852220 backdropClass : string ;
21862221 panelClass : string ;
21872222 restoreFocus = true ;
2223+ ariaLabel : string ;
2224+ ariaLabelledby : string ;
2225+ ariaDescribedby : string ;
21882226}
21892227
21902228@Component ( {
0 commit comments