Skip to content

Commit 17ce902

Browse files
committed
fix(material/chips): add support for aria-description
Add support for aria-description on mat-chip, mat-chip-option and mat-chip-row. mat-chip-option and mat-chip-row put aria-desciprtion on the same element that already has the aria-label. aria-description is needed for when developers need to provide more information that in the aria-label. This is especially needed for chip-row when [editable]="true". That's because it gives a way to communicate to screen reader users how to begin editing a chip.
1 parent 7e3a9df commit 17ce902

File tree

8 files changed

+14
-5
lines changed

8 files changed

+14
-5
lines changed

src/components-examples/material/chips/chips-input/chips-input-example.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
<mat-chip-row *ngFor="let fruit of fruits"
55
(removed)="remove(fruit)"
66
[editable]="true"
7-
(edited)="edit(fruit, $event)">
7+
(edited)="edit(fruit, $event)"
8+
[aria-description]="'press enter to edit ' + fruit.name">
89
{{fruit.name}}
9-
<button matChipRemove [attr.aria-label]="'remove ' + fruit">
10+
<button matChipRemove [attr.aria-label]="'remove ' + fruit.name">
1011
<mat-icon>cancel</mat-icon>
1112
</button>
1213
</mat-chip-row>

src/components-examples/material/chips/chips-input/chips-input-example.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export class ChipsInputExample {
5050

5151
// Edit existing fruit
5252
const index = this.fruits.indexOf(fruit);
53-
if (index > 0) {
53+
if (index >= 0) {
5454
this.fruits[index].name = value;
5555
}
5656
}

src/material/chips/chip-option.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
[_allowFocusWhenDisabled]="true"
1212
[attr.aria-selected]="ariaSelected"
1313
[attr.aria-label]="ariaLabel"
14+
[attr.aria-description]="ariaDescription"
1415
role="option">
1516
<span class="mdc-evolution-chip__graphic mat-mdc-chip-graphic" *ngIf="_hasLeadingGraphic()">
1617
<ng-content select="mat-chip-avatar, [matChipAvatar]"></ng-content>

src/material/chips/chip-option.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export class MatChipSelectionChange {
6464
'[class.mat-mdc-chip-with-trailing-icon]': '_hasTrailingIcon()',
6565
'[attr.tabindex]': 'null',
6666
'[attr.aria-label]': 'null',
67+
'[attr.aria-description]': 'null',
6768
'[attr.role]': 'role',
6869
'[id]': 'id',
6970
},

src/material/chips/chip-row.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
[attr.role]="editable ? 'button' : null"
1414
[tabIndex]="tabIndex"
1515
[disabled]="disabled"
16-
[attr.aria-label]="ariaLabel">
16+
[attr.aria-label]="ariaLabel"
17+
[attr.aria-description]="ariaDescription">
1718
<span class="mdc-evolution-chip__graphic mat-mdc-chip-graphic" *ngIf="leadingIcon">
1819
<ng-content select="mat-chip-avatar, [matChipAvatar]"></ng-content>
1920
</span>

src/material/chips/chip-row.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export interface MatChipEditedEvent extends MatChipEvent {
6464
'[id]': 'id',
6565
'[attr.tabindex]': 'null',
6666
'[attr.aria-label]': 'null',
67+
'[attr.aria-description]': 'null',
6768
'[attr.role]': 'role',
6869
'(mousedown)': '_mousedown($event)',
6970
'(dblclick)': '_doubleclick($event)',

src/material/chips/chip.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ export class MatChip
150150
/** ARIA label for the content of the chip. */
151151
@Input('aria-label') ariaLabel: string | null = null;
152152

153+
/** ARIA description for the content of the chip. */
154+
@Input('aria-description') ariaDescription: string | null = null;
155+
153156
private _textElement!: HTMLElement;
154157

155158
/**

tools/public_api_guard/material/chips.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export const MAT_CHIPS_DEFAULT_OPTIONS: InjectionToken<MatChipsDefaultOptions>;
6565
export class MatChip extends _MatChipMixinBase implements AfterViewInit, CanColor, CanDisableRipple, CanDisable, HasTabIndex, OnDestroy {
6666
constructor(_changeDetectorRef: ChangeDetectorRef, elementRef: ElementRef<HTMLElement>, _ngZone: NgZone, _focusMonitor: FocusMonitor, _document: any, animationMode?: string, _globalRippleOptions?: RippleGlobalOptions | undefined, tabIndex?: string);
6767
_animationsDisabled: boolean;
68+
ariaDescription: string | null;
6869
ariaLabel: string | null;
6970
protected basicChipAttrName: string;
7071
// (undocumented)
@@ -113,7 +114,7 @@ export class MatChip extends _MatChipMixinBase implements AfterViewInit, CanColo
113114
// (undocumented)
114115
protected _value: any;
115116
// (undocumented)
116-
static ɵcmp: i0.ɵɵComponentDeclaration<MatChip, "mat-basic-chip, mat-chip", ["matChip"], { "color": "color"; "disabled": "disabled"; "disableRipple": "disableRipple"; "tabIndex": "tabIndex"; "role": "role"; "id": "id"; "ariaLabel": "aria-label"; "value": "value"; "removable": "removable"; "highlighted": "highlighted"; }, { "removed": "removed"; "destroyed": "destroyed"; }, ["leadingIcon", "trailingIcon", "removeIcon"], ["mat-chip-avatar, [matChipAvatar]", "*", "mat-chip-trailing-icon,[matChipRemove],[matChipTrailingIcon]"], false, never>;
117+
static ɵcmp: i0.ɵɵComponentDeclaration<MatChip, "mat-basic-chip, mat-chip", ["matChip"], { "color": "color"; "disabled": "disabled"; "disableRipple": "disableRipple"; "tabIndex": "tabIndex"; "role": "role"; "id": "id"; "ariaLabel": "aria-label"; "ariaDescription": "aria-description"; "value": "value"; "removable": "removable"; "highlighted": "highlighted"; }, { "removed": "removed"; "destroyed": "destroyed"; }, ["leadingIcon", "trailingIcon", "removeIcon"], ["mat-chip-avatar, [matChipAvatar]", "*", "mat-chip-trailing-icon,[matChipRemove],[matChipTrailingIcon]"], false, never>;
117118
// (undocumented)
118119
static ɵfac: i0.ɵɵFactoryDeclaration<MatChip, [null, null, null, null, null, { optional: true; }, { optional: true; }, { attribute: "tabindex"; }]>;
119120
}

0 commit comments

Comments
 (0)