Skip to content

Commit 84012a0

Browse files
committed
fix(player): include visible playback rate in accessible name
1 parent cfdddd8 commit 84012a0

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

‎packages/player/src/controls.test.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,30 @@ describe("createControls host listeners", () => {
7676
host.remove();
7777
});
7878
});
79+
80+
describe("createControls playback speed name", () => {
81+
it("includes the visible rate initially and after menu and API updates", () => {
82+
const host = document.createElement("div");
83+
const onSpeedChange = vi.fn();
84+
const api = createControls(host, { ...noopCallbacks(), onSpeedChange });
85+
const speedButton = host.querySelector(".hfp-speed-btn");
86+
87+
expect(speedButton?.textContent).toBe("1x");
88+
expect(speedButton?.getAttribute("aria-label")).toBe("Playback speed: 1x");
89+
90+
const option = host.querySelector<HTMLButtonElement>('[data-speed="1.5"]');
91+
expect(option).not.toBeNull();
92+
option?.click();
93+
94+
expect(speedButton?.textContent).toBe("1.5x");
95+
expect(speedButton?.getAttribute("aria-label")).toBe("Playback speed: 1.5x");
96+
expect(onSpeedChange).toHaveBeenCalledWith(1.5);
97+
98+
api.updateSpeed(2);
99+
100+
expect(speedButton?.textContent).toBe("2x");
101+
expect(speedButton?.getAttribute("aria-label")).toBe("Playback speed: 2x");
102+
103+
api.destroy();
104+
});
105+
});

‎packages/player/src/controls.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export function createControls(
101101
speedBtn.className = "hfp-speed-btn";
102102
speedBtn.type = "button";
103103
speedBtn.textContent = "1x";
104-
speedBtn.setAttribute("aria-label", "Playback speed");
104+
speedBtn.setAttribute("aria-label", "Playback speed: 1x");
105105

106106
const speedMenu = document.createElement("div");
107107
speedMenu.className = "hfp-speed-menu";
@@ -273,6 +273,7 @@ export function createControls(
273273
const newSpeed = parseFloat(target.dataset.speed!);
274274
speedIndex = presets.indexOf(newSpeed);
275275
speedBtn.textContent = formatSpeed(newSpeed);
276+
speedBtn.setAttribute("aria-label", `Playback speed: ${formatSpeed(newSpeed)}`);
276277
setActiveOption(newSpeed);
277278
speedMenu.classList.remove("hfp-open");
278279
speedBtn.setAttribute("aria-expanded", "false");
@@ -374,6 +375,7 @@ export function createControls(
374375
const idx = presets.indexOf(speed);
375376
if (idx !== -1) speedIndex = idx;
376377
speedBtn.textContent = formatSpeed(speed);
378+
speedBtn.setAttribute("aria-label", `Playback speed: ${formatSpeed(speed)}`);
377379
setActiveOption(speed);
378380
},
379381
updateMuted(muted: boolean) {

0 commit comments

Comments
 (0)