fix(player): include visible playback rate in accessible name (#6032)

This commit is contained in:
Dante
2026-10-24 07:18:36 +00:00
committed by GitHub
parent c9ab2796af
commit 8b1bf6b914
2 changed files with 30 additions and 1 deletions
+27
View File
@@ -76,3 +76,30 @@ describe("createControls host listeners", () => {
host.remove();
});
});
describe("createControls playback speed name", () => {
it("includes the visible rate initially and after menu and API updates", () => {
const host = document.createElement("div");
const onSpeedChange = vi.fn();
const api = createControls(host, { ...noopCallbacks(), onSpeedChange });
const speedButton = host.querySelector(".hfp-speed-btn");
expect(speedButton?.textContent).toBe("1x");
expect(speedButton?.getAttribute("aria-label")).toBe("Playback speed: 1x");
const option = host.querySelector<HTMLButtonElement>('[data-speed="1.5"]');
expect(option).not.toBeNull();
option?.click();
expect(speedButton?.textContent).toBe("1.5x");
expect(speedButton?.getAttribute("aria-label")).toBe("Playback speed: 1.5x");
expect(onSpeedChange).toHaveBeenCalledWith(1.5);
api.updateSpeed(2);
expect(speedButton?.textContent).toBe("2x");
expect(speedButton?.getAttribute("aria-label")).toBe("Playback speed: 2x");
api.destroy();
});
});
+3 -1
View File
@@ -101,7 +101,7 @@ export function createControls(
speedBtn.className = "hfp-speed-btn";
speedBtn.type = "button";
speedBtn.textContent = "1x";
speedBtn.setAttribute("aria-label", "Playback speed");
speedBtn.setAttribute("aria-label", "Playback speed: 1x");
const speedMenu = document.createElement("div");
speedMenu.className = "hfp-speed-menu";
@@ -273,6 +273,7 @@ export function createControls(
const newSpeed = parseFloat(target.dataset.speed!);
speedIndex = presets.indexOf(newSpeed);
speedBtn.textContent = formatSpeed(newSpeed);
speedBtn.setAttribute("aria-label", `Playback speed: ${formatSpeed(newSpeed)}`);
setActiveOption(newSpeed);
speedMenu.classList.remove("hfp-open");
speedBtn.setAttribute("aria-expanded", "false");
@@ -374,6 +375,7 @@ export function createControls(
const idx = presets.indexOf(speed);
if (idx !== -1) speedIndex = idx;
speedBtn.textContent = formatSpeed(speed);
speedBtn.setAttribute("aria-label", `Playback speed: ${formatSpeed(speed)}`);
setActiveOption(speed);
},
updateMuted(muted: boolean) {