Skip to content

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

Open
b84330808 wants to merge 1 commit into
mui:masterfrom
b84330808:fix-slider-decimal-min
Open

b84330808 wants to merge 1 commit into
mui:masterfrom
b84330808:fix-slider-decimal-min

Conversation

@b84330808

Copy link
Copy Markdown

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.

…step

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@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 3m 06s · details


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

This branch has not been deployed

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

Labels

None yet

1 participant