Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: slider to range step values #14460

Merged
merged 2 commits into from
Aug 21, 2023

Conversation

lee-chase
Copy link
Member

Closes #14455

Javascript floating point maths is a bit problematic.

0.3 + 0.3 + 0.3 evaluates to 0.89999999999'

The range control does not normally have a problem with this, ensuring the nearest fixed length value is used.

While this could be fixed by replicating the math inside the standard input control, the simplest solution is to set the value of a range control and read it back. This PR does just that.

Changelog

Changed

  • packages/react/src/components/Slider/Slider.tsx

Testing / Reviewing

  1. Run Storybook locally and selecting the Slider component.
  2. Set Step to 0.3.
  3. Drag the handle to the value 0.
  4. Press the up arrow 3 times.

The result should be 0.9 but is 0.8999999' due to JS floating point math.

Applying this PR we can see the value is 0.9.

@netlify
Copy link

netlify bot commented Aug 18, 2023

Deploy Preview for carbon-components-react ready!

Name Link
🔨 Latest commit 909ab7d
🔍 Latest deploy log https://app.netlify.com/sites/carbon-components-react/deploys/64dfc8c8ef0de60008201d35
😎 Deploy Preview https://deploy-preview-14460--carbon-components-react.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 site configuration.

@netlify
Copy link

netlify bot commented Aug 18, 2023

Deploy Preview for carbon-elements ready!

Name Link
🔨 Latest commit 909ab7d
🔍 Latest deploy log https://app.netlify.com/sites/carbon-elements/deploys/64dfc8c8c72c9800081b425a
😎 Deploy Preview https://deploy-preview-14460--carbon-elements.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 site configuration.

Copy link
Member

@tay1orjones tay1orjones left a comment

Choose a reason for hiding this comment

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

Clever to use the browser's built-in rounding to help with this situation. I like it! 👍

@github-actions github-actions bot added this pull request to the merge queue Aug 18, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Aug 18, 2023
@andreancardona andreancardona added this pull request to the merge queue Aug 21, 2023
Merged via the queue into carbon-design-system:main with commit 1aab3b5 Aug 21, 2023
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Slider with fractional values has javascript math error
4 participants