Skip to content

fix(Slider): keep max reachable when step does not divide the range - #6399

Closed
korkt-kim wants to merge 2 commits into
meta:mainfrom
korkt-kim:fix/slider-step-endpoint
Closed

korkt-kim wants to merge 2 commits into
meta:mainfrom
korkt-kim:fix/slider-step-endpoint

Conversation

@korkt-kim

@korkt-kim korkt-kim commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

User impact

With min={0}, max={100} and step={3}, Slider stops at 99 when dragged to the right endpoint or operated with End. Its accessible maximum is still 100, but neither input method can select it.

Fixes #6735

Problem and solution fit

The value is rounded to the step grid before it is clamped. At the endpoint, 100 rounds to 99; clamping leaves it there because it is already within bounds. A second edge case appears when the current value is an off-grid maximum: subtracting a step and then rounding takes 100 → 97 → 96, skipping the adjacent value 99.

The fix includes the explicit maximum in nearest-value selection and makes arrow keys choose the adjacent step in their direction. The final interval may be shorter than step: 96 → 99 → 100, and back through 99 rather than skipping it.

Expected behavior and authority

  • Slider documents max as its maximum value. The existing implementation already permits an off-grid maximum when rounding overshoots and clamping brings it back: min=0, max=100, step=6 reaches 100 today. This restores consistent endpoint reachability rather than making it depend on the remainder.
  • The APG Slider pattern assigns End to the last allowed value. This fix treats the explicit max as allowed; it does not claim that WCAG requires this particular step policy or that it matches native HTML range sanitization.

Smallest restoration

Slider.tsx: share nearest-step/endpoint selection across pointer and keyboard updates, and select the adjacent step before applying bounds on arrow-key movement. Existing decimal cleanup, range separation, and callback handling stay in place. No new props, styling, dependencies, or default values.

Three regression tests cover single-value keyboard/callback behavior, range separation and ARIA bounds, and pointer dragging to both 100 and the neighboring 99.

Evidence

Reproduce

  1. Open Custom Step with step=3.
  2. Drag to the right endpoint: the value stops at 99.
  3. Focus the thumb and press End: it still reads 99, with aria-valuemax="100".
  4. On this branch, open the same story/args locally: both actions reach 100. ArrowLeft then ArrowRight visits 99 → 100.

AS-IS / TO-BE: real Chrome 153 keyboard and mouse input, published Storybook versus this branch at b46a9c0ec8. The diagnostic panels are injected by the probe; their values are read from the live DOM after each action. They are not product UI.

AS-IS TO-BE
Published Slider: End and right-endpoint drag both stop at 99 while aria-valuemax is 100 Fixed Slider: End and drag reach 100; arrow keys visit 99 and return to 100

Before recording · After recording · Probe, raw observations, and test logs

Representative unchanged keyboard paths, checked on both builds:

Configuration End → ArrowLeft
min=0, max=100, step=10 100 → 90
min=0, max=100, step=6 100 → 96
min=1, max=100, step=3 100 → 97
min=-1, max=100, step=3 100 → 98

The published deployment is not asserted to be the exact base commit. For regression proof, the same new tests were run with a temporary Vite hook substituting only Slider's source:

Source under test Result
Base f138ed997b 3 failed, 65 passed — new tests receive 99 instead of 100
Endpoint fix, but old currentValue ± step arrow logic 2 failed, 66 passed — keyboard tests receive 96 instead of 99
This fix 68 passed

The probe configs and logs are linked above. No live source was swapped, and the tested source hashes match the committed files. These are scoped Chromium checks, not a full assistive-technology or cross-browser audit.

Scope

  • One endpoint-reachability defect and its adjacent-step consequence are addressed.
  • No unrelated API, visual, layout, or cleanup changes are included.
  • The off-grid endpoint policy is explicit above; no new public API is introduced.
  • Public text and artifacts contain no internal Meta context. Evidence lives on a separate fork branch; this PR changes only Slider, its tests, and a changeset.

