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

Slider: update --slider-bar-width to use 2*var(--slider-size) #7464

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Bvngee
Copy link

@Bvngee Bvngee commented Feb 9, 2025

My goal is to make a RangedSlider that looks something like this:

image

So after messing around a bit I ended up with the following props:

<RangeSlider thumbSize="6" styles={{ thumb: { borderWidth: 0 }}} />

However, by default, the bar component of the slider is not placed at equal distances from both of the thumbs, so it looks horrible:

image

After playing around in firefox's css inspector for a bit, I was able to figure out that changing the --slider-bar-width property of the mantine-Slider-bar div as such fixed the issue:

image

This makes sense in my head; First the bar's offset is set to the correct left side unfilled percentage, but then its subtracted by --slider-size for some padding (I assume). Now, after the width of the bar is set to the exact filled percentage, the right side is behind the correct placement by exactly --slider-size, and thus needs to be extended by 2*var(--slider-size) to match the appearance of the left side.

I've also been able to implement this fix in a slightly-hacky way using the Styles API:

<RangeSlider
    thumbSize="6"
    styles={{
        thumb: { borderWidth: 0 },
        bar: { width: "calc(var(--slider-bar-width) + var(--slider-size))", },
    }}
/>

I've verified extremely briefly that it doesn't break regular sliders, but I haven't tested much else at all (I'm doing this solely in the github UI, I merely guessed where the right place to put this is). Apologies, I just don't really have much time atm.

Please feel free to close this if I'm completely wrong about this problem and have a better idea for a solution. I've only just started using this library like yesterday, so I wouldn't be surprised :) Thanks everyone for your work and help!

@Bvngee
Copy link
Author

Bvngee commented Feb 9, 2025

Im even realizing this improves the look of the disabled rangedslider in the docs example:
image
image

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.

1 participant