Repository navigation
fix(Slider): a drag belongs to the pointer that started it - #8152
Conversation
A second finger that lands on the slider, moves or lifts during a drag no longer moves the value, takes over the drag or ends it (a control tracks one touch, as UIKit's isMultipleTouchEnabled = false). A drag whose pointer capture is lost without an up also ends, so the slider never stays held by a pointer that is gone.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
There was a problem hiding this comment.
One change is needed before approval: the lostpointercapture listener is bound once to the control node (Slider.tsx:837-846), so when that node is replaced, as a FormLayout direction change does, a drag in progress never ends and the slider then refuses every later pointer press, where main recovers on the next tap. Listening on the control's owner document (track.ownerDocument) instead fixes both the before-drag and mid-drag cases with the existing tests still passing, and a regression case for the replaced node would keep it fixed. Otherwise the fix does what it says: tying a drag to the pointer that started it restores onChangeEnd to the drag's own release, and it holds up with two fingers, mouse plus finger, and plain mouse, pen and touch drags.
[Automated review]
| } | ||
| const onLostCapture = (event: globalThis.PointerEvent) => | ||
| endDrag(event.pointerId); | ||
| track.addEventListener('lostpointercapture', onLostCapture); |
There was a problem hiding this comment.
This listener lives on the node trackRef holds when the Effect runs, and the Effect only re-runs when endDrag changes. A FormLayout direction change re-parents Field's children and replaces that node while the Slider stays mounted. In Chromium, switching it mid-drag fires lostpointercapture at the document, and a finger lifted away from the slider sends pointerup to html, so the drag stays open and handlePointerDown (L752-754) refuses every later pointer press; main recovers on the next tap. Listening on the owner document fixes it (the Slider suite still passes, and both the before-drag and mid-drag replacement cases recover):
const doc = track.ownerDocument;
doc.addEventListener('lostpointercapture', onLostCapture);
return () => doc.removeEventListener('lostpointercapture', onLostCapture);
PR Analysis Report📚 Storybook Preview🧪 Sandbox PreviewModified ComponentsSlider (@astryxdesign/core) · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Visual Regression46 of 496 shot(s) changed. A change here is a question, not a failure: check whether the after is the
and 26 more. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
There was a problem hiding this comment.
Recommended for approval: a drag now belongs to the pointer that started it, and moving the lost-capture listener to the owner document fixes the earlier case where a mid-drag FormLayout change left the slider refusing presses; both hold with real mouse, touch and pen input in Chromium. One optional follow-up: the replaced-node test switches FormLayout to horizontal, which keeps the control node, so horizontal-labels would make it exercise the replacement its name describes. The failing pr-a11y job runs a test file added to main after this branch was cut, so a rebase should clear it.
[Automated review]
| const before = trackOf(screen.getByRole('slider')); | ||
| fireEvent.pointerDown(before, {clientX: 136, clientY: 10, pointerId: 1}); | ||
|
|
||
| rerender(<InLayout direction="horizontal" />); |
There was a problem hiding this comment.
This switch keeps the control node: Field re-parents its children only for horizontal-labels (Field.tsx:240-241), and vertical and horizontal share one branch, so the old node is still connected when lostpointercapture reaches the document. The case proves a document-level end, not the replacement its name describes. With horizontal-labels the node is replaced and the case still passes on this head:
function InLayout({direction}: {direction: 'vertical' | 'horizontal-labels'}) {
// …
}
// …
rerender(<InLayout direction="horizontal-labels" />);…ag (#8284) Follow-up to #8152. ## User impact Every Slider on a page, desktop included, kept a document-level `lostpointercapture` listener for as long as it was mounted, although the listener only matters while a drag is in progress. A page with many sliders paid for that many always-on document listeners, and each one ran on every capture loss anywhere on the page. After this change the listener exists only for the duration of a drag. Dragging behaves exactly as before, including the case #8152 fixed: when the control node is replaced mid-drag (a FormLayout direction change), losing the capture still ends the drag, and the slider answers the next press. ## Problem and solution fit - Why does it happen? #8152 moved the lost-capture listener from the control node to the owner document so a replaced node stays covered, and attached it in an Effect for the component's lifetime. - Why does it hurt? `architecture:react-component-runtime` INV5/INV7 keep document-level subscriptions scoped to the interaction that needs them. - Fix: attach the document listener in the pointer-down handler that starts the drag and remove it when the drag ends (pointer up, cancel, or lost capture). An unmount mid-drag also removes it. ## Expected behavior and authority - `architecture:react-component-runtime` INV5/INV7 (current): document-level listeners are scoped to the interaction that needs them. - `component:Slider` FR5 (current): an interaction ends when its drag is released; unchanged. ## Smallest restoration - `Slider.tsx`: the listener is added in `handlePointerDown` and removed in `endDrag` (and on unmount); the lifetime Effect is gone. No API, prop, default, DOM or visual change. ## Evidence - New test "holds a document listener only while a drag is in progress": no listener while idle, one added on pointer down and the same one removed on pointer up, and a second drag's listener removed on unmount. It fails on `main`. - The replaced-node test now switches FormLayout to `horizontal-labels`, which replaces the control node (the previous `horizontal` kept it), and still passes: the drag ends and the next press works. - All Slider tests pass (100). ## Scope - [x] One defect is restored. - [x] Separable contradictory or unsettled tagalongs were removed or split. - [x] No new public API, visual representation, default, or interaction model is hidden under the bug-fix label. - [x] Public text and artifacts contain no internal Meta context. ## Testing - `pnpm vitest run packages/core/src/Slider`: 100 passed. - `tsc --noEmit` for core; strict eslint; prettier.
Siblings on the same pointer handlers: #8151 (coincident range thumbs) and #7516 (pointer selection of an off-grid max). Whichever lands later is rebased.
User impact
On a touch screen, a second finger that touches a Slider during a drag (a palm, a resting thumb) takes the drag over. The value jumps to that finger. When it lifts,
onChangeEndcommits a value the user never chose, and the first finger stops moving the slider. Now the drag belongs to the finger that started it, and two fingers can still drag two sliders.Problem and solution fit
pointerId: anypointerdownstarts a drag, anypointermovedrives it, and anypointerupends it.onChangeEnd, so a stray touch commits a wrong value.The slider ignores every other pointer until the drag's own pointer lifts or is cancelled. A capture lost without an up also ends the drag. Otherwise a drag left open would block every later press.
Expected behavior and authority
component:SliderFR5:onChangeEndfires once, when the drag is released or cancelled.UIView.isMultipleTouchEnableddefaults tofalse(Apple).Smallest restoration
The change is in
Slider.tsxonly. A ref holds the drag'spointerId, and alostpointercapturelistener ends the drag. There is no new prop.Evidence
Real touch in Chromium (phone emulation, two touch points). Finger A grabs the thumb at 50, and finger B lands on the track at 10 %:
mainonChangeEnd(9)onChangeEnd(71)Slider.test.tsx. Its second-finger and lost-capture cases fail onmain.Scope
Testing
pnpm exec vitest run --project ui packages/core/src/Slider: 3 files, 98 tests pass. Withmain'sSlider.tsx, 2 of the 3 new cases fail.pnpm -F @astryxdesign/core typecheck, eslint and prettier on the touched files, and the pre-commit checks: pass.