Testing

  • pnpm exec vitest run packages/core/src/Slider/Slider.test.tsx — 68 passed.
  • Full test suite — pnpm test --maxWorkers=4 — 17,113 passed, 50 skipped (GNU cp on PATH; see note below).
  • pnpm -F @astryxdesign/core typecheck — passed.
  • pnpm -F @astryxdesign/core typecheck:docs — passed.
  • pnpm build — passed.
  • pnpm lint:strict — 0 errors; 84 warnings outside Slider.
  • Real-browser pointer/keyboard checks and unchanged paths above.

The first full run on macOS passed 17,105 tests but hit two unrelated setup-fixture failures because BSD cp does not support --reflink=auto. The entire suite was rerun with GNU cp 9.11 on PATH using pnpm test --maxWorkers=4; no test exclusions or repository fixes were added for that environment issue.

@vercel

vercel Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Oct 13, 2026 10:16am UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 20, 2026
@astracat-bot

astracat-bot Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
❓ Needs maintainer input (for maintainers only) Oct 20, 2026, 12:01 AM UTC

@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge labels Sep 20, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the careful endpoint fix and regression coverage. The implementation reads as matching the policy you describe — pointer and End can reach the explicit maximum, and arrow keys visit the adjacent selectable value instead of skipping it — and this review found no concrete code defect in the single or range cases.

Approval is waiting on a maintainer decision, though. Slider's current governing contract covers its anatomy and theming and does not settle whether the explicit maximum should join the selectable set when the step does not divide the range, including the shorter final interval, preferring maximum on a tie, arrow movement from off-grid values, and the range-thumb separation case. A maintainer needs to provide or identify the governing spec for that addition before it can be approved; please do not treat this as a request to rewrite the fix or to author the spec yourself.

Once that policy is settled in favour, the remaining step is normal verification on the merged result. If it is settled the other way, the endpoint behaviour would need to change accordingly.

[Automated review]

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the careful endpoint fix and regression coverage. The implementation matches the policy you describe — pointer and End can reach the explicit maximum, and arrow keys visit the adjacent selectable value instead of skipping it — and this review found no concrete code defect in the single or range cases; the focused tests and browser checks for the step=3 case pass.

Approval is waiting on a maintainer decision, though. Slider's current governing contract covers its anatomy and theming and does not settle whether the explicit maximum should join the selectable set when the step does not divide the range, including the shorter final interval, preferring maximum on a tie, arrow movement from off-grid values, and the range-thumb separation case. A maintainer needs to provide or identify the governing spec for that addition before it can be approved; please do not treat this as a request to rewrite the fix or to author the spec yourself.

Once that policy is settled in favour, the remaining step is normal verification on the merged result. If it is settled the other way, the endpoint behaviour would need to change accordingly.

[Automated review]

github-actions Bot added a commit that referenced this pull request Sep 29, 2026
@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

Current run: The current CI run concluded failure. Current analysis is unavailable.

The exact-head preview is not available yet.


