Skip to content

Commit 58a7ead

Browse files
committed
feat(Slider): one touch model on every touch device
The maintainers ruled one touch model on every touch device, iOS and Android alike, with no platform idiom (the touch resolver in meta#8062, now in meta#8076; AST-094 in meta#8316): touch behaviors key on a coarse primary pointer, and the resolver no longer reports an idiom. The slider's touch presentation (the thumbs' touch targets, UISlider's tracking and coast, the track's tap, the lift) now applies under any finger; a mouse or a trackpad keeps the pointer handlers. The docs, story and changeset say "under a finger" instead of "on iOS". Tests: the Android cases that kept today's slider are flipped. The unit case gives a coarse pointer with no iOS engine (no -webkit-touch-callout) the touch targets and leaves a finger on the track to the touch presentation; it fails on the previous head. The interaction cases run with no iOS-engine emulation, and the Android case now checks the same model there: the lift, the travel past the threshold and a track tap that sets the value on its lift (the Android Reduce Motion case was the iOS one's duplicate and goes). The fine-pointer cases stay as they were: no touch targets, and the desktop geometry case's pointer styles.
1 parent b459a62 commit 58a7ead

8 files changed

Lines changed: 89 additions & 174 deletions

File tree

‎.changeset/slider-touch-tracking.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
'@astryxdesign/core': patch
33
---
44

5-
[feat] Slider: on iOS the slider tracks a finger as UISlider does. Only the thumb takes a drag, through a 48 px target, so a swipe from the track scrolls the page; a tap on the track or a mark sets the value when the finger lifts, the thumb springing there (UISlider ignores track taps; a drag is not the only pointer way to set the value, WCAG 2.5.7). The value follows the finger’s travel past a 10 px threshold over the track’s length, so the thumb never jumps to the finger. A release coasts on UIKit’s spring before `onChangeEnd` reports. The coast runs on the compositor and keeps moving while the main thread is busy. A mouse, and every other touch screen (Android’s included), keeps the current behavior.
5+
[feat] Slider: under a finger, on any touch device, the slider tracks as UISlider does. Only the thumb takes a drag, through a 48 px target, so a swipe from the track scrolls the page; a tap on the track or a mark sets the value when the finger lifts, the thumb springing there (UISlider ignores track taps; a drag is not the only pointer way to set the value, WCAG 2.5.7). The value follows the finger’s travel past a 10 px threshold over the track’s length, so the thumb never jumps to the finger. A release coasts on UIKit’s spring before `onChangeEnd` reports. The coast runs on the compositor and keeps moving while the main thread is busy. A mouse or a trackpad keeps the current behavior.
66
@vjeux

‎apps/storybook/stories/Slider.stories.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ export const TouchTracking: Story = {
313313
docs: {
314314
description: {
315315
story:
316-
'On iOS only the thumb takes a drag, through a touch target larger than it; a swipe from the track scrolls the page, and a tap on the track sets the value when the finger lifts. The value follows the finger’s travel past a 10 px start threshold, so the thumb never jumps to the finger, and a release coasts on before `onChangeEnd` reports the value.',
316+
'Under a finger only the thumb takes a drag, through a touch target larger than it; a swipe from the track scrolls the page, and a tap on the track sets the value when the finger lifts. The value follows the finger’s travel past a 10 px start threshold, so the thumb never jumps to the finger, and a release coasts on before `onChangeEnd` reports the value.',
317317
},
318318
},
319319
},

‎packages/core/src/Slider/Slider.doc.mjs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ export const docs = {
297297
],
298298
anatomy,
299299
description:
300-
'A draggable control for selecting a numeric value or range within defined bounds. Supports single value and range selection, tick marks, custom value formatting, and vertical orientation. Use it when users need to explore a continuous range, such as volume, price, or percentage. On iOS it tracks a finger as UISlider does: only the thumb takes the finger, through a target larger than it, the value follows the finger’s travel rather than jumping to it, a release coasts on before `onChangeEnd`, a swipe from the track scrolls the page, and a tap on the track or a mark sets the value when the finger lifts (the thumb springs there). Other touch screens, Android’s included, keep the pointer behavior: a tap on the track moves the thumb there.',
300+
'A draggable control for selecting a numeric value or range within defined bounds. Supports single value and range selection, tick marks, custom value formatting, and vertical orientation. Use it when users need to explore a continuous range, such as volume, price, or percentage. Under a finger, on any touch device, it tracks as UISlider does: only the thumb takes a drag, through a target larger than it, the value follows the finger’s travel rather than jumping to it, a release coasts on before `onChangeEnd`, a swipe from the track scrolls the page, and a tap on the track or a mark sets the value when the finger lifts (the thumb springs there). A mouse or a trackpad keeps the pointer behavior: a press on the track moves the thumb there.',
301301
bestPractices: [
302302
{
303303
guidance: true,
@@ -510,7 +510,7 @@ export const docsZh = {
510510
usage: {
511511
anatomy,
512512
description:
513-
'A draggable control for selecting a numeric value or range within defined bounds. Supports single value and range selection, tick marks, custom value formatting, and vertical orientation. Use it when users need to explore a continuous range, such as volume, price, or percentage. On iOS it tracks a finger as UISlider does: only the thumb takes the finger, through a target larger than it, the value follows the finger’s travel rather than jumping to it, a release coasts on before `onChangeEnd`, a swipe from the track scrolls the page, and a tap on the track or a mark sets the value when the finger lifts (the thumb springs there). Other touch screens, Android’s included, keep the pointer behavior: a tap on the track moves the thumb there.',
513+
'A draggable control for selecting a numeric value or range within defined bounds. Supports single value and range selection, tick marks, custom value formatting, and vertical orientation. Use it when users need to explore a continuous range, such as volume, price, or percentage. Under a finger, on any touch device, it tracks as UISlider does: only the thumb takes a drag, through a target larger than it, the value follows the finger’s travel rather than jumping to it, a release coasts on before `onChangeEnd`, a swipe from the track scrolls the page, and a tap on the track or a mark sets the value when the finger lifts (the thumb springs there). A mouse or a trackpad keeps the pointer behavior: a press on the track moves the thumb there.',
514514
bestPractices: [
515515
{
516516
guidance: true,
@@ -546,7 +546,7 @@ export const docsDense = {
546546
usage: {
547547
anatomy,
548548
description:
549-
'A draggable control for selecting a numeric value or range within defined bounds. Supports single value and range selection, tick marks, custom value formatting, and vertical orientation. Use it when users need to explore a continuous range, such as volume, price, or percentage. On iOS it tracks a finger as UISlider does: only the thumb takes the finger, through a target larger than it, the value follows the finger’s travel rather than jumping to it, a release coasts on before `onChangeEnd`, a swipe from the track scrolls the page, and a tap on the track or a mark sets the value when the finger lifts (the thumb springs there). Other touch screens, Android’s included, keep the pointer behavior: a tap on the track moves the thumb there.',
549+
'A draggable control for selecting a numeric value or range within defined bounds. Supports single value and range selection, tick marks, custom value formatting, and vertical orientation. Use it when users need to explore a continuous range, such as volume, price, or percentage. Under a finger, on any touch device, it tracks as UISlider does: only the thumb takes a drag, through a target larger than it, the value follows the finger’s travel rather than jumping to it, a release coasts on before `onChangeEnd`, a swipe from the track scrolls the page, and a tap on the track or a mark sets the value when the finger lifts (the thumb springs there). A mouse or a trackpad keeps the pointer behavior: a press on the track moves the thumb there.',
550550
bestPractices: [
551551
{
552552
guidance: true,

‎packages/core/src/Slider/Slider.tsx‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/**
66
* @file Slider.tsx
77
* @input Uses React, useId, useRef, useCallback, useEffect, Field, useTooltip, VisuallyHidden; the touch presentation resolver and useSliderTouch (UISlider's touch tracking)
8-
* @output Exports Slider and its props; unfilled marks share the track token; modifier-only key presses do not restore the thumb focus ring; a drag belongs to the pointer that started it; the thumbs and the filled range travel by `translate` from a progress custom property in container units of a box filling the control's padding box, so moving them never lays out (a value tooltip or text display still does) and padding on the control moves no part; the value tooltip anchors to a box layout places at the value; under a finger on iOS (the touch presentation's iOS idiom) only the thumbs' touch targets take touches, tracked as UISlider does, while a mouse and every other touch screen (Android's) keep the pointer handlers
8+
* @output Exports Slider and its props; unfilled marks share the track token; modifier-only key presses do not restore the thumb focus ring; a drag belongs to the pointer that started it; the thumbs and the filled range travel by `translate` from a progress custom property in container units of a box filling the control's padding box, so moving them never lays out (a value tooltip or text display still does) and padding on the control moves no part; the value tooltip anchors to a box layout places at the value; under a finger (a coarse primary pointer, on every touch device) only the thumbs' touch targets take a drag, tracked as UISlider does, and a tap on the track sets the value on its lift, while a mouse or a trackpad keeps the pointer handlers
99
* @position Core implementation; consumed by index.ts, tested by Slider.test.tsx
1010
*
1111
* SYNC: When modified, update these files to stay in sync:
@@ -210,7 +210,7 @@ const styles = stylex.create({
210210
display: 'flex',
211211
alignItems: 'center',
212212
flexGrow: 1,
213-
// Under the touch presentation (iOS) the gesture host sets the touch
213+
// Under the touch presentation (a finger) the gesture host sets the touch
214214
// targets' and the track's touch-action as their recognizers need it
215215
// (the track's tap leaves the page its scrolling), and turns text
216216
// selection and the callout off where a finger is held.
@@ -734,14 +734,11 @@ export function Slider({ref, ...props}: SliderProps) {
734734
const draggingThumbRef = useRef<number | null>(null);
735735
const [draggingThumb, setDraggingThumb] = useState<number | null>(null);
736736

737-
// Under a finger on iOS the thumbs track touches as UISlider does
738-
// (useSliderTouch); a mouse keeps the pointer handlers below. UISlider's
739-
// tracking is the iOS idiom: Android's Material slider moves the thumb to a
740-
// tap on the track and has no momentum, so every other touch screen keeps
741-
// the pointer handlers too.
742-
const touchPresentation = useTouchPresentation();
743-
const isTouchPresentation =
744-
touchPresentation.isTouch && touchPresentation.idiom === 'ios';
737+
// Under a finger the thumbs track touches as UISlider does
738+
// (useSliderTouch): one touch model on every touch device, a coarse
739+
// primary pointer whatever the platform (spec:AST-094). A mouse or a
740+
// trackpad keeps the pointer handlers below.
741+
const isTouchPresentation = useTouchPresentation().isTouch;
745742
const hasTouchTargets = isTouchPresentation && !isDisabled;
746743
// Whether the touch presentation takes touches (useSliderTouch): the
747744
// pointer handlers then leave a finger or a pen to it.

‎packages/core/src/Slider/__tests__/SliderGeometry.a11y.chromium.spec.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ test('padding on the control keeps the thumb on the track, the fill and the mark
443443

444444
// Desktop keeps the pointer model: no touch targets, the control's own
445445
// touch-action and user-select, and none of the touch presentation's inline
446-
// styles (the gesture host sets those only on iOS, while a finger is down).
446+
// styles (the gesture host sets those only under a finger, while it is down).
447447
test('a desktop slider keeps its pointer styles: no touch targets, no inline touch styles', async ({
448448
page,
449449
}) => {

0 commit comments

Comments
 (0)