From 8f2bad22c44f998db7b8dcf449f4e8da8761cd06 Mon Sep 17 00:00:00 2001 From: XZH Date: Mon, 14 Sep 2026 18:22:27 -0700 Subject: [PATCH] fix(reading): keep mobile toolbar actions reachable --- web/components/reading/ReaderPane.tsx | 123 ++++++++++++++++++- web/tests/reading-toolbar-selection.spec.tsx | 37 +++++- 2 files changed, 157 insertions(+), 3 deletions(-) diff --git a/web/components/reading/ReaderPane.tsx b/web/components/reading/ReaderPane.tsx index 30d4db694..17a29c646 100644 --- a/web/components/reading/ReaderPane.tsx +++ b/web/components/reading/ReaderPane.tsx @@ -11,6 +11,7 @@ import { Crosshair, Download, FileText, + MoreHorizontal, Loader2, History, PanelRightClose, @@ -209,6 +210,7 @@ export function ReaderPane({ string | null | undefined >(undefined); const [showHistory, setShowHistory] = useState(false); + const [showMoreTools, setShowMoreTools] = useState(false); const [unavailableMaterials, setUnavailableMaterials] = useState>( new Set(), ); @@ -773,12 +775,14 @@ export function ReaderPane({ locationHistory.index >= locationHistory.entries.length - 1 } onClick={() => stepHistory(1)} + className="hidden md:inline-flex" /> setShowHistory((current) => !current)} + className="hidden md:inline-flex" /> )} @@ -788,7 +792,7 @@ export function ReaderPane({ {/* The one place the reader's position is stated. Monospace is for code, not for a line of UI copy; tabular figures alone stop the number from jittering as the learner scrolls. */} - + {t("{{unit}} {{n}} / {{total}}", { unit: unitWord, n: currentLocator, @@ -822,12 +826,14 @@ export function ReaderPane({ } active={autoJump} onClick={toggleAutoJump} + className="hidden md:inline-flex" /> void runExport()} + className="hidden md:inline-flex" /> )} + {material && ( + { + setShowMoreTools(!showMoreTools); + if (!showMoreTools) setShowHistory(false); + }} + className="inline-flex md:hidden" + /> + )} + {showMoreTools && material && ( +
+ {locationHistory.entries.length > 0 && ( + <> + = locationHistory.entries.length - 1 + } + onClick={() => { + stepHistory(1); + setShowMoreTools(false); + }} + /> + { + setShowHistory(true); + setShowMoreTools(false); + }} + /> + + )} + + { + void runExport(); + setShowMoreTools(false); + }} + /> +
+ )} + {showHistory && locationHistory.entries.length > 0 && (
{[...locationHistory.entries] @@ -1027,6 +1099,7 @@ function HeaderButton({ active, spinning, disabled, + menu = false, className = "", }: { icon: typeof FileText; @@ -1035,6 +1108,7 @@ function HeaderButton({ active?: boolean; spinning?: boolean; disabled?: boolean; + menu?: boolean; className?: string; }) { return ( @@ -1042,7 +1116,9 @@ function HeaderButton({ type="button" title={label} aria-label={label} - aria-pressed={active} + aria-pressed={menu ? undefined : active} + aria-haspopup={menu ? "menu" : undefined} + aria-expanded={menu ? active : undefined} disabled={spinning || disabled} onClick={onClick} className={`h-7 w-7 shrink-0 items-center justify-center rounded-lg transition disabled:cursor-default ${ @@ -1057,3 +1133,46 @@ function HeaderButton({ ); } + +function MenuToolButton({ + icon: Icon, + label, + onClick, + active, + spinning, + disabled, +}: { + icon: typeof FileText; + label: string; + onClick: () => void; + active?: boolean; + spinning?: boolean; + disabled?: boolean; +}) { + return ( + + ); +} diff --git a/web/tests/reading-toolbar-selection.spec.tsx b/web/tests/reading-toolbar-selection.spec.tsx index f17033079..5518d4adf 100644 --- a/web/tests/reading-toolbar-selection.spec.tsx +++ b/web/tests/reading-toolbar-selection.spec.tsx @@ -1,4 +1,10 @@ -import { act, render, screen, waitFor } from "@testing-library/react"; +import { + act, + render, + screen, + waitFor, + within, +} from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import { beforeEach, describe, expect, it, vi } from "vitest"; @@ -151,4 +157,33 @@ describe("reading toolbar with a live selection", () => { // and 400s when they disagree. expect(body.locator).toBe(4); }); + + it("keeps secondary mobile tools behind the reading more menu", async () => { + const user = userEvent.setup(); + render( + undefined} + onToggleBookmark={() => undefined} + />, + ); + + const more = await screen.findByRole("button", { name: "More" }); + expect(more.className).toContain("md:hidden"); + expect(more).toHaveAttribute("aria-haspopup", "menu"); + expect( + screen.getByRole("button", { name: /Bookmark this page/ }), + ).toBeVisible(); + + await user.click(more); + const menu = screen.getByRole("menu", { name: "More" }); + const autoJump = within(menu).getByRole("menuitemcheckbox", { + name: /Auto-jump on/, + }); + expect(autoJump.getAttribute("aria-checked")).toBe("true"); + + await user.click(autoJump); + expect( + within(menu).getByRole("menuitemcheckbox", { name: /Auto-jump off/ }), + ).toHaveAttribute("aria-checked", "false"); + }); });