Skip to content

Commit c02624d

Browse files
committed
add describedbyids and use to preserve existing ids
1 parent 1b4cae7 commit c02624d

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/material/form-field/form-field-control.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ export abstract class MatFormFieldControl<T> {
7575
*/
7676
readonly disableAutomaticLabeling?: boolean;
7777

78+
readonly describedByIds?: string[];
79+
7880
/** Sets the list of element IDs that currently describe this control. */
7981
abstract setDescribedByIds(ids: string[]): void;
8082

src/material/form-field/form-field.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,9 @@ export class MatFormField
308308
// Unique id for the hint label.
309309
readonly _hintLabelId = this._idGenerator.getId('mat-mdc-hint-');
310310

311+
// Ids obtained from the fields
312+
private _describedByIds: Array<String> = [];
313+
311314
/** Gets the current form field control */
312315
get _control(): MatFormFieldControl<any> {
313316
return this._explicitFormFieldControl || this._formFieldControl;
@@ -705,7 +708,17 @@ export class MatFormField
705708
ids.push(...this._errorChildren.map(error => error.id));
706709
}
707710

708-
this._control.setDescribedByIds(ids);
711+
let currentIds = this._control.describedByIds ?? [];
712+
let combinedIds: Array<string> = [];
713+
currentIds.forEach(id => {
714+
if (!this._describedByIds.includes(id)) {
715+
combinedIds.push(id);
716+
}
717+
});
718+
combinedIds.concat(...ids);
719+
720+
this._control.setDescribedByIds(combinedIds);
721+
this._describedByIds = ids;
709722
}
710723
}
711724

0 commit comments

Comments
 (0)