Skip to content

Commit 3e47349

Browse files
committed
fix(material/form-field): preserve aria-describedby set externally across all form controls
add describedbyids and use to preserve existing ids add describedByIds to input add comment Move better sync logic to formfield add describedByIds to other controls update api goldens tweak comment
1 parent 538b8bc commit 3e47349

File tree

13 files changed

+82
-22
lines changed

13 files changed

+82
-22
lines changed

goldens/material/chips/index.api.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ export class MatChipGrid extends MatChipSet implements AfterContentInit, AfterVi
172172
readonly controlType: string;
173173
// (undocumented)
174174
protected _defaultRole: string;
175+
get describedByIds(): string[];
175176
get disabled(): boolean;
176177
set disabled(value: boolean);
177178
get empty(): boolean;
@@ -250,6 +251,7 @@ export class MatChipInput implements MatChipTextControl, OnChanges, OnDestroy {
250251
// (undocumented)
251252
protected _chipGrid: MatChipGrid;
252253
clear(): void;
254+
get describedByIds(): string[];
253255
get disabled(): boolean;
254256
set disabled(value: boolean);
255257
disabledInteractive: boolean;
@@ -514,6 +516,7 @@ export class MatChipsModule {
514516

515517
// @public
516518
export interface MatChipTextControl {
519+
readonly describedByIds?: string[];
517520
empty: boolean;
518521
focus(): void;
519522
focused: boolean;

goldens/material/datepicker/index.api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,7 @@ export class MatDateRangeInput<D> implements MatFormFieldControl<DateRange<D>>,
567567
controlType: string;
568568
get dateFilter(): DateFilterFn<D>;
569569
set dateFilter(value: DateFilterFn<D>);
570+
get describedByIds(): string[];
570571
readonly disableAutomaticLabeling = true;
571572
get disabled(): boolean;
572573
set disabled(value: boolean);

goldens/material/form-field/index.api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ export type MatFormFieldAppearance = 'fill' | 'outline';
156156
export abstract class MatFormFieldControl<T> {
157157
readonly autofilled?: boolean;
158158
readonly controlType?: string;
159+
readonly describedByIds?: string[];
159160
readonly disableAutomaticLabeling?: boolean;
160161
readonly disabled: boolean;
161162
readonly empty: boolean;

goldens/material/input/index.api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ export class MatInput implements MatFormFieldControl_2<any>, OnChanges, OnDestro
152152
constructor(...args: unknown[]);
153153
autofilled: boolean;
154154
controlType: string;
155+
get describedByIds(): string[];
155156
protected _dirtyCheckNativeValue(): void;
156157
get disabled(): boolean;
157158
set disabled(value: BooleanInput);

goldens/material/select/index.api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ export class MatSelect implements AfterContentInit, OnChanges, OnDestroy, OnInit
266266
customTrigger: MatSelectTrigger;
267267
// (undocumented)
268268
protected _defaultOptions: MatSelectConfig | null;
269+
get describedByIds(): string[];
269270
protected readonly _destroy: Subject<void>;
270271
readonly disableAutomaticLabeling = true;
271272
disabled: boolean;

src/material/chips/chip-grid.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,14 @@ export class MatChipGrid
349349
this.stateChanges.next();
350350
}
351351

352+
/**
353+
* Implemented as part of MatFormFieldControl.
354+
* @docs-private
355+
*/
356+
get describedByIds(): string[] {
357+
return this._chipInput?.describedByIds || [];
358+
}
359+
352360
/**
353361
* Implemented as part of MatFormFieldControl.
354362
* @docs-private

src/material/chips/chip-input.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,17 @@ export class MatChipInput implements MatChipTextControl, OnChanges, OnDestroy {
218218
this.inputElement.value = '';
219219
}
220220

221+
/**
222+
* Implemented as part of MatChipTextControl.
223+
* @docs-private
224+
*/
225+
get describedByIds(): string[] {
226+
const element = this._elementRef.nativeElement;
227+
const existingDescribedBy = element.getAttribute('aria-describedby');
228+
229+
return existingDescribedBy?.split(' ') || [];
230+
}
231+
221232
setDescribedByIds(ids: string[]): void {
222233
const element = this._elementRef.nativeElement;
223234

src/material/chips/chip-text-control.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ export interface MatChipTextControl {
2323
/** Focuses the text control. */
2424
focus(): void;
2525

26+
/** Gets the list of ids the input is described by. */
27+
readonly describedByIds?: string[];
28+
2629
/** Sets the list of ids the input is described by. */
2730
setDescribedByIds(ids: string[]): void;
2831
}

src/material/datepicker/date-range-input.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,14 @@ export class MatDateRangeInput<D>
284284
this.ngControl = inject(ControlContainer, {optional: true, self: true}) as any;
285285
}
286286

287+
/**
288+
* Implemented as part of MatFormFieldControl.
289+
* @docs-private
290+
*/
291+
get describedByIds(): string[] {
292+
return this._ariaDescribedBy?.split(' ') || [];
293+
}
294+
287295
/**
288296
* Implemented as a part of `MatFormFieldControl`.
289297
* @docs-private

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

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

78+
/** Gets the list of element IDs that currently describe this control. */
79+
readonly describedByIds?: string[];
80+
7881
/** Sets the list of element IDs that currently describe this control. */
7982
abstract setDescribedByIds(ids: string[]): void;
8083

0 commit comments

Comments
 (0)