Skip to content

fix(slider): round snapped values to the min/step decimal precision - #3897

Merged
cixzhang merged 1 commit into
meta:mainfrom
arham766:fix/slider-step-precision
Jul 30, 2026
Merged

cixzhang merged 1 commit into
meta:mainfrom
arham766:fix/slider-step-precision

Conversation

@arham766

Copy link
Copy Markdown
Contributor

With fractional steps, snapToStep computed min + steps * step, which accumulates binary floating-point error: a keyboard nudge on a step={0.1} slider emitted 0.30000000000000004 through onChange/onChangeEnd, and the value leaked into aria-valuenow and the value tooltip once the consumer echoed it back. Snapped values are now rounded to the combined decimal precision of min and step (handling exponent-notation steps like 1e-7, capped at 20 digits for toFixed). A legitimately snapped value can never carry more decimals than min and step combined, so the rounding removes only the error — exact steps are unchanged.

Test plan:

pnpm exec vitest run packages/core/src/Slider/Slider.test.tsx

New tests drive fractional-step sliders via keyboard in both single and range mode and assert onChange receives exact decimals (0.3, not 0.30000000000000004).

@vercel

vercel Bot commented Jul 13, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview, Comment Jul 13, 2026 1:07am

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 13, 2026
@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 Jul 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR Analysis Report

No new or modified components detected.

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.6KB 0B

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | View full report

@cixzhang cixzhang 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.

Nice thanks for fixing these fractionals

@cixzhang
cixzhang enabled auto-merge (squash) July 30, 2026 04:29
@github-actions github-actions Bot removed the needs:code-review High-risk change (new package/component/API) — needs human code review before merge label Jul 30, 2026
@cixzhang
cixzhang merged commit 63b0660 into meta:main Jul 30, 2026
20 checks passed
AKnassa added a commit to AKnassa/astryx that referenced this pull request Sep 26, 2026
Resolved conflicts:
- packages/core/src/Slider/Slider.tsx: getDecimalPrecision/snapToStep
  took upstream/main's version from meta#3897 (counts mantissa digits via
  toExponential) and dropped this branch's duplicate helper. The
  text-value width change merged cleanly.
- packages/core/src/Slider/Slider.test.tsx: kept upstream's focus ring
  modality suite and this branch's width-stability suite. Dropped this
  branch's keyboard decimal-step test (duplicate of upstream's "emits
  exact decimal values for fractional steps on keyboard") and moved the
  pointer-position decimal test next to upstream's fractional-step
  tests, updating its comment for the thumb-inset travel math. The
  FormData test formatting now matches upstream exactly.
AKnassa added a commit to AKnassa/astryx that referenced this pull request Sep 26, 2026
Address the review on meta#4050.

F1 (exponent-notation steps lost mantissa digits): the merge from
upstream/main already replaced this branch's getDecimalPrecision with
the meta#3897 helper, which counts mantissa digits. Add a regression test
that steps a controlled slider by 1.23e-7 twice and expects onChange
1.23e-7 then 2.46e-7 and aria-valuenow "2.46e-7". With the old helper
it received [[1e-7], [2e-7]]. Drop the decimal-step sentence from the
changeset, because meta#3897 already shipped it.

F2/F3 (ch reservation missed mid-range and wide-glyph labels): drop
tabular-nums and the ch min-width. Each value now renders in an
inline-grid slot that stacks its visible text on an aria-hidden,
visibility:hidden, zero-height sizer listing every reachable formatted
label, one per line. The browser sizes the slot to the widest real
label, as Tab's labelSizer and ToggleButton's widthReservation do. The
sizer covers every step up to 200 steps (TEXT_VALUE_SIZER_LIMIT). Past
that it takes evenly spaced steps plus the endpoints' neighbours. Range
mode gives each value its own slot. Replace the ch-string tests with
sizer tests (every label whatever the value, a mid-range-widest word
formatter, `%` labels with no inline style, per-slot range sizers,
decimal steps, and long-range sampling). All six failed before the
change.

This branch was successfully deployed

1 active deployment
Preview — 808c0067 Deployed Jul 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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants