Skip to content

Fix slider zero falsy#21864

Open
MarianaAa01 wants to merge 4 commits intocarbon-design-system:mainfrom
MarianaAa01:fix-slider-zero-falsy
Open

Fix slider zero falsy#21864
MarianaAa01 wants to merge 4 commits intocarbon-design-system:mainfrom
MarianaAa01:fix-slider-zero-falsy

Conversation

@MarianaAa01
Copy link

Closes #21611

When the slider is initialized with value 0 and a negative min, the knob is placed at the leftmost position instead of the correct position. This happens because if (value) treats 0 as falsy, falling back to _cachedRate instead of computing the correct rate.

Changelog

Changed

  • Fixed slider value handling when value is 0 by replacing falsy checks (if (value) / if (unstable_valueUpper)) with explicit null checks (!= null), ensuring 0 is treated as a valid value.

Testing / Reviewing

  • Initialize with value="0" and confirm el.value === 0.
  • Confirm the thumb reflects aria-valuenow="0" on initial render.
  • Simulate click at 50% of the track and ensure value remains 0.
  • Simulate click at 90% of the track and verify the value updates proportionally.

PR Checklist

As the author of this PR, before marking ready for review, confirm you:

  • Reviewed every line of the diff
  • Updated documentation and storybook examples
  • Wrote passing tests that cover this change
  • Addressed any impact on accessibility (a11y)
  • Tested for cross-browser consistency
  • Validated that this code is ready for review and status checks should pass

More details can be found in the pull request guide

MarianaAa01 and others added 4 commits March 11, 2026 14:17
When the slider is initialized with value 0 and a negative min,
the knob is placed at the leftmost position instead of the correct
position. This happens because if (value) treats 0 as falsy,
falling back to _cachedRate instead of computing the correct rate.

Fixes carbon-design-system#21611
@MarianaAa01 MarianaAa01 requested a review from a team as a code owner March 18, 2026 22:00
@github-actions
Copy link
Contributor

github-actions bot commented Mar 18, 2026

All contributors have signed the DCO.
Posted by the DCO Assistant Lite bot.

@MarianaAa01
Copy link
Author

I have read the DCO document and I hereby sign the DCO.

@netlify
Copy link

netlify bot commented Mar 18, 2026

Deploy Preview for v11-carbon-web-components ready!

Name Link
🔨 Latest commit 79f85c8
🔍 Latest deploy log https://app.netlify.com/projects/v11-carbon-web-components/deploys/69bb2069ae49b400090acff8
😎 Deploy Preview https://deploy-preview-21864--v11-carbon-web-components.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.

@netlify
Copy link

netlify bot commented Mar 18, 2026

Deploy Preview for v11-carbon-react ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 79f85c8
🔍 Latest deploy log https://app.netlify.com/projects/v11-carbon-react/deploys/69bb2069e9d3ba0008e5752f
😎 Deploy Preview https://deploy-preview-21864--v11-carbon-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 project configuration.

const { max, min, value } = this;
// Copes with out-of-range value coming programmatically or from `<cds-slider-input>`
if (value) {
if (value != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is '' supposed to pass this check?

Copy link
Author

Choose a reason for hiding this comment

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

Is it better then to do if (value || value === 0) or to do if (value !== null || value !== undefined || value !== '')? Because it looks as if the functionality inside the if statement expects value to be a number but currently it accepts any non falsy value.

Copy link
Contributor

Choose a reason for hiding this comment

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

value || value === 0 is the safer change here.

value !== null || value !== undefined || value !== '' would always evaluate to true, so it would not guard anything. Even if that were changed to &&, it would still allow NaN through.

Longer term, after this bug is fixed, this code could probably be improved with Number.isFinite(value) so it only accepts numeric values. That's a separate change though.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: slider initialized with 0 treated as falsy instead of true zero

2 participants