Skip to content

[slider] Keep the decimals of a non-integer min when snapping to the step - #49635

Merged
ZeeshanTamboli merged 3 commits into
mui:masterfrom
b84330808:fix-slider-decimal-min
Nov 9, 2026
Merged

ZeeshanTamboli merged 3 commits into
mui:masterfrom
b84330808:fix-slider-decimal-min

Conversation

@b84330808

@b84330808 b84330808 commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

With a non-integer min and an integer step, clicking or dragging the Slider lands on integers instead of the step grid. With <Slider min={0.5} max={10.5} step={1} /> the valid values are 0.5, 1.5, 2.5, … (that's where marks draws them, and what the arrow keys give), but a click at 30% sets 4 instead of 3.5.

roundValueToStep snaps to … * step + min but then rounds to the decimals of step only, so the .5 coming from min gets rounded away:

function roundValueToStep(value: number, step: number, min: number) {
const nearest = Math.round((value - min) / step) * step + min;
return Number(nearest.toFixed(getDecimalPrecision(step)));
}

This rounds to the larger of the decimals of step and min. Added a test under prop: step that fails on master with expected … 'aria-valuenow' with the value '3.5', but the value was '4'.

I used Claude Code to write this change.

Before: https://stackblitz.com/edit/github-nb1ogvqc
After: https://stackblitz.com/edit/x9gwqxz6

@code-infra-dashboard

code-infra-dashboard Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Deploy preview

https://deploy-preview-49635--material-ui.netlify.app/
QR code for https://deploy-preview-49635--material-ui.netlify.app/

Bundle size

Bundle Parsed size Gzip size
@mui/material 🔺+20B(0.00%) 🔺+9B(+0.01%)
@mui/lab 0B(0.00%) 0B(0.00%)
@mui/private-theming 0B(0.00%) 0B(0.00%)
@mui/system 0B(0.00%) 0B(0.00%)
@mui/utils 0B(0.00%) 0B(0.00%)

Details of bundle changes

Performance

No regressions in 32 benchmarks · ran 4m 39s · details


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

@zannager zannager added the scope: slider Changes related to the slider. label Nov 3, 2026
@ZeeshanTamboli ZeeshanTamboli added type: bug It doesn't behave as expected. needs cherry-pick The PR should be cherry-picked to master after merge. v9.x labels Nov 9, 2026

@ZeeshanTamboli ZeeshanTamboli left a comment

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.

Thanks for this. #49476 is the keyboard version of this rounding bug.

@ZeeshanTamboli
ZeeshanTamboli merged commit bde72af into mui:master Nov 9, 2026
23 checks passed
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Cherry-pick PRs will be created targeting branches: v9.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs cherry-pick The PR should be cherry-picked to master after merge. scope: slider Changes related to the slider. type: bug It doesn't behave as expected. v9.x

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants