Skip to content

feat(material/chips): update chip-list describedby to match input #24292

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

Merged
merged 1 commit into from
Feb 14, 2022
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: 11 additions & 5 deletions src/material/chips/chip-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ export class MatChipListChange {
exportAs: 'matChipList',
host: {
'[attr.tabindex]': 'disabled ? null : _tabIndex',
'[attr.aria-describedby]': '_ariaDescribedby || null',
'[attr.aria-required]': 'role ? required : null',
'[attr.aria-disabled]': 'disabled.toString()',
'[attr.aria-invalid]': 'errorState',
Expand Down Expand Up @@ -144,9 +143,6 @@ export class MatChipList
/** Uid of the chip list */
_uid: string = `mat-chip-list-${nextUniqueId++}`;

/** The aria-describedby attribute on the chip list for improved a11y. */
_ariaDescribedby: string;

/** Tab index for the chip list. */
_tabIndex = 0;

Expand Down Expand Up @@ -177,6 +173,12 @@ export class MatChipList
return this.empty ? null : 'listbox';
}

/**
* Implemented as part of MatFormFieldControl.
* @docs-private
*/
@Input('aria-describedby') userAriaDescribedBy: string;

/** An object used to control when error messages are shown. */
@Input() override errorStateMatcher: ErrorStateMatcher;

Expand Down Expand Up @@ -455,7 +457,11 @@ export class MatChipList
* @docs-private
*/
setDescribedByIds(ids: string[]) {
this._ariaDescribedby = ids.join(' ');
if (ids.length) {
this._elementRef.nativeElement.setAttribute('aria-describedby', ids.join(' '));
} else {
this._elementRef.nativeElement.removeAttribute('aria-describedby');
}
}

// Implemented as part of ControlValueAccessor.
Expand Down
4 changes: 2 additions & 2 deletions tools/public_api_guard/material/chips.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ export interface MatChipInputEvent {
export class MatChipList extends _MatChipListBase implements MatFormFieldControl<any>, ControlValueAccessor, AfterContentInit, DoCheck, OnInit, OnDestroy, CanUpdateErrorState {
constructor(_elementRef: ElementRef<HTMLElement>, _changeDetectorRef: ChangeDetectorRef, _dir: Directionality, _parentForm: NgForm, _parentFormGroup: FormGroupDirective, _defaultErrorStateMatcher: ErrorStateMatcher, ngControl: NgControl);
_allowFocusEscape(): void;
_ariaDescribedby: string;
ariaOrientation: 'horizontal' | 'vertical';
_blur(): void;
readonly change: EventEmitter<MatChipListChange>;
Expand Down Expand Up @@ -255,6 +254,7 @@ export class MatChipList extends _MatChipListBase implements MatFormFieldControl
_uid: string;
protected _updateFocusForDestroyedChips(): void;
protected _updateTabIndex(): void;
userAriaDescribedBy: string;
_userTabIndex: number | null;
get value(): any;
set value(value: any);
Expand All @@ -264,7 +264,7 @@ export class MatChipList extends _MatChipListBase implements MatFormFieldControl
// (undocumented)
writeValue(value: any): void;
// (undocumented)
static ɵcmp: i0.ɵɵComponentDeclaration<MatChipList, "mat-chip-list", ["matChipList"], { "errorStateMatcher": "errorStateMatcher"; "multiple": "multiple"; "compareWith": "compareWith"; "value": "value"; "required": "required"; "placeholder": "placeholder"; "disabled": "disabled"; "ariaOrientation": "aria-orientation"; "selectable": "selectable"; "tabIndex": "tabIndex"; }, { "change": "change"; "valueChange": "valueChange"; }, ["chips"], ["*"]>;
static ɵcmp: i0.ɵɵComponentDeclaration<MatChipList, "mat-chip-list", ["matChipList"], { "userAriaDescribedBy": "aria-describedby"; "errorStateMatcher": "errorStateMatcher"; "multiple": "multiple"; "compareWith": "compareWith"; "value": "value"; "required": "required"; "placeholder": "placeholder"; "disabled": "disabled"; "ariaOrientation": "aria-orientation"; "selectable": "selectable"; "tabIndex": "tabIndex"; }, { "change": "change"; "valueChange": "valueChange"; }, ["chips"], ["*"]>;
// (undocumented)
static ɵfac: i0.ɵɵFactoryDeclaration<MatChipList, [null, null, { optional: true; }, { optional: true; }, { optional: true; }, null, { optional: true; self: true; }]>;
}
Expand Down