Skip to content

[slider] Fix keyboard floating-point rounding - #4548

Merged
atomiks merged 4 commits into
mui:masterfrom
atomiks:codex/slider-keyboard-rounding
Apr 8, 2026
Merged

atomiks merged 4 commits into
mui:masterfrom
atomiks:codex/slider-keyboard-rounding

Conversation

@atomiks

@atomiks atomiks commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Fixes #4547

This keeps keyboard-driven slider updates aligned with the configured step when working with fractional values. Arrow key and page key interactions now normalize their computed value before clamping, matching the existing pointer behavior.

Changes

  • Round keyboard step updates before applying the new slider value.
  • Add a regression test covering fractional keyboard increments on the slider.

@atomiks atomiks added type: bug It doesn't behave as expected. component: slider Changes related to the slider component. labels Apr 7, 2026 — with ChatGPT Codex Connector
@pkg-pr-new

pkg-pr-new Bot commented Apr 7, 2026 •

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@4548
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@4548
    

commit: 99afcda

@mui-bot

mui-bot commented Apr 7, 2026 •

Copy link
Copy Markdown

Bundle size report

Bundle Parsed size Gzip size
@base-ui/react 🔺+71B(+0.02%) 🔺+27B(+0.02%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

@netlify

netlify Bot commented Apr 7, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 99afcda
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/69d5e256e675e00008b72f73
😎 Deploy Preview https://deploy-preview-4548--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

atomiks commented Apr 7, 2026 •

Copy link
Copy Markdown
Contributor Author

Codex Review (GPT-5.4)

Dominant type: bug-fix (secondary: tests, react-ui). I re-reviewed the current patch against a freshly fetched upstream/master after the follow-up commit and reran pnpm test:jsdom SliderRoot SliderThumb roundValueToStep --no-watch plus pnpm prettier --check packages/react/src/slider/utils/roundValueToStep.ts packages/react/src/slider/utils/roundValueToStep.test.ts.

1. Remaining Bugs / Issues (None)

Previous Review Issues Status

The latest inline review note about fractional min origins is now addressed. roundValueToStep() preserves precision from both step and min, so values such as min={0.25} with step={0.1} no longer collapse to 0.3 when the valid stepped value is 0.35.

Root Cause & Patch Assessment

The original keyboard fix was correct in scope, and this follow-up closes a separate rounding gap in the shared slider step helper. Using the maximum precision of step and min is consistent with slider semantics because the valid value grid is anchored to the min origin, not just the step size in isolation.

Test Coverage Assessment

Coverage is now stronger in the exact area raised by review.

  • The branch already had regressions for fractional keyboard stepping and largeStep behavior.
  • It now also includes a focused utility regression for fractional min origins in roundValueToStep.

That looks sufficient for this PR’s current scope.

Recommendation

Approve ✅

I do not see any remaining branch-specific issues in the current patch. The latest follow-up addresses the inline review concern directly and adds targeted coverage for it.

@atomiks
atomiks requested a review from mj12albert April 7, 2026 12:56
@atomiks
atomiks marked this pull request as ready for review April 7, 2026 12:58

@mj12albert mj12albert Apr 7, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
return Number(nearest.toFixed(Math.max(getDecimalPrecision(step), getDecimalPrecision(min))));

Not directly related, but while testing this I noticed that <Slider min={0.25} step={0.1} defaultValue={0.35} max={1} /> doesn't work, unlike NumberField. This should fix it

@atomiks
atomiks merged commit 481ddf7 into mui:master Apr 8, 2026
7 checks passed
@atomiks
atomiks deleted the codex/slider-keyboard-rounding branch April 8, 2026 05:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: slider Changes related to the slider component. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[slider] Value getting floating-point imprecision when using keyboard

3 participants