Skip to content

fix(material-experimental/mdc-list): set a role on MatNavList and Mat… #25412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/material-experimental/mdc-list/action-list.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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