Skip to content

Commit 8d57d32

Browse files
crisbetojelbourn
authored andcommitted
fix(chips): set aria-required on chip input (#18098)
Sets an `aria-required` on the input that's associated with a chip list. Matches something similar we did for the MDC-based chips in #18049 since the MDC chip listbox setup is similar to our current chips setup.
1 parent 9227c7b commit 8d57d32

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/material/chips/chip-input.spec.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,15 @@ describe('MatChipInput', () => {
138138
expect(listElement.getAttribute('tabindex')).toBe('0', 'Expected tabindex to remain 0');
139139
}));
140140

141+
it('should be aria-required if the chip list is required', () => {
142+
expect(inputNativeElement.hasAttribute('aria-required')).toBe(false);
143+
144+
fixture.componentInstance.required = true;
145+
fixture.detectChanges();
146+
147+
expect(inputNativeElement.getAttribute('aria-required')).toBe('true');
148+
});
149+
141150
});
142151

143152
describe('[addOnBlur]', () => {
@@ -245,7 +254,7 @@ describe('MatChipInput', () => {
245254
@Component({
246255
template: `
247256
<mat-form-field>
248-
<mat-chip-list #chipList>
257+
<mat-chip-list #chipList [required]="required">
249258
<mat-chip>Hello</mat-chip>
250259
<input matInput [matChipInputFor]="chipList"
251260
[matChipInputAddOnBlur]="addOnBlur"
@@ -257,7 +266,8 @@ describe('MatChipInput', () => {
257266
})
258267
class TestChipInput {
259268
@ViewChild(MatChipList) chipListInstance: MatChipList;
260-
addOnBlur: boolean = false;
269+
addOnBlur = false;
270+
required = false;
261271
placeholder = '';
262272

263273
add(_: MatChipInputEvent) {

src/material/chips/chip-input.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ let nextUniqueId = 0;
4343
'[attr.disabled]': 'disabled || null',
4444
'[attr.placeholder]': 'placeholder || null',
4545
'[attr.aria-invalid]': '_chipList && _chipList.ngControl ? _chipList.ngControl.invalid : null',
46+
'[attr.aria-required]': '_chipList && _chipList.required || null',
4647
}
4748
})
4849
export class MatChipInput implements MatChipTextControl, OnChanges {

0 commit comments

Comments
 (0)