From 0265e7117cb4294938674461a534e49bd0175658 Mon Sep 17 00:00:00 2001 From: DoodleBear Date: Wed, 30 Sep 2026 18:19:10 +0900 Subject: [PATCH] fix: sliders that could not reach their own ends, and cards that ate slider clicks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two reports, two root causes, both found by writing the failing test first. **Every PercentSlider was clamped at the middle of its own track.** `value={Math.round(clamp(fraction, 0, 1) * 100)}` pinned the thumb at track 100 no matter what the track's `max` was. Speed (max 300) could reach a third of its travel, stagger and gap x and gap y (max 200) half of theirs — and the half that did nothing is exactly where the dots overlap and where a per-dot delay is wider than the cycle, which is the range the control exists for. Clamping against the track's own top fixes it. **And each call site divided by 100 a second time.** `PercentSlider` already converts the track value back to a 0…1 fraction before handing it to `onChange`; softness, grow, floor, gap x and gap y were each dividing again. So every one of those options was set to 1/100th of what the track said — softness at the far right was 0.01, grow was 0.005. This is the same raw-fraction-against-a-hundredths-track defect the repo already records for three other sliders, and it had come back wearing a different hat. Both halves of it are in one commit because either alone leaves a slider lying about its range. **Cards past the end of a scrolling row stole clicks from the sliders.** Reported as "Chasing and Morphing often will not click" — those two were fine; the cards PAST them were not. `overflow-x: auto` scrolls and clips the PAINTING, but the outgoing cards stayed hit-testable past the row's right edge, over `.playground-field`, which comes later in the DOM and therefore won the click. Breathing, Morphing and `off` rendered, looked selectable, and swallowed nothing: the slider underneath took every click. `contain: paint` stops the escape. Found by hit-testing with `document.elementFromPoint` inside the overlap, not by looking — a screenshot of that state looks like a working row. The regression test asserts the DECLARATION rather than the hit test, because jsdom loads no CSS and `getComputedStyle` returned empty for everything; reading the stylesheet is weaker than measuring, and the measurement cannot run in jsdom. What it does catch is an edit that drops `contain: paint`. Not fixed here, because it is a design question and not a defect: **`stagger` and `softness` do reach the CSS renderer** — `field.ts` sets `--botui-seed` from the spread, and the stylesheet delays each cell by it. What makes `chasing` look unsmooth is that it is a uniform highlight sweeping a ring, and a uniform sweep has nothing to interpolate. --- apps/site/src/components/Playground.tsx | 18 ++++++--- apps/site/src/styles/site.css | 17 +++++++- apps/site/test/playground.test.tsx | 52 +++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 7 deletions(-) diff --git a/apps/site/src/components/Playground.tsx b/apps/site/src/components/Playground.tsx index 0c864b0..7985a50 100644 --- a/apps/site/src/components/Playground.tsx +++ b/apps/site/src/components/Playground.tsx @@ -239,19 +239,19 @@ export function Playground({ initial }: { initial?: Partial }) label={m.ctl_softness()} fraction={options.softness ?? 0} display={`${Math.round((options.softness ?? 0) * 100)}%`} - onChange={(v) => set({ softness: v / 100 })} + onChange={(v) => set({ softness: v })} /> set({ grow: v / 100 })} + onChange={(v) => set({ grow: v })} /> set({ floor: v / 100 })} + onChange={(v) => set({ floor: v })} /> @@ -310,7 +310,7 @@ export function Playground({ initial }: { initial?: Partial }) step={5} max={200} display={percent(options.gapX ?? 0)} - onChange={(v) => set({ gapX: v / 100 })} + onChange={(v) => set({ gapX: v })} /> }) step={5} max={200} display={percent(options.gapY ?? 0)} - onChange={(v) => set({ gapY: v / 100 })} + onChange={(v) => set({ gapY: v })} /> @@ -434,7 +434,13 @@ function PercentSlider({ return ( .card { diff --git a/apps/site/test/playground.test.tsx b/apps/site/test/playground.test.tsx index 545622f..c27f3ff 100644 --- a/apps/site/test/playground.test.tsx +++ b/apps/site/test/playground.test.tsx @@ -11,10 +11,15 @@ import { act } from "react"; import { createRoot, type Root } from "react-dom/client"; import { Playground } from "../src/components/Playground.js"; import { DEFAULTS, cellsFor } from "@botharness/botui-core"; +import { readFileSync } from "node:fs"; +import { dirname, join } from "node:path"; +import { fileURLToPath } from "node:url"; // React 19's act() refuses to run unless the environment opts in. Without this every // render is a no-op with a warning, and the assertions fail for a reason that has // nothing to do with the component. +const src = join(dirname(fileURLToPath(import.meta.url)), "../src"); + beforeAll(() => { (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true; }); @@ -152,6 +157,29 @@ describe("the playground controls", () => { expect(field().length).toBeGreaterThan(10); }); + it("every slider can actually reach its own declared maximum", () => { + // `PercentSlider` clamped its value to `fraction * 100` with fraction pinned inside + // [0, 1] — so a slider declaring `max={200}` could never pass 100. Gap X, Gap Y and + // stagger all declare 200, which is the range where dots overlap and where a + // per-dot delay is wider than the whole cycle. Those three were pinned at 100: the + // thumb sat at the middle of its own track and the top half of the travel did + // nothing. A slider whose declared max it cannot reach is a control lying about its + // own range, which is the defect the repo already records for these three. + const sliders = [...container.querySelectorAll(".playground-field input[type=range]")]; + expect(sliders.length).toBeGreaterThan(5); + for (const input of sliders) { + const min = Number(input.min); + const max = Number(input.max); + const label = input.closest(".playground-field")?.querySelector("span")?.textContent ?? ""; + // drive it to the top of its own track + drag(input, max); + const at = Number(input.value); + expect(at, `${label.trim()} declares max=${max} but stops at ${at}`).toBe(max); + drag(input, min); + expect(Number(input.value), `${label.trim()} does not reach its min`).toBe(min); + } + }); + it("opens on the CSS renderer, because it is the one worth demonstrating", () => { // CSS costs zero JS per frame and SVG is the escape hatch for the motions CSS // cannot express, so the cheaper one is the default and the other has to be asked @@ -242,6 +270,30 @@ describe("the playground controls", () => { expect(labels[2]).toMatch(/floor|底噪/i); }); + it("the scrolling rows clip their overflow, so a card cannot sit on top of a slider", () => { + // Reported as "Chasing and Morphing often will not click". Those two were clickable; + // the cards PAST them were not. `overflow-x: auto` scrolls and clips the PAINTING, + // but the outgoing cards stayed hit-testable past the row's right edge — over + // `.playground-field`, which comes later in the DOM and therefore won the click. So + // Breathing, Morphing and `off` rendered, looked selectable, and swallowed nothing: + // the slider underneath them took every click. `contain: paint` is what stops it. + // + // Asserted against the STYLESHEET, not getComputedStyle: jsdom does not load the + // page's CSS at all, so every computed value here came back empty. Reading the source + // is weaker than measuring, and the measurement that found this — `elementFromPoint` + // inside the overlap, in a real browser — cannot run here. What can be asserted is + // that the declarations are present, so a future edit that drops `contain: paint` + // fails here instead of shipping again. + const css = readFileSync(join(src, "styles/site.css"), "utf8"); + const row = css.match(/\.card-grid \{([^}]*)\}/)?.[1] ?? ""; + expect(row, ".card-grid must exist in the stylesheet").not.toBe(""); + expect(row, "the row scrolls sideways").toMatch(/overflow-x:\s*auto/); + // Without this the overflow is clipped visually and still clickable. + expect(row, "the row must clip paint, or outgoing cards steal slider clicks").toMatch( + /contain:\s*paint/, + ); + }); + it("a card group is one tab stop with one selection, not a grid of buttons", () => { // A grid of