File tree Expand file tree Collapse file tree 8 files changed +28
-0
lines changed
tools/public_api_guard/material Expand file tree Collapse file tree 8 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 1
1
< ng-template >
2
2
< div
3
3
class ="mat-mdc-menu-panel mdc-menu-surface mdc-menu-surface--open "
4
+ [id] ="panelId "
4
5
[ngClass] ="_classList "
5
6
(keydown) ="_handleKeydown($event) "
6
7
(click) ="closed.emit('click') "
Original file line number Diff line number Diff line change @@ -74,6 +74,15 @@ describe('MatMenu', () => {
74
74
overlayContainer . ngOnDestroy ( ) ;
75
75
} ) ) ;
76
76
77
+ it ( 'should aria-controls the menu panel' , ( ) => {
78
+ const fixture = createComponent ( SimpleMenu , [ ] , [ FakeIcon ] ) ;
79
+ fixture . detectChanges ( ) ;
80
+ fixture . componentInstance . trigger . openMenu ( ) ;
81
+ fixture . detectChanges ( ) ;
82
+ expect ( fixture . componentInstance . triggerEl . nativeElement . getAttribute ( 'aria-controls' ) )
83
+ . toBe ( fixture . componentInstance . menu . panelId ) ;
84
+ } ) ;
85
+
77
86
it ( 'should open the menu as an idempotent operation' , ( ) => {
78
87
const fixture = createComponent ( SimpleMenu , [ ] , [ FakeIcon ] ) ;
79
88
fixture . detectChanges ( ) ;
Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ export interface MatMenuPanel<T = any> {
37
37
lazyContent ?: MatMenuContent ;
38
38
backdropClass ?: string ;
39
39
hasBackdrop ?: boolean ;
40
+ readonly panelId ?: string ;
40
41
41
42
/**
42
43
* @deprecated To be removed.
Original file line number Diff line number Diff line change @@ -76,6 +76,7 @@ const passiveEventListenerOptions = normalizePassiveListenerOptions({passive: tr
76
76
'class' : 'mat-menu-trigger' ,
77
77
'aria-haspopup' : 'true' ,
78
78
'[attr.aria-expanded]' : 'menuOpen || null' ,
79
+ '[attr.aria-controls]' : 'menuOpen ? menu.panelId : null' ,
79
80
'(mousedown)' : '_handleMousedown($event)' ,
80
81
'(keydown)' : '_handleKeydown($event)' ,
81
82
'(click)' : '_handleClick($event)' ,
Original file line number Diff line number Diff line change 1
1
< ng-template >
2
2
< div
3
3
class ="mat-menu-panel "
4
+ [id] ="panelId "
4
5
[ngClass] ="_classList "
5
6
(keydown) ="_handleKeydown($event) "
6
7
(click) ="closed.emit('click') "
Original file line number Diff line number Diff line change @@ -76,6 +76,15 @@ describe('MatMenu', () => {
76
76
overlayContainer . ngOnDestroy ( ) ;
77
77
} ) ) ;
78
78
79
+ it ( 'should aria-controls 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-controls' ) )
85
+ . toBe ( fixture . componentInstance . menu . panelId ) ;
86
+ } ) ;
87
+
79
88
it ( 'should open the menu as an idempotent operation' , ( ) => {
80
89
const fixture = createComponent ( SimpleMenu , [ ] , [ FakeIcon ] ) ;
81
90
fixture . detectChanges ( ) ;
Original file line number Diff line number Diff line change @@ -90,6 +90,8 @@ export function MAT_MENU_DEFAULT_OPTIONS_FACTORY(): MatMenuDefaultOptions {
90
90
*/
91
91
const MAT_MENU_BASE_ELEVATION = 4 ;
92
92
93
+ let menuPanelUid = 0 ;
94
+
93
95
/** Base class with all of the `MatMenu` functionality. */
94
96
@Directive ( {
95
97
// 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>
237
239
*/
238
240
@Output ( ) close = this . closed ;
239
241
242
+ readonly panelId = `mat-menu-panel-${ menuPanelUid ++ } ` ;
243
+
240
244
constructor (
241
245
private _elementRef : ElementRef < HTMLElement > ,
242
246
private _ngZone : NgZone ,
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ export declare class _MatMenuBase implements AfterContentInit, MatMenuPanel<MatM
20
20
lazyContent : MatMenuContent ;
21
21
overlapTrigger : boolean ;
22
22
panelClass : string ;
23
+ readonly panelId : string ;
23
24
parentMenu : MatMenuPanel | undefined ;
24
25
templateRef : TemplateRef < any > ;
25
26
xPosition : MenuPositionX ;
@@ -105,6 +106,7 @@ export interface MatMenuPanel<T = any> {
105
106
hasBackdrop ?: boolean ;
106
107
lazyContent ?: MatMenuContent ;
107
108
overlapTrigger : boolean ;
109
+ readonly panelId ?: string ;
108
110
parentMenu ?: MatMenuPanel | undefined ;
109
111
removeItem ?: ( item : T ) => void ;
110
112
resetActiveItem : ( ) => void ;
You can’t perform that action at this time.
0 commit comments