Skip to content

Commit 3f78cda

Browse files
jackfranklinDevtools-frontend LUCI CQ
authored andcommitted
RPP: add aria-label to <button> in DevTools button
This helps screen-readers whereas an aria-label on the devtools-button element is not always read out (see attached bug for guidance from a11y). Bug: 447625868 Change-Id: Idae3f5a886dc88dd10207997000e62f11216db0e Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/7002767 Commit-Queue: Jack Franklin <[email protected]> Commit-Queue: Ergün Erdoğmuş <[email protected]> Auto-Submit: Jack Franklin <[email protected]> Reviewed-by: Ergün Erdoğmuş <[email protected]>
1 parent 6a9b9c3 commit 3f78cda

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

front_end/panels/timeline/components/ExportTraceOptions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ export class ExportTraceOptions extends HTMLElement {
235235
${checkboxesWithInfoDialog.has(checkboxId) ? html`
236236
<devtools-button
237237
aria-details=${`export-trace-tooltip-${checkboxId}`}
238-
aria-label=${this.#accessibleLabelForInfoCheckbox(checkboxId)}
238+
.accessibleLabel=${this.#accessibleLabelForInfoCheckbox(checkboxId)}
239239
class="pen-icon"
240240
.iconName=${'info'}
241241
.variant=${Buttons.Button.Variant.ICON}

front_end/ui/components/buttons/Button.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,13 @@ describe('Button', () => {
210210
assert.isAbove(buttonHeight, 0);
211211
});
212212

213+
it('sets the accessible label on the internal button', async () => {
214+
const button = renderButton({variant: Buttons.Button.Variant.PRIMARY, iconName, accessibleLabel: 'test-label'}, '');
215+
const innerButton = button.shadowRoot?.querySelector('button');
216+
assert.isOk(innerButton);
217+
assert.strictEqual(innerButton.getAttribute('aria-label'), 'test-label');
218+
});
219+
213220
describe('in forms', () => {
214221
function renderForm(data: Buttons.Button.ButtonData = {
215222
variant: Buttons.Button.Variant.PRIMARY,

front_end/ui/components/buttons/Button.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ interface ButtonState {
6363
jslogContext?: string;
6464
longClickable?: boolean;
6565
inverseColorTheme?: boolean;
66+
/**
67+
* Sets aria-label on the internal <button> element.
68+
*/
69+
accessibleLabel?: string;
6670
}
6771

6872
interface CommonButtonData {
@@ -84,6 +88,10 @@ interface CommonButtonData {
8488
jslogContext?: string;
8589
longClickable?: boolean;
8690
inverseColorTheme?: boolean;
91+
/**
92+
* Sets aria-label on the internal <button> element.
93+
*/
94+
accessibleLabel?: string;
8795
}
8896

8997
export type ButtonData = CommonButtonData&(|{
@@ -143,6 +151,9 @@ export class Button extends HTMLElement {
143151
if ('size' in data && data.size) {
144152
this.#props.size = data.size;
145153
}
154+
if (data.accessibleLabel) {
155+
this.#props.accessibleLabel = data.accessibleLabel;
156+
}
146157

147158
this.#props.active = Boolean(data.active);
148159
this.#props.spinner = Boolean('spinner' in data ? data.spinner : false);
@@ -187,6 +198,11 @@ export class Button extends HTMLElement {
187198
this.#render();
188199
}
189200

201+
set accessibleLabel(label: string) {
202+
this.#props.accessibleLabel = label;
203+
this.#render();
204+
}
205+
190206
set reducedFocusRing(reducedFocusRing: boolean) {
191207
this.#props.reducedFocusRing = reducedFocusRing;
192208
this.#render();
@@ -357,6 +373,7 @@ export class Button extends HTMLElement {
357373
.disabled=${this.#props.disabled}
358374
class=${classMap(classes)}
359375
aria-pressed=${ifDefined(this.#props.toggled)}
376+
aria-label=${ifDefined(this.#props.accessibleLabel)}
360377
jslog=${ifDefined(jslog)}>
361378
${hasIcon ? html`
362379
<devtools-icon name=${ifDefined(this.#props.toggled ? this.#props.toggledIconName : this.#props.iconName)}>

0 commit comments

Comments
 (0)