Generated by PR Enrichment workflow | View current CI run

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the careful fix and tests: the implementation does what the description says and this review found no code defect, but approval is waiting on a maintainer decision rather than on changes from you. Slider's current spec does not say whether the explicit max is a selectable value when step does not divide the range, so a maintainer needs to provide or identify the governing spec for that addition, covering End and dragging reaching max, the shorter final interval with max preferred on a tie, arrow keys moving to the adjacent selectable value from any off-grid value, and the same rule for range thumbs under minStepsBetweenThumbs. For that decision, note that on main ArrowRight from 99 already reaches 100 while End and dragging stop at 99 (step={3}), so today's behaviour is not consistently grid-only either. If the policy is accepted, two small optional touch-ups would help (mention in the changeset that arrow keys now stop at the adjacent value from any off-grid value, not only next to the maximum, and keep the file header's existing note that unfilled marks share the track token), and there is no need for you to write the spec.

[Automated review]

Comment thread .changeset/slider-step-endpoints.md Outdated
'@astryxdesign/core': patch
---

[fix] Keep Slider endpoints selectable when the step does not divide the range. Pointer input and End now reach the explicit maximum, and arrow keys move between that endpoint and its nearest step without skipping a value.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: the code also changes arrow-key movement from any off-grid value, not only next to the endpoint. For example, with step={10} and value={55}, ArrowRight now goes to 60 instead of 70. If maintainers accept this policy, consider saying so here so the release note covers it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 4ba130d206. The changeset now explicitly covers arrow-key movement from any off-grid value, including the step={10}, value={55} example: ArrowRight selects 60 instead of 70.

This is a documentation-only follow-up; the endpoint/off-grid policy still awaits the maintainer decision noted in the review.

* @file Slider.tsx
* @input Uses React, useId, useRef, useCallback, Field, Tooltip, useTooltip, VisuallyHidden
* @output Exports Slider and its props; unfilled marks share the track token; modifier-only key presses do not restore the thumb focus ring
* @output Exports Slider and its props; explicit endpoints remain selectable with off-grid steps, and arrow keys visit adjacent steps

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: this drops "unfilled marks share the track token" from @output. That is still true (the mark style paints --color-track), so it could stay beside the new note.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 4ba130d206. Restored "Unfilled marks share the track token" in the file header alongside the endpoint and focus-ring notes. No runtime behavior changed.

@korkt-kim
korkt-kim marked this pull request as ready for review October 13, 2026 10:30

@astracat-bot astracat-bot Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix and the regression tests. This needs changes from you, and approval also waits on a maintainer decision. Since this branch was cut, main has shipped End reaching an off-grid max and settled the arrow and Page keys in the Slider spec (the key result snaps to the nearest step, then clamps), so please rebase onto main, keep its key handling, and drop the snap-first arrow and Page logic, which also fixes the arrow keys getting stuck at 7 or 57 for a controlled value={fraction * 100}. Whether a drag, track press or mark press should select an off-grid max (the nearest of the step grid plus max, ties going to max) is not settled by the current Slider spec, so a maintainer needs to provide or identify the governing spec for that pointer rule before it can be approved; you don't need to write it.

[Automated review]

Comment on lines +843 to +859
const snapped = snapToStep(currentVal, min, step);
let newVal: number;

switch (e.key) {
case 'ArrowRight':
case 'ArrowUp':
newVal = currentVal + step;
newVal =
snapped > currentVal
? snapped
: snapToStep(currentVal + step, min, step);
break;
case 'ArrowLeft':
case 'ArrowDown':
newVal = currentVal - step;
newVal =
snapped < currentVal
? snapped
: snapToStep(currentVal - step, min, step);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arrow keys can stall on floating-point noise. snapped > currentVal and snapped < currentVal are exact comparisons, so a controlled value that is off the grid only by binary rounding counts as off-grid, and the press just returns its grid value. When the caller maps that value back the same way, the next render brings the noise back and the thumb never moves: with value={fraction * 100} and onChange={v => setFraction(v / 100)} (default step), stepping down from 10 stops at 7 (0.07 * 100 is 7.000000000000001), and stepping up from 55 stops at 57. main keeps stepping. Treating a value within rounding tolerance of snapped as on the grid avoids it, for example:

const snapped = snapToStep(currentVal, min, step);
const offGrid = Math.abs(snapped - currentVal) > Math.abs(step) * 1e-9;
// ArrowRight / ArrowUp; mirror it for ArrowLeft / ArrowDown
newVal =
  offGrid && snapped > currentVal
    ? snapped
    : snapToStep(currentVal + step, min, step);

A regression test with a fraction-backed controlled value would keep it fixed.

@cixzhang

Copy link
Copy Markdown
Contributor

Closing as superseded by #7516. Posted by Cindy's agent on her behalf.

@cixzhang cixzhang closed this Oct 28, 2026
@github-actions
github-actions Bot deleted the fix/slider-step-endpoint branch October 29, 2026 11:51

This branch was successfully deployed

1 active deployment
Preview — 4ba130d2 Deployed Oct 13, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Slider cannot reach max when step does not divide the range

2 participants