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
18 changes: 12 additions & 6 deletions apps/site/src/components/Playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,19 +239,19 @@ export function Playground({ initial }: { initial?: Partial<DotMatrixOptions> })
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 })}
/>
<PercentSlider
label={m.ctl_grow()}
fraction={options.grow ?? 0.5}
display={percent(options.grow ?? 0.5)}
onChange={(v) => set({ grow: v / 100 })}
onChange={(v) => set({ grow: v })}
/>
<PercentSlider
label={m.ctl_floor()}
fraction={options.floor ?? 0.16}
display={percent(options.floor ?? 0.16)}
onChange={(v) => set({ floor: v / 100 })}
onChange={(v) => set({ floor: v })}
/>
</Group>

Expand Down Expand Up @@ -310,15 +310,15 @@ export function Playground({ initial }: { initial?: Partial<DotMatrixOptions> })
step={5}
max={200}
display={percent(options.gapX ?? 0)}
onChange={(v) => set({ gapX: v / 100 })}
onChange={(v) => set({ gapX: v })}
/>
<PercentSlider
label={m.ctl_gap_y()}
fraction={options.gapY ?? 0}
step={5}
max={200}
display={percent(options.gapY ?? 0)}
onChange={(v) => set({ gapY: v / 100 })}
onChange={(v) => set({ gapY: v })}
/>
</Group>

Expand Down Expand Up @@ -434,7 +434,13 @@ function PercentSlider({
return (
<Slider
label={label}
value={Math.round(Math.min(Math.max(fraction, 0), 1) * 100)}
// The track is in HUNDREDTHS of the option, always: `onChange` divides by 100, so
// track 100 is fraction 1 and track `max` is fraction `max / 100`. The clamp was
// `Math.min(fraction, 1) * 100`, which pinned every slider at track 100 — so speed
// (max 300), stagger, gap x and gap y each had a top half of their travel that did
// nothing, and the thumb sat in the middle of a track it could never reach the end
// of. Clamp against the track's own top instead.
value={Math.round(Math.min(Math.max(fraction * 100, min), max))}
min={min}
max={max}
step={step}
Expand Down
17 changes: 16 additions & 1 deletion apps/site/src/styles/site.css
Original file line number Diff line number Diff line change
Expand Up @@ -760,11 +760,26 @@ footer {
.card-grid {
display: flex;
gap: 4px;
/* auto on BOTH axes, and the cross-axis one is load-bearing. `overflow-x: auto` alone
lets the overflowing cards paint and hit-test OUTSIDE the row: Breathing, Morphing
and `off` sat past the row's right edge, over the slider column, and because the
sliders come later in the DOM they won the click — the cards looked present and were
unclickable. Clipping on y as well stops the escape in the first place. */
overflow-x: auto;
overflow-y: hidden;
scroll-snap-type: x proximity;
/* the scrollbar is the affordance; a fading edge says "there is more" without one */
padding-bottom: 2px;
scrollbar-width: thin;
/* the row is a flex child of a flex column; without this it sizes to its content and
the "overflow" is never inside a scrollport at all */
min-width: 0;
max-width: 100%;
/* `contain: paint` is what actually stops the outgoing cards stealing clicks from the
slider column. `overflow-x: auto` scrolls and clips the PAINTING, but the cards were
still hit-testable past the row's right edge — Breathing, Morphing and `off` sat on
top of `.playground-field`, which comes later in the DOM and therefore won the click.
That is why those cards looked selectable and were not. */
contain: paint;
}

.card-grid > .card {
Expand Down
52 changes: 52 additions & 0 deletions apps/site/test/playground.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 <button>s would make every card a tab stop and would leave the group
// with no announced position ("3 of 14"), and arrow keys would do nothing. Radios
Expand Down
Loading