Skip to content

Commit 0a4d8e9

Browse files
committed
fix(material-experimental/mdc-list): set a role on MatNavList and MatActionList (#25412)
make the following changes to align with legacy version of list - `MatNavList` apply `role="navigation"` - `MatActionList` apply `role="group"` (cherry picked from commit dd1bfad)
1 parent 3aaf899 commit 0a4d8e9

File tree

5 files changed

+45
-2
lines changed

5 files changed

+45
-2
lines changed

src/material-experimental/mdc-list/action-list.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {MatListBase} from './list-base';
1515
template: '<ng-content></ng-content>',
1616
host: {
1717
'class': 'mat-mdc-action-list mat-mdc-list-base mdc-list',
18+
'role': 'group',
1819
},
1920
styleUrls: ['list.css'],
2021
encapsulation: ViewEncapsulation.None,

src/material-experimental/mdc-list/list.spec.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ describe('MDC-based MatList', () => {
9999
expect(listItem.nativeElement.className).toContain('mdc-list-item--with-three-lines');
100100
});
101101

102-
it('should add aria roles properly', () => {
102+
it('should not apply aria roles to mat-list', () => {
103103
const fixture = TestBed.createComponent(ListWithMultipleItems);
104104
fixture.detectChanges();
105105

@@ -113,6 +113,26 @@ describe('MDC-based MatList', () => {
113113
.toBeNull();
114114
});
115115

116+
it('should apply role="navigation" to mat-nav-list', () => {
117+
const fixture = TestBed.createComponent(NavListWithOneAnchorItem);
118+
fixture.detectChanges();
119+
120+
const list = fixture.debugElement.children[0];
121+
expect(list.nativeElement.getAttribute('role'))
122+
.withContext('Expect mat-nav-list to have navigation role')
123+
.toBe('navigation');
124+
});
125+
126+
it('should apply role="group" to mat-action-list', () => {
127+
const fixture = TestBed.createComponent(ActionListWithoutType);
128+
fixture.detectChanges();
129+
130+
const list = fixture.debugElement.children[0];
131+
expect(list.nativeElement.getAttribute('role'))
132+
.withContext('Expect mat-action-list to have group role')
133+
.toBe('group');
134+
});
135+
116136
it('should not show ripples for non-nav lists', fakeAsync(() => {
117137
const fixture = TestBed.createComponent(ListWithOneAnchorItem);
118138
fixture.detectChanges();

src/material-experimental/mdc-list/nav-list.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {MatListBase} from './list-base';
1515
template: '<ng-content></ng-content>',
1616
host: {
1717
'class': 'mat-mdc-nav-list mat-mdc-list-base mdc-list',
18+
'role': 'navigation',
1819
},
1920
styleUrls: ['list.css'],
2021
encapsulation: ViewEncapsulation.None,

src/material/list/list.spec.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ describe('MatList', () => {
9999
expect(listItem.nativeElement.className).toContain('mat-3-line');
100100
});
101101

102-
it('should add aria roles properly', () => {
102+
it('should not apply aria roles to mat-list', () => {
103103
const fixture = TestBed.createComponent(ListWithMultipleItems);
104104
fixture.detectChanges();
105105

@@ -113,6 +113,26 @@ describe('MatList', () => {
113113
.toBeNull();
114114
});
115115

116+
it('should apply role="navigation" to mat-nav-list', () => {
117+
const fixture = TestBed.createComponent(NavListWithOneAnchorItem);
118+
fixture.detectChanges();
119+
120+
const list = fixture.debugElement.children[0];
121+
expect(list.nativeElement.getAttribute('role'))
122+
.withContext('Expect mat-nav-list to have navigation role')
123+
.toBe('navigation');
124+
});
125+
126+
it('should apply role="group" to mat-action-list', () => {
127+
const fixture = TestBed.createComponent(ActionListWithoutType);
128+
fixture.detectChanges();
129+
130+
const list = fixture.debugElement.children[0];
131+
expect(list.nativeElement.getAttribute('role'))
132+
.withContext('Expect mat-action-list to have group role')
133+
.toBe('group');
134+
});
135+
116136
it('should not show ripples for non-nav lists', () => {
117137
const fixture = TestBed.createComponent(ListWithOneAnchorItem);
118138
fixture.detectChanges();

src/material/list/list.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ export class MatList
113113

114114
if (this._getListType() === 'action-list') {
115115
_elementRef.nativeElement.classList.add('mat-action-list');
116+
_elementRef.nativeElement.setAttribute('role', 'group');
116117
}
117118
}
118119

0 commit comments

Comments
 (0)