Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions packages/player/src/controls.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
4 changes: 3 additions & 1 deletion packages/player/src/controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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) {
Expand Down
Loading