Skip to content

Commit 09b25a1

Browse files
authoredMar 17, 2025
fix(material/chips): adds default placeholder for chips input (#30452)
* fix(material/chips): creates default aria-placeholder for chips input Updates Angular Components Chips input so that if no placeholder value is provided and if no ariaPlaceholder value is provided, that a default value will be used. This improves accessibility by providing an aria-placeholder value for VoiceControl to use as a name for the input. Fixes b/380092814 * refactor(material/chips): fix lint errors Updates to fix lint errors. * build(material/chips): updates build for chips.md Ran command to update chips.md. * fix(material/chips): fixes chips input demo moving input out of chip-grid Updates previous chips-demo.html so that the input element is not a child of chip-grid, but rather a sibling. When mat-chip-grid contains the input, it hides this as an interactive element from mobile Voice Controls making it inaccessible. Fixes b/380092814 * docs(material/chips): update chips docs based on aria-placeholder addition Updates documentation on chips.md regarding proper placement of the input element as a sibiling of as opposed to being a child. Also adds an explanation of the new implementation of ariaPlaceholder on mat-chip input. * refactor(material/chips): convert ariaPlaceholder to ariaLabel for chips input Updates previous fix to Angular Components chips input for using aria-placeholder and converts it to ariaLabel instead. For the chips-demo moved the input related to chip-grid to outside of chip-grid so that Voice Control is able to recognize input as an interactive element. If inside, the input is hidden from Voice Control making it not fully accessible. * refactor(material/chips): testing ariaLabel with input inside chip-grid Updating previous fix to see if ariaLabel will be read even if input is inside chip-grid. * refactor(material/chips): make recommended changes after review Updates previous fix by implementing recommended changes by reviewer. * refactor(material/chips): updates chips demo to use aria-label Updates previous change to Chips demo to use aria-label. * refactor(material/chips): removes commented out code Cleans up previous changes and removes unused code. * docs(material/chips): updates chips input accesibility recommendation Updates example which previously used ariaPlaceholder and instead uses an aria-label. * build(material/chips): updates build for chips.md Ran command to update chips.md api guard.
1 parent 43b0860 commit 09b25a1

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed
 

‎src/dev-app/chips/chips-demo.html

+12-6
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ <h4>Unstyled</h4>
2929
<mat-basic-chip-row>Basic Chip Row 1</mat-basic-chip-row>
3030
<mat-basic-chip-row>Basic Chip Row 2</mat-basic-chip-row>
3131
<mat-basic-chip-row>Basic Chip Row 3</mat-basic-chip-row>
32-
<input [matChipInputFor]="basicGrid" readonly>
3332
</mat-chip-grid>
33+
<input [matChipInputFor]="basicGrid" readonly>
3434

3535
<h4>With avatar, icons, and color</h4>
3636

@@ -185,11 +185,17 @@ <h4>Input is last child of chip grid</h4>
185185
</mat-chip-row>
186186
}
187187
<input [disabled]="disableInputs"
188-
[matChipInputFor]="chipGrid1"
189-
[matChipInputSeparatorKeyCodes]="separatorKeysCodes"
190-
[matChipInputAddOnBlur]="addOnBlur"
191-
(matChipInputTokenEnd)="add($event)" />
188+
[matChipInputFor]="chipGrid1"
189+
[matChipInputSeparatorKeyCodes]="separatorKeysCodes"
190+
[matChipInputAddOnBlur]="addOnBlur"
191+
(matChipInputTokenEnd)="add($event)"
192+
aria-label="New contributor input..." />
192193
</mat-chip-grid>
194+
<input [disabled]="disableInputs"
195+
[matChipInputFor]="chipGrid1"
196+
[matChipInputSeparatorKeyCodes]="separatorKeysCodes"
197+
[matChipInputAddOnBlur]="addOnBlur"
198+
(matChipInputTokenEnd)="add($event)" />
193199
</mat-form-field>
194200

195201
<h4>Input is next sibling child of chip grid</h4>
@@ -209,7 +215,7 @@ <h4>Input is next sibling child of chip grid</h4>
209215
<input [matChipInputFor]="chipGrid2"
210216
[matChipInputSeparatorKeyCodes]="separatorKeysCodes"
211217
[matChipInputAddOnBlur]="addOnBlur"
212-
(matChipInputTokenEnd)="add($event)" />
218+
(matChipInputTokenEnd)="add($event)"/>
213219
</mat-form-field>
214220

215221
<p>

‎src/material/chips/chips.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ The chips components support 3 user interaction patterns, each with its own cont
141141

142142
`<mat-chip-grid>` and `<mat-chip-row>` : These elements implement a grid accessibility pattern. Use them as part of a free form input that allows users to enter text to add chips.
143143

144+
Note : be sure to have the input element be a sibling of mat-chip-grid to ensure accessibility of the input element by accessibility devices such as Voice Control. It is also recommended to apply an appropriate `aria-label` to the input to optimize accessibility of the input.
145+
144146
```html
145147
<mat-form-field>
146148
<mat-chip-grid #myChipGrid [(ngModel)]="mySelection"
@@ -153,10 +155,11 @@ The chips components support 3 user interaction patterns, each with its own cont
153155
</button>
154156
</mat-chip-row>
155157
}
156-
<input [matChipInputFor]="myChipGrid"
157-
[matChipInputSeparatorKeyCodes]="separatorKeysCodes"
158-
(matChipInputTokenEnd)="add($event)" />
159158
</mat-chip-grid>
159+
<input [matChipInputFor]="myChipGrid"
160+
[matChipInputSeparatorKeyCodes]="separatorKeysCodes"
161+
(matChipInputTokenEnd)="add($event)"
162+
aria-label="Add sandwich fillings..." />
160163
</mat-form-field>
161164
```
162165

0 commit comments

Comments
 (0)
Failed to load comments.