Skip to content

Commit 7dcc788

Browse files
feat(material/chips): update chip-list describedby to match input
Fixes ExpressionChangedAfterItHasBeenCheckedError that occurs when chip-lists are content-projected into a mat-form-field
1 parent fed8fae commit 7dcc788

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

src/material/chips/chip-list.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ export class MatChipListChange {
7878
exportAs: 'matChipList',
7979
host: {
8080
'[attr.tabindex]': 'disabled ? null : _tabIndex',
81-
'[attr.aria-describedby]': '_ariaDescribedby || null',
8281
'[attr.aria-required]': 'role ? required : null',
8382
'[attr.aria-disabled]': 'disabled.toString()',
8483
'[attr.aria-invalid]': 'errorState',
@@ -144,9 +143,6 @@ export class MatChipList
144143
/** Uid of the chip list */
145144
_uid: string = `mat-chip-list-${nextUniqueId++}`;
146145

147-
/** The aria-describedby attribute on the chip list for improved a11y. */
148-
_ariaDescribedby: string;
149-
150146
/** Tab index for the chip list. */
151147
_tabIndex = 0;
152148

@@ -455,7 +451,11 @@ export class MatChipList
455451
* @docs-private
456452
*/
457453
setDescribedByIds(ids: string[]) {
458-
this._ariaDescribedby = ids.join(' ');
454+
if (ids.length) {
455+
this._elementRef.nativeElement.setAttribute('aria-describedby', ids.join(' '));
456+
} else {
457+
this._elementRef.nativeElement.removeAttribute('aria-describedby');
458+
}
459459
}
460460

461461
// Implemented as part of ControlValueAccessor.

tools/public_api_guard/material/chips.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ export interface MatChipInputEvent {
181181
export class MatChipList extends _MatChipListBase implements MatFormFieldControl<any>, ControlValueAccessor, AfterContentInit, DoCheck, OnInit, OnDestroy, CanUpdateErrorState {
182182
constructor(_elementRef: ElementRef<HTMLElement>, _changeDetectorRef: ChangeDetectorRef, _dir: Directionality, _parentForm: NgForm, _parentFormGroup: FormGroupDirective, _defaultErrorStateMatcher: ErrorStateMatcher, ngControl: NgControl);
183183
_allowFocusEscape(): void;
184-
_ariaDescribedby: string;
185184
ariaOrientation: 'horizontal' | 'vertical';
186185
_blur(): void;
187186
readonly change: EventEmitter<MatChipListChange>;

0 commit comments

Comments
 (0)