Skip to content

Commit e5c3ddf

Browse files
authored
fix(material/timepicker): adds default aria-label to timepicker toggle (#30284)
* fix(material/timepicker): adds aria-labelledby to timepicker toggle Updates Angular Component Timepicker so the timepicker toggle uses the aria-labelledby value for the timepicker toggle button to make it more accessible. Fixes b/380308482 * 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 * refactor(material/timepicker): fix lint error Updates previous fix to fix lint error. * build(material/timepicker): updates api goldens Ran command to update api goldens. * refactor(material/timepicker): adds check for aria-labelledby for override Updates previous fix which implements a default aria-label if no custom aria-label is provided to where it checks if an aria-lablledby value is provided and uses the aria-labelledby value if available. If not it will check for a custom aria-label and if that is not provided it will default to the generic aria-label value.
1 parent ff8cffc commit e5c3ddf

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/material/timepicker/timepicker-toggle.html

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

src/material/timepicker/timepicker-toggle.ts

+16
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ export class MatTimepickerToggle<D> {
6262
alias: 'aria-label',
6363
});
6464

65+
/** Screen-reader labelled by id for the button. */
66+
readonly ariaLabelledby = input<string | undefined>(undefined, {
67+
alias: 'aria-labelledby',
68+
});
69+
70+
/** Default aria-label for the toggle if none is provided. */
71+
private readonly _defaultAriaLabel = 'Open timepicker options';
72+
6573
/** Whether the toggle button is disabled. */
6674
readonly disabled: InputSignalWithTransform<boolean, unknown> = input(false, {
6775
transform: booleanAttribute,
@@ -84,4 +92,12 @@ export class MatTimepickerToggle<D> {
8492
event.stopPropagation();
8593
}
8694
}
95+
96+
/**
97+
* Checks for ariaLabelledby and if empty uses custom
98+
* aria-label or defaultAriaLabel if neither is provided.
99+
*/
100+
getAriaLabel(): string | null {
101+
return this.ariaLabelledby() ? null : this.ariaLabel() || this._defaultAriaLabel;
102+
}
87103
}

tools/public_api_guard/material/timepicker.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,17 @@ export interface MatTimepickerSelected<D> {
124124
// @public
125125
export class MatTimepickerToggle<D> {
126126
readonly ariaLabel: InputSignal<string | undefined>;
127+
readonly ariaLabelledby: InputSignal<string | undefined>;
127128
readonly disabled: InputSignalWithTransform<boolean, unknown>;
128129
readonly disableRipple: InputSignalWithTransform<boolean, unknown>;
130+
getAriaLabel(): string | null;
129131
// (undocumented)
130132
protected _isDisabled: Signal<boolean>;
131133
protected _open(event: Event): void;
132134
readonly tabIndex: InputSignal<number | null>;
133135
readonly timepicker: InputSignal<MatTimepicker<D>>;
134136
// (undocumented)
135-
static ɵcmp: i0.ɵɵComponentDeclaration<MatTimepickerToggle<any>, "mat-timepicker-toggle", ["matTimepickerToggle"], { "timepicker": { "alias": "for"; "required": true; "isSignal": true; }; "ariaLabel": { "alias": "aria-label"; "required": false; "isSignal": true; }; "disabled": { "alias": "disabled"; "required": false; "isSignal": true; }; "tabIndex": { "alias": "tabIndex"; "required": false; "isSignal": true; }; "disableRipple": { "alias": "disableRipple"; "required": false; "isSignal": true; }; }, {}, never, ["[matTimepickerToggleIcon]"], true, never>;
137+
static ɵcmp: i0.ɵɵComponentDeclaration<MatTimepickerToggle<any>, "mat-timepicker-toggle", ["matTimepickerToggle"], { "timepicker": { "alias": "for"; "required": true; "isSignal": true; }; "ariaLabel": { "alias": "aria-label"; "required": false; "isSignal": true; }; "ariaLabelledby": { "alias": "aria-labelledby"; "required": false; "isSignal": true; }; "disabled": { "alias": "disabled"; "required": false; "isSignal": true; }; "tabIndex": { "alias": "tabIndex"; "required": false; "isSignal": true; }; "disableRipple": { "alias": "disableRipple"; "required": false; "isSignal": true; }; }, {}, never, ["[matTimepickerToggleIcon]"], true, never>;
136138
// (undocumented)
137139
static ɵfac: i0.ɵɵFactoryDeclaration<MatTimepickerToggle<any>, never>;
138140
}

0 commit comments

Comments
 (0)