Skip to content

Slider: stop the track from resizing while you drag#4050

Open
AKnassa wants to merge 1 commit into
facebook:mainfrom
AKnassa:ak-4033-slider-track-stability
Open

Slider: stop the track from resizing while you drag#4050
AKnassa wants to merge 1 commit into
facebook:mainfrom
AKnassa:ak-4033-slider-track-stability

Conversation

@AKnassa

@AKnassa AKnassa commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

What this does

Fixes the Slider so the bar stays the same size while you drag the knob, and makes the numbers it shows clean (no more 0.30000000000000004).

Screen.Recording.2026-07-18.at.12.27.39.AM.mov

Why

The value label next to the slider changed width as the number changed (like "9" becoming "10"), which squeezed the bar, which moved the knob under your mouse, which changed the number again — so the whole thing jittered while dragging. And with decimal steps, the label could show long floating-point garbage.

What changed

  • The value label now reserves enough space for the widest number it could ever show, so the bar never grows or shrinks mid-drag.
  • Digits now use equal-width numerals, so the label doesn't wiggle as values tick by.
  • Decimal steps now produce clean values (0.3, not 0.30000000000000004) — in the label, for screen readers (aria-valuenow), and in the value given to your code (onChange).

How to see it

Open the Slider story in Storybook (pnpm -F storybook dev, then Core → Slider) and drag the knob back and forth without releasing — the track stays perfectly still and the numbers stay tidy. Six new tests cover the width reservation and the decimal-step precision.

Fixes #4033

The text value label sits in the same flex row as the flex-growing
track, so a label changing width while dragging resized the track and
shifted the thumb under the pointer, retriggering value recalculation.
Reserve the width of the widest formatted candidate (min/max/±step,
doubled plus separator in range mode) in ch units with tabular-nums so
the track size never moves.

Also snap decimal steps to the precision of step/min so 0.2 + 0.1
emits 0.3 — not 0.30000000000000004 — in the visible label,
aria-valuenow, and onChange.

Fixes facebook#4033
@vercel

vercel Bot commented Jul 18, 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 18, 2026 4:29am

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 18, 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 18, 2026
@AKnassa
AKnassa marked this pull request as ready for review July 18, 2026 04:28
@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.7KB 0B

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | View full report

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 component - track size changes often

1 participant