File tree Expand file tree Collapse file tree 5 files changed +16
-0
lines changed Expand file tree Collapse file tree 5 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ export interface MatMenuPanel<T = any> {
3737 lazyContent ?: MatMenuContent ;
3838 backdropClass ?: string ;
3939 hasBackdrop ?: boolean ;
40+ readonly panelId ?: string ;
4041
4142 /**
4243 * @deprecated To be removed.
Original file line number Diff line number Diff line change @@ -76,6 +76,7 @@ const passiveEventListenerOptions = normalizePassiveListenerOptions({passive: tr
7676 'class' : 'mat-menu-trigger' ,
7777 'aria-haspopup' : 'true' ,
7878 '[attr.aria-expanded]' : 'menuOpen || null' ,
79+ '[attr.aria-owns]' : 'menuOpen ? menu.panelId : null' ,
7980 '(mousedown)' : '_handleMousedown($event)' ,
8081 '(keydown)' : '_handleKeydown($event)' ,
8182 '(click)' : '_handleClick($event)' ,
Original file line number Diff line number Diff line change 11< ng-template >
22 < div
33 class ="mat-menu-panel "
4+ [id] ="panelId "
45 [ngClass] ="_classList "
56 (keydown) ="_handleKeydown($event) "
67 (click) ="closed.emit('click') "
Original file line number Diff line number Diff line change @@ -76,6 +76,15 @@ describe('MatMenu', () => {
7676 overlayContainer . ngOnDestroy ( ) ;
7777 } ) ) ;
7878
79+ it ( 'should aria-owns the menu panel' , ( ) => {
80+ const fixture = createComponent ( SimpleMenu , [ ] , [ FakeIcon ] ) ;
81+ fixture . detectChanges ( ) ;
82+ fixture . componentInstance . trigger . openMenu ( ) ;
83+ fixture . detectChanges ( ) ;
84+ expect ( fixture . componentInstance . triggerEl . nativeElement . getAttribute ( 'aria-owns' ) )
85+ . toBe ( fixture . componentInstance . menu . panelId ) ;
86+ } ) ;
87+
7988 it ( 'should open the menu as an idempotent operation' , ( ) => {
8089 const fixture = createComponent ( SimpleMenu , [ ] , [ FakeIcon ] ) ;
8190 fixture . detectChanges ( ) ;
Original file line number Diff line number Diff line change @@ -90,6 +90,8 @@ export function MAT_MENU_DEFAULT_OPTIONS_FACTORY(): MatMenuDefaultOptions {
9090 */
9191const MAT_MENU_BASE_ELEVATION = 4 ;
9292
93+ let menuPanelUid = 0 ;
94+
9395/** Base class with all of the `MatMenu` functionality. */
9496@Directive ( {
9597 // TODO(devversion): this selector can be removed when we update to Angular 9.0.
@@ -237,6 +239,8 @@ export class _MatMenuBase implements AfterContentInit, MatMenuPanel<MatMenuItem>
237239 */
238240 @Output ( ) close = this . closed ;
239241
242+ readonly panelId = `mat-menu-panel-${ menuPanelUid ++ } ` ;
243+
240244 constructor (
241245 private _elementRef : ElementRef < HTMLElement > ,
242246 private _ngZone : NgZone ,
You can’t perform that action at this time.
0 commit comments