Skip to content

Commit 53ffc0e

Browse files
committed
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.
1 parent 0aad0fa commit 53ffc0e

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

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

Lines changed: 2 additions & 2 deletions
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

@@ -210,7 +210,7 @@ <h4>Input is next sibling child of chip grid</h4>
210210
[matChipInputSeparatorKeyCodes]="separatorKeysCodes"
211211
[matChipInputAddOnBlur]="addOnBlur"
212212
(matChipInputTokenEnd)="add($event)"
213-
ariaPlaceholder="New contributor input..." />
213+
ariaLabel="New contributor input..." />
214214
</mat-form-field>
215215

216216
<p>

src/material/chips/chip-input.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export interface MatChipInputEvent {
5959
'[id]': 'id',
6060
'[attr.disabled]': 'disabled || null',
6161
'[attr.placeholder]': 'placeholder || null',
62-
'[attr.aria-placeholder]': 'getAriaPlaceholder()',
62+
'[attr.aria-label]': 'ariaLabel || null',
6363
'[attr.aria-invalid]': '_chipGrid && _chipGrid.ngControl ? _chipGrid.ngControl.invalid : null',
6464
'[attr.aria-required]': '_chipGrid && _chipGrid.required || null',
6565
'[attr.required]': '_chipGrid && _chipGrid.required || null',
@@ -105,8 +105,11 @@ export class MatChipInput implements MatChipTextControl, OnChanges, OnDestroy {
105105
/** The input's placeholder text. */
106106
@Input() placeholder: string = '';
107107

108-
/** Screenreader placeholder for the input, only used if placeholder is not provided. */
109-
@Input() ariaPlaceholder: string | null;
108+
/**
109+
* Aria-label for the input. Optional, but highly recommended to improve
110+
* accessibility for Voice Control naming/usage of the entering input field itself.
111+
*/
112+
@Input() ariaLabel: string | null;
110113

111114
/** Unique id for the input. */
112115
@Input() id: string = inject(_IdGenerator).getId('mat-mdc-chip-list-input-');
@@ -129,12 +132,6 @@ export class MatChipInput implements MatChipTextControl, OnChanges, OnDestroy {
129132
/** The native input element to which this directive is attached. */
130133
readonly inputElement!: HTMLInputElement;
131134

132-
/**
133-
* Default Screen-reader placeholder for the input if no placeholder or
134-
* ariaPlaceholder is provided.
135-
*/
136-
private readonly _defaultAriaPlaceholder = 'Enter input';
137-
138135
constructor(...args: unknown[]);
139136

140137
constructor() {
@@ -234,11 +231,11 @@ export class MatChipInput implements MatChipTextControl, OnChanges, OnDestroy {
234231
return !hasModifierKey(event) && new Set(this.separatorKeyCodes).has(event.keyCode);
235232
}
236233

237-
/**
238-
* Checks whether placeholder is used, if not checks for ariaPlaceholder, and resorts
239-
* to default value if neither is provided.
240-
*/
241-
getAriaPlaceholder(): string | null {
242-
return this.placeholder ? null : this.ariaPlaceholder || this._defaultAriaPlaceholder;
243-
}
234+
// /**
235+
// * Checks whether placeholder is used, if not checks for ariaPlaceholder, and resorts
236+
// * to default value if neither is provided.
237+
// */
238+
// getAriaPlaceholder(): string | null {
239+
// return this.placeholder ? null : this.ariaPlaceholder || null;
240+
// }
244241
}

0 commit comments

Comments
 (0)