Skip to content

feat(material-experimental/mdc-chips): Allow custom role for chip set #20829

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
Nov 3, 2020
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
8 changes: 7 additions & 1 deletion src/material-experimental/mdc-chips/chip-set.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,15 @@ describe('MDC-based MatChipSet', () => {
expect(chips.toArray().every(chip => chip.disabled)).toBe(true);
}));

it('should have role presentation', () => {
it('should have role presentation by default', () => {
expect(chipSetNativeElement.getAttribute('role')).toBe('presentation');
});

it('should allow a custom role to be specified', () => {
chipSetInstance.role = 'list';
fixture.detectChanges();
expect(chipSetNativeElement.getAttribute('role')).toBe('list');
});
});
});

Expand Down
14 changes: 13 additions & 1 deletion src/material-experimental/mdc-chips/chip-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,19 @@ export class MatChipSet extends _MatChipSetMixinBase implements AfterContentInit
get empty(): boolean { return this._chips.length === 0; }

/** The ARIA role applied to the chip set. */
get role(): string | null { return this.empty ? null : 'presentation'; }
@Input()
get role(): string | null {
if (this._role) {
return this._role;
} else {
return this.empty ? null : 'presentation';
}
}

set role(value: string | null) {
this._role = value;
}
private _role: string|null = null;

/** Whether any of the chips inside of this chip-set has focus. */
get focused(): boolean { return this._hasFocusedChip(); }
Expand Down