Resizable panel
A resize handle’s limits should explain themselves: past the edge it gives a little, then previews what letting go will do.
The problem
A resize handle with hard limits feels broken at the edges. You keep dragging and nothing happens, with no hint whether you hit a wall or the app stopped listening.
The other common mistake is rendering on every pointer move. Each frame goes through state, the panel and everything inside it re-render, and the drag stutters.
What I concluded
Past the max, the panel stretches at a fraction of the pointer’s speed and then arms “expand”. Past the min, it tucks and arms “dismiss”. Let go while armed and that’s what happens. Let go anywhere else and it’s an ordinary resize.
The drag itself never renders. Each animation frame writes custom properties on the panel, and the width goes into state once, on release.
const raw = d.startWidth + (d.startX - d.x);
const clamped = Math.min(Math.max(raw, MIN), MAX);
const over = raw - clamped;
if (over >= ARM_EXPAND) d.armed = "expand";
else if (-over >= ARM_DISMISS) d.armed = "dismiss";
else if (d.armed === "expand" && over < ARM_EXPAND - BACK)
d.armed = "";
else if (d.armed === "dismiss" && -over < ARM_DISMISS - BACK)
d.armed = "";
const give = Math.max(0, over) * STRETCH;
node.style.setProperty("--rh-width", `${clamped + give}px`);
node.dataset.armed = d.armed;
Rules
- Dismiss arms further out than expand. Resizing down to the minimum should never close the panel by accident.
- Disarming needs a step back. An armed gesture has to come back a bit before it lets go, so it doesn’t flicker right on the line.
- Frames write styles, release writes state. At most one paint per frame, and one commit per drag.
- The keyboard gets the resize, not the gesture. The handle is a focusable
role="separator"with its current, min and max values. Arrows step, Shift steps further, Home and End jump to the bounds. A key press has nothing to overshoot, so arming is pointer only.
What you get
The edges stop feeling like walls and start offering choices, and the person sees which one before committing. The drag stays smooth because nothing re-renders until it’s over.
The demo has a toggle for the step-back rule: turn it off and hover on the arming line to see the flicker it prevents. Related: Layout geometry, Assistant panel.