An open source design system that's fully customizable and agent ready
TypeScript
fix(Slider): a press on the mark label of coincident thumbs goes to the upper thumb, as a press on the thumbs does (#9184)
Christopher Chedeaudce0ccfd63d5
diff --git a/.changeset/slider-coincident-press-focus.md b/.changeset/slider-coincident-press-focus.mdnew file mode 100644index 0000000000..577af5eed0--- /dev/null+++ b/.changeset/slider-coincident-press-focus.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] Slider: a press on the mark label of two coincident thumbs' shared value now goes to the upper thumb, as a press on the thumbs does, so a press that never moves leaves focus on the same thumb wherever it lands. Before, a press on that label went to the lower thumb, which the upper one covers.++@vjeuxdiff --git a/packages/core/src/Slider/Slider.spec.md b/packages/core/src/Slider/Slider.spec.mdindex 1011212372..f23b712d76 100644--- a/packages/core/src/Slider/Slider.spec.md+++ b/packages/core/src/Slider/Slider.spec.md@@ -78,14 +78,14 @@ modes, states, and usage remain documented in `Slider.doc.mjs`.## Behavioral and layout contract-| ID | Candidate invariant | Basis | Review state |-| --- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------- | -------------------------------------------------- |-| FR1 | The current render places a filled range, one or two thumbs, and optional tick marks over the background track. | Current source, docs, and focused tests | Verified current behavior; no new behavior decided |-| FR2 | `Slider`, `Interactive control`, `Track`, and `Thumb` carry the `slider`, `slider-control`, `slider-track`, and `slider-thumb` targets respectively. | Current source, public docs, and DEC-1 | Approved additive target contract |-| FR3 | Filled range, tick marks, mark labels, and adjacent text value display are stable rendered parts without their own current Slider target. | Current source and public docs | Verified current asymmetry; not ratified as policy |-| FR4 | Label and status presentation continue to use Field and FieldStatus; value tooltips continue to use Tooltip. | Current source and focused tests | Verified composition boundary |-| FR5 | `onChangeEnd` fires once when an interaction ends — a pointer drag or track press is released or cancelled, or a keyboard step (arrow, Page, Home, End) completes — and carries the value the owner renders after its synchronous response to that interaction's `onChange` calls, including any clamp, snap, or rejection; it never carries a value Slider emitted that the owner did not render. A range reports both values the same way. | Maintainer decision (DEC-3) | Approved |-| FR6 | When both thumbs of a range share a value, a pointer press takes the thumb that can travel toward the pointer: a press on the track beside them takes the thumb on its side, and a press on the thumbs moves neither until the pointer moves, when the direction of that first movement picks the thumb, which takes the drag's focus, pressed state and value tooltip. A drag that began on the shared thumbs and comes back past their value moves the other thumb: the dragged thumb stops against it and the other follows the pointer, so with both at 80 a drag to 95 and back to 50 ends at [50, 80]. | Current source and focused tests | Accepted contract |+| ID | Candidate invariant | Basis | Review state |+| --- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------- | -------------------------------------------------- |+| FR1 | The current render places a filled range, one or two thumbs, and optional tick marks over the background track. | Current source, docs, and focused tests | Verified current behavior; no new behavior decided |+| FR2 | `Slider`, `Interactive control`, `Track`, and `Thumb` carry the `slider`, `slider-control`, `slider-track`, and `slider-thumb` targets respectively. | Current source, public docs, and DEC-1 | Approved additive target contract |+| FR3 | Filled range, tick marks, mark labels, and adjacent text value display are stable rendered parts without their own current Slider target. | Current source and public docs | Verified current asymmetry; not ratified as policy |+| FR4 | Label and status presentation continue to use Field and FieldStatus; value tooltips continue to use Tooltip. | Current source and focused tests | Verified composition boundary |+| FR5 | `onChangeEnd` fires once when an interaction ends — a pointer drag or track press is released or cancelled, or a keyboard step (arrow, Page, Home, End) completes — and carries the value the owner renders after its synchronous response to that interaction's `onChange` calls, including any clamp, snap, or rejection; it never carries a value Slider emitted that the owner did not render. A range reports both values the same way. | Maintainer decision (DEC-3) | Approved |+| FR6 | When both thumbs of a range share a value, a pointer press takes the thumb that can travel toward the pointer: a press on the track beside them takes the thumb on its side, and a press on the thumbs or on their shared value, such as its mark label, moves neither until the pointer moves, when the direction of that first movement picks the thumb, which takes the drag's focus, pressed state and value tooltip. Until then the upper thumb, drawn over the lower one, holds the press, its focus and its pressed state, so a press that never moves changes no value and leaves focus on the upper thumb. A drag that began on the shared thumbs and comes back past their value moves the other thumb: the dragged thumb stops against it and the other follows the pointer, so with both at 80 a drag to 95 and back to 50 ends at [50, 80]. | Current source and focused tests | Accepted contract |### Observed current target asymmetry@@ -226,16 +226,16 @@ separately listed value tooltip retains Tooltip's target.## Verification map-| Contract | Verification | Representative states | Mutation or failure expectation | Audit section |-| ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------- |-| FR1 | `Slider.test.tsx` structure, range, and marks suites | Single, range, horizontal, vertical, marks | Removing or misaligning stable parts breaks existing role, position, or mark assertions. | `audit:Slider/anatomy` |-| AR1 | Slider accessibility contract (`internal/a11y-spec`, pending) bound to Slider; disabled-thumb Tab stop pending conformance; in jsdom and Chromium; `Slider.test.tsx` keyboard suites, including "follows the mirrored track under RTL: ArrowLeft increases, ArrowRight decreases, Up/Down unchanged" and "keeps ArrowLeft decreasing on a vertical track under RTL"; the Page, Home/End and Up/Down cases under the contract | Single and range; horizontal LTR and RTL; vertical; disabled; formatted value | A thumb loses its role, name or value properties; an arrow, Page, Home or End key stops stepping or steps against the mirrored track; a range thumb crosses the other | `audit:Slider/accessibility` |-| FR2 | `Slider.test.tsx`, `themingTargets.test.ts`, generated probe theme, and Chromium | Root, horizontal/vertical control, disabled control, track, and thumb | A target class/state is missing, undocumented, or placed outside its owning anatomy. | `audit:Slider/theming` |-| FR3 | Source and consumer-doc review | Filled range, marks, labels, adjacent text value | A missing target is inaccurately documented as present or intentionally permanent. | `audit:Slider/theming` |-| FR4 | Source inspection; focused tests cover label, status, and disabled-reason Tooltip only | Label, status, value tooltip, disabled reason | Shared composition or its accessible association disappears; value-tooltip composition still lacks focused coverage. | `audit:Slider/anatomy` |-| FR5 | Pending: `Slider.test.tsx` change-end cases driven by an owner that renders, clamps, or rejects the emitted value (not yet in the suite) | Single and range; pointer release before and after the owner re-renders; each keyboard step | `onChangeEnd` reports a value the owner did not render, fires more than once per interaction, or skips a completed keyboard step | `audit:Slider/accessibility` |-| FR6 | `Slider.test.tsx` coincident range thumbs cases | Both thumbs at the minimum, the maximum and mid-range; a track press on each side; a press on the thumbs moved either way; a drag that passes back over the shared value; right to left | A press or drag on coincident thumbs moves neither thumb, moves the thumb that cannot travel toward the pointer, or keeps its focus, pressed state or tooltip on a thumb the drag has left | `audit:Slider/anatomy` |-| Theming anatomy map | `scripts/check-knowledge.mjs` | Canonical anatomy and four current local targets | Missing, extra, prefixed, stale, or unclaimed mappings fail repository validation. | `audit:Slider/theming` |+| Contract | Verification | Representative states | Mutation or failure expectation | Audit section |+| ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------- |+| FR1 | `Slider.test.tsx` structure, range, and marks suites | Single, range, horizontal, vertical, marks | Removing or misaligning stable parts breaks existing role, position, or mark assertions. | `audit:Slider/anatomy` |+| AR1 | Slider accessibility contract (`internal/a11y-spec`, pending) bound to Slider; disabled-thumb Tab stop pending conformance; in jsdom and Chromium; `Slider.test.tsx` keyboard suites, including "follows the mirrored track under RTL: ArrowLeft increases, ArrowRight decreases, Up/Down unchanged" and "keeps ArrowLeft decreasing on a vertical track under RTL"; the Page, Home/End and Up/Down cases under the contract | Single and range; horizontal LTR and RTL; vertical; disabled; formatted value | A thumb loses its role, name or value properties; an arrow, Page, Home or End key stops stepping or steps against the mirrored track; a range thumb crosses the other | `audit:Slider/accessibility` |+| FR2 | `Slider.test.tsx`, `themingTargets.test.ts`, generated probe theme, and Chromium | Root, horizontal/vertical control, disabled control, track, and thumb | A target class/state is missing, undocumented, or placed outside its owning anatomy. | `audit:Slider/theming` |+| FR3 | Source and consumer-doc review | Filled range, marks, labels, adjacent text value | A missing target is inaccurately documented as present or intentionally permanent. | `audit:Slider/theming` |+| FR4 | Source inspection; focused tests cover label, status, and disabled-reason Tooltip only | Label, status, value tooltip, disabled reason | Shared composition or its accessible association disappears; value-tooltip composition still lacks focused coverage. | `audit:Slider/anatomy` |+| FR5 | Pending: `Slider.test.tsx` change-end cases driven by an owner that renders, clamps, or rejects the emitted value (not yet in the suite) | Single and range; pointer release before and after the owner re-renders; each keyboard step | `onChangeEnd` reports a value the owner did not render, fires more than once per interaction, or skips a completed keyboard step | `audit:Slider/accessibility` |+| FR6 | `Slider.test.tsx` coincident range thumbs cases | Both thumbs at the minimum, the maximum and mid-range; a track press on each side; a press on the thumbs moved either way; a press that never moves, on the thumbs and on the mark label of their value; a drag that passes back over the shared value; right to left | A press or drag on coincident thumbs moves neither thumb, moves the thumb that cannot travel toward the pointer, keeps its focus, pressed state or tooltip on a thumb the drag has left, or leaves a press that never moves on the lower thumb | `audit:Slider/anatomy` |+| Theming anatomy map | `scripts/check-knowledge.mjs` | Canonical anatomy and four current local targets | Missing, extra, prefixed, stale, or unclaimed mappings fail repository validation. | `audit:Slider/theming` |The focused Slider suite asserts the `slider-control` target's orientation anddisabled state. Source/metadata guards cover all four target declarations. Thediff --git a/packages/core/src/Slider/Slider.test.tsx b/packages/core/src/Slider/Slider.test.tsxindex 1bd65bcac6..7f46053fb4 100644--- a/packages/core/src/Slider/Slider.test.tsx+++ b/packages/core/src/Slider/Slider.test.tsx@@ -1714,6 +1714,58 @@ describe('coincident range thumbs', () => {expect(end).toHaveAttribute('aria-valuenow', '100');});+ it('leaves the press and focus on the upper thumb, drawn on top, when a press on the shared thumbs never moves', () => {+ const onChange = vi.fn();+ render(<ControlledRange initial={[50, 50]} onChange={onChange} />);+ mockGroupRect();+ const [start, end] = screen.getAllByRole('slider');+ // Both thumbs share a stacking level, so the later one in the document,+ // the upper thumb, is drawn over the lower one and takes the press.+ expect(+ start.compareDocumentPosition(end) & Node.DOCUMENT_POSITION_FOLLOWING,+ ).toBeTruthy();+ fireEvent.pointerDown(end, {clientX: 100, clientY: 10, pointerId: 1});+ expect(declaresPressedOverlay(end)).toBe(true);+ expect(declaresPressedOverlay(start)).toBe(false);+ fireEvent.pointerUp(end, {clientX: 100, clientY: 10, pointerId: 1});+ expect(start).toHaveAttribute('aria-valuenow', '50');+ expect(end).toHaveAttribute('aria-valuenow', '50');+ expect(document.activeElement).toBe(end);+ });++ it('holds a press on the mark label of the shared value on the upper thumb, as a press on the thumbs does', () => {+ function MarkedRange() {+ const [value, setValue] = useState<[number, number]>([50, 50]);+ return (+ <Slider+ label="Price"+ value={value}+ min={0}+ max={100}+ marks={[{value: 50, label: '50%'}]}+ onChange={setValue}+ />+ );+ }+ render(<MarkedRange />);+ mockGroupRect();+ const [start, end] = screen.getAllByRole('slider');+ const label = screen+ .getByText('50%')+ .closest<HTMLElement>('[data-mark-value]')!;+ // The label sits at the shared value, so nothing says which way the+ // drag goes yet: the upper thumb, drawn over the lower one, holds the+ // press, as it does for a press on the thumbs.+ fireEvent.pointerDown(label, {clientX: 100, clientY: 10, pointerId: 1});+ expect(declaresPressedOverlay(end)).toBe(true);+ expect(declaresPressedOverlay(start)).toBe(false);+ expect(document.activeElement).toBe(end);+ fireEvent.pointerUp(label, {clientX: 100, clientY: 10, pointerId: 1});+ expect(start).toHaveAttribute('aria-valuenow', '50');+ expect(end).toHaveAttribute('aria-valuenow', '50');+ expect(document.activeElement).toBe(end);+ });+it('hands the drag, its focus and its pressed paint to the thumb the first movement picks', () => {const onChange = vi.fn();render(<ControlledRange initial={[50, 50]} onChange={onChange} />);diff --git a/packages/core/src/Slider/Slider.tsx b/packages/core/src/Slider/Slider.tsxindex cc87803e62..d4e19910e6 100644--- a/packages/core/src/Slider/Slider.tsx+++ b/packages/core/src/Slider/Slider.tsx@@ -834,6 +834,14 @@ export function Slider({ref, ...props}: SliderProps) {pressedThumbIndex >= 0 ? pressedThumbIndex : getClosestThumb(newVal);const parks =isCoincident && (pressedThumbIndex >= 0 || newVal === values[0]);+ // Until the first movement, a parked press is held by the upper thumb,+ // the one drawn over the lower one, wherever it landed: on the thumbs+ // (which the upper thumb covers) or on their shared value elsewhere,+ // such as its mark label. So its pressed paint shows, and a press that+ // never moves leaves focus on the same thumb.+ if (parks && pressedThumbIndex < 0) {+ thumbIndex = 1;+ }// The first movement is measured from the pointer itself, not from a// mark it pressed (a wide label sits away from its mark's value).coincidentDragRef.current = parks