Skip to content

Commit f77684a

Browse files
authored
feat(a11y): add aria-labels to toolbar icons for screen reader suppor… (#6309)
* feat(a11y): add aria-labels to toolbar icons for screen reader support (#5948) - Add aria-label to play, stop, fullscreen, new project, open, save, planet, menu and help toolbar icons in index.html - Add keydown Enter/Space handlers in toolbar.js for play and stop - Addresses WCAG 2.1 AA screen reader accessibility requirements * feat(a11y): add aria-labels to toolbar icons for screen reader support (#5948) * Fix toolbar tests: add setAttribute mock for aria-label changes * fix(a11y): wrap aria-label strings in _() for i18n
1 parent 4bf55d0 commit f77684a

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

js/__tests__/toolbar.test.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,15 +237,18 @@ describe("Toolbar Class", () => {
237237
const elements = {
238238
play: {
239239
onclick: null,
240-
addEventListener: jest.fn()
240+
addEventListener: jest.fn(),
241+
setAttribute: jest.fn()
241242
},
242243
stop: {
243244
style: { color: "" },
244245
addEventListener: jest.fn(),
245-
removeEventListener: jest.fn()
246+
removeEventListener: jest.fn(),
247+
setAttribute: jest.fn()
246248
},
247249
record: {
248-
className: ""
250+
className: "",
251+
setAttribute: jest.fn()
249252
}
250253
};
251254

@@ -284,7 +287,12 @@ describe("Toolbar Class", () => {
284287
});
285288

286289
test("renderStopIcon sets onclick and updates stop button behavior", () => {
287-
const stopIcon = { onclick: null, style: { color: "" } };
290+
const stopIcon = {
291+
onclick: null,
292+
style: { color: "" },
293+
setAttribute: jest.fn(),
294+
addEventListener: jest.fn()
295+
};
288296
const recordButton = { className: "recording" };
289297

290298
global.docById.mockImplementation(id =>

js/toolbar.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,15 @@ class Toolbar {
467467
const playIcon = docById("play");
468468
const stopIcon = docById("stop");
469469
const recordButton = docById("record");
470+
playIcon.setAttribute("role", "button");
471+
playIcon.setAttribute("aria-label", _("Play project"));
472+
playIcon.setAttribute("tabindex", "0");
473+
playIcon.addEventListener("keydown", e => {
474+
if (e.key === "Enter" || e.key === " ") {
475+
e.preventDefault();
476+
playIcon.click();
477+
}
478+
});
470479
let isPlayIconRunning = false;
471480

472481
function handleClick() {
@@ -520,6 +529,15 @@ class Toolbar {
520529
renderStopIcon(onclick) {
521530
const stopIcon = docById("stop");
522531
const recordButton = docById("record");
532+
stopIcon.setAttribute("role", "button");
533+
stopIcon.setAttribute("aria-label", _("Stop project"));
534+
stopIcon.setAttribute("tabindex", "0");
535+
stopIcon.addEventListener("keydown", e => {
536+
if (e.key === "Enter" || e.key === " ") {
537+
e.preventDefault();
538+
stopIcon.click();
539+
}
540+
});
523541
stopIcon.onclick = () => {
524542
onclick(this.activity);
525543
stopIcon.style.color = "white";

0 commit comments

Comments
 (0)