@@ -503,6 +503,38 @@ describe('MDC-based MatMenu', () => {
503
503
expect ( role ) . toBe ( 'menu' , 'Expected panel to have the "menu" role.' ) ;
504
504
} ) ;
505
505
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
+
506
538
it ( 'should set the "menuitem" role on the items by default' , ( ) => {
507
539
const fixture = createComponent ( SimpleMenu , [ ] , [ FakeIcon ] ) ;
508
540
fixture . detectChanges ( ) ;
@@ -2163,7 +2195,10 @@ describe('MatMenu default overrides', () => {
2163
2195
#menu="matMenu"
2164
2196
[class]="panelClass"
2165
2197
(closed)="closeCallback($event)"
2166
- [backdropClass]="backdropClass">
2198
+ [backdropClass]="backdropClass"
2199
+ [aria-label]="ariaLabel"
2200
+ [aria-labelledby]="ariaLabelledby"
2201
+ [aria-describedby]="ariaDescribedby">
2167
2202
2168
2203
<button mat-menu-item> Item </button>
2169
2204
<button mat-menu-item disabled> Disabled </button>
@@ -2185,6 +2220,9 @@ class SimpleMenu {
2185
2220
backdropClass : string ;
2186
2221
panelClass : string ;
2187
2222
restoreFocus = true ;
2223
+ ariaLabel : string ;
2224
+ ariaLabelledby : string ;
2225
+ ariaDescribedby : string ;
2188
2226
}
2189
2227
2190
2228
@Component ( {
0 commit comments