Skip to content
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

fix(chips): don't set aria-required when element doesn't have a role #17425

Merged
merged 1 commit into from
Oct 18, 2019
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
16 changes: 16 additions & 0 deletions src/material-experimental/mdc-chips/chip-grid.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,22 @@ describe('MatChipGrid', () => {

expect(chips.toArray().every(chip => chip.disabled)).toBe(true);
}));

it('should not set a role on the grid when the list is empty', () => {
testComponent.chips = [];
fixture.detectChanges();

expect(chipGridNativeElement.hasAttribute('role')).toBe(false);
});

it('should not set aria-required when it does not have a role', () => {
testComponent.chips = [];
fixture.detectChanges();

expect(chipGridNativeElement.hasAttribute('role')).toBe(false);
expect(chipGridNativeElement.hasAttribute('aria-required')).toBe(false);
});

});

describe('focus behaviors', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/material-experimental/mdc-chips/chip-grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const _MatChipGridMixinBase: CanUpdateErrorStateCtor & typeof MatChipGridBase =
'[tabIndex]': '_chips && _chips.length === 0 ? -1 : tabIndex',
// TODO: replace this binding with use of AriaDescriber
'[attr.aria-describedby]': '_ariaDescribedby || null',
'[attr.aria-required]': 'required.toString()',
'[attr.aria-required]': 'role ? required : null',
'[attr.aria-disabled]': 'disabled.toString()',
'[attr.aria-invalid]': 'errorState',
'[class.mat-mdc-chip-list-disabled]': 'disabled',
Expand Down
16 changes: 16 additions & 0 deletions src/material-experimental/mdc-chips/chip-listbox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,22 @@ describe('MatChipListbox', () => {

expect(chips.toArray().every(chip => chip.disabled)).toBe(true);
}));

it('should not set a role on the grid when the list is empty', () => {
testComponent.chips = [];
fixture.detectChanges();

expect(chipListboxNativeElement.hasAttribute('role')).toBe(false);
});

it('should not set aria-required when it does not have a role', () => {
testComponent.chips = [];
fixture.detectChanges();

expect(chipListboxNativeElement.hasAttribute('role')).toBe(false);
expect(chipListboxNativeElement.hasAttribute('aria-required')).toBe(false);
});

});

describe('with selected chips', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/material-experimental/mdc-chips/chip-listbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const MAT_CHIP_LISTBOX_CONTROL_VALUE_ACCESSOR: any = {
'[tabIndex]': 'empty ? -1 : tabIndex',
// TODO: replace this binding with use of AriaDescriber
'[attr.aria-describedby]': '_ariaDescribedby || null',
'[attr.aria-required]': 'required.toString()',
'[attr.aria-required]': 'role ? required : null',
'[attr.aria-disabled]': 'disabled.toString()',
'[attr.aria-multiselectable]': 'multiple',
'[attr.aria-orientation]': 'ariaOrientation',
Expand Down
8 changes: 8 additions & 0 deletions src/material/chips/chip-list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ describe('MatChipList', () => {

expect(chipListNativeElement.getAttribute('role')).toBeNull('Expect no role attribute');
});

it('should not have aria-required when it has no role', () => {
fixture.componentInstance.foods = [];
fixture.detectChanges();

expect(chipListNativeElement.hasAttribute('role')).toBe(false);
expect(chipListNativeElement.hasAttribute('aria-required')).toBe(false);
});
});

describe('focus behaviors', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/material/chips/chip-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class MatChipListChange {
host: {
'[attr.tabindex]': 'disabled ? null : _tabIndex',
'[attr.aria-describedby]': '_ariaDescribedby || null',
'[attr.aria-required]': 'required.toString()',
'[attr.aria-required]': 'role ? required : null',
'[attr.aria-disabled]': 'disabled.toString()',
'[attr.aria-invalid]': 'errorState',
'[attr.aria-multiselectable]': 'multiple',
Expand Down