Skip to content

Commit

Permalink
fix(material-experimental/mdc-list): set a role on MatNavList and Mat…
Browse files Browse the repository at this point in the history
…ActionList (#25412)

make the following changes to align with legacy version of list
 - `MatNavList` apply `role="navigation"`
 - `MatActionList` apply `role="group"`
  • Loading branch information
zarend committed Aug 10, 2022
1 parent 08fba43 commit dd1bfad
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/material-experimental/mdc-list/action-list.ts
Expand Up @@ -15,6 +15,7 @@ import {MatListBase} from './list-base';
template: '<ng-content></ng-content>',
host: {
'class': 'mat-mdc-action-list mat-mdc-list-base mdc-list',
'role': 'group',
},
styleUrls: ['list.css'],
encapsulation: ViewEncapsulation.None,
Expand Down
22 changes: 21 additions & 1 deletion src/material-experimental/mdc-list/list.spec.ts
Expand Up @@ -99,7 +99,7 @@ describe('MDC-based MatList', () => {
expect(listItem.nativeElement.className).toContain('mdc-list-item--with-three-lines');
});

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

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

it('should apply role="navigation" to mat-nav-list', () => {
const fixture = TestBed.createComponent(NavListWithOneAnchorItem);
fixture.detectChanges();

const list = fixture.debugElement.children[0];
expect(list.nativeElement.getAttribute('role'))
.withContext('Expect mat-nav-list to have navigation role')
.toBe('navigation');
});

it('should apply role="group" to mat-action-list', () => {
const fixture = TestBed.createComponent(ActionListWithoutType);
fixture.detectChanges();

const list = fixture.debugElement.children[0];
expect(list.nativeElement.getAttribute('role'))
.withContext('Expect mat-action-list to have group role')
.toBe('group');
});

it('should not show ripples for non-nav lists', fakeAsync(() => {
const fixture = TestBed.createComponent(ListWithOneAnchorItem);
fixture.detectChanges();
Expand Down
1 change: 1 addition & 0 deletions src/material-experimental/mdc-list/nav-list.ts
Expand Up @@ -15,6 +15,7 @@ import {MatListBase} from './list-base';
template: '<ng-content></ng-content>',
host: {
'class': 'mat-mdc-nav-list mat-mdc-list-base mdc-list',
'role': 'navigation',
},
styleUrls: ['list.css'],
encapsulation: ViewEncapsulation.None,
Expand Down
22 changes: 21 additions & 1 deletion src/material/list/list.spec.ts
Expand Up @@ -99,7 +99,7 @@ describe('MatList', () => {
expect(listItem.nativeElement.className).toContain('mat-3-line');
});

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

Expand All @@ -113,6 +113,26 @@ describe('MatList', () => {
.toBeNull();
});

it('should apply role="navigation" to mat-nav-list', () => {
const fixture = TestBed.createComponent(NavListWithOneAnchorItem);
fixture.detectChanges();

const list = fixture.debugElement.children[0];
expect(list.nativeElement.getAttribute('role'))
.withContext('Expect mat-nav-list to have navigation role')
.toBe('navigation');
});

it('should apply role="group" to mat-action-list', () => {
const fixture = TestBed.createComponent(ActionListWithoutType);
fixture.detectChanges();

const list = fixture.debugElement.children[0];
expect(list.nativeElement.getAttribute('role'))
.withContext('Expect mat-action-list to have group role')
.toBe('group');
});

it('should not show ripples for non-nav lists', () => {
const fixture = TestBed.createComponent(ListWithOneAnchorItem);
fixture.detectChanges();
Expand Down
1 change: 1 addition & 0 deletions src/material/list/list.ts
Expand Up @@ -113,6 +113,7 @@ export class MatList

if (this._getListType() === 'action-list') {
_elementRef.nativeElement.classList.add('mat-action-list');
_elementRef.nativeElement.setAttribute('role', 'group');
}
}

Expand Down

0 comments on commit dd1bfad

Please sign in to comment.