Skip to content

Commit 2252c9a

Browse files
committed
fix(material/timepicker): adds default timepicker toggle aria-label
Updates Angular Components Timepicker component by creating a default aria-label to the timepicker toggle if one is not supplied. This makes the button more accessible and descriptive for screen readers. Fix b/380308482
1 parent f3a9a31 commit 2252c9a

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ <h2>Basic timepicker</h2>
1111
[matTimepickerMax]="maxControl.value"
1212
[formControl]="control">
1313
<mat-timepicker [interval]="intervalControl.value" #basicPicker/>
14-
<mat-timepicker-toggle [for]="basicPicker" aria-labelledby="mat-mdc-form-field-label-0" matSuffix/>
14+
<mat-timepicker-toggle [for]="basicPicker" matSuffix/>
1515
</mat-form-field>
1616

1717
<p>Value: {{control.value}}</p>

src/material/timepicker/timepicker-toggle.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
mat-icon-button
33
type="button"
44
aria-haspopup="listbox"
5-
[attr.aria-label]="ariaLabel()"
5+
[attr.aria-label]="getAriaLabel()"
66
[attr.aria-labelledby]="ariaLabelledby()"
77
[attr.aria-expanded]="timepicker().isOpen()"
88
[attr.tabindex]="_isDisabled() ? -1 : tabIndex()"

src/material/timepicker/timepicker-toggle.ts

+12
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ export class MatTimepickerToggle<D> {
6767
alias: 'aria-labelledby',
6868
});
6969

70+
/** Default aria-label for the toggle if none is provided. */
71+
private readonly defaultAriaLabel = 'Open timepicker options';
72+
7073
/** Whether the toggle button is disabled. */
7174
readonly disabled: InputSignalWithTransform<boolean, unknown> = input(false, {
7275
transform: booleanAttribute,
@@ -89,4 +92,13 @@ export class MatTimepickerToggle<D> {
8992
event.stopPropagation();
9093
}
9194
}
95+
96+
/**
97+
* Gets the aria-label to use for the toggle button.
98+
* Returns the user-provided aria-label if one exists,
99+
* otherwise returns the default aria-label using the timepicker's panelId.
100+
*/
101+
getAriaLabel(): string {
102+
return this.ariaLabel() || this.defaultAriaLabel;
103+
}
92104
}

0 commit comments

Comments
 (0)