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

Support a clickable label for Slider #379

Open
penx opened this issue Mar 15, 2024 · 2 comments
Open

Support a clickable label for Slider #379

penx opened this issue Mar 15, 2024 · 2 comments
Labels
a11y Related to accessibility request New feature or request

Comments

@penx
Copy link
Contributor

penx commented Mar 15, 2024

I would like to add a label element for a slider component. Clicking the label should focus the slider.

At the moment I cannot find a way to do this with Radix Themes directly.

I can do this with Radix Primitives by making the Slider.Thumb a input[type="range"] using the asChild prop.

As Radix Themes does not expose the Thumb part, in order to do this with Radix Themes I would need to build my own Slider using the Radix Themes classes and Radix Primitives parts.

This is fine - but perhaps this technique is useful for others or perhaps you want to incorporate this in to Radix Themes. I am not sure if there is a drawback to making the Thumb part an input[type=range], I haven't found one yet, but if there is not perhaps this should be done as standard?

Check out this stackblitz - it shows the issue and how I have solved it:

https://stackblitz.com/edit/vitejs-vite-5ikew3

Note that the Thumb already has role="slider" and, as far as I can see, input[type=range] is a sensible default when using role=slider:

When not using the HTML element to create your slider
...
It is recommended to use a native of type range, , rather than the slider role.

https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/slider_role

@vladmoroz
Copy link
Contributor

@benoitgrelard check this out

image

@vladmoroz vladmoroz added request New feature or request a11y Related to accessibility labels Mar 15, 2024
@jjenzz
Copy link

jjenzz commented Mar 15, 2024

changing the Slider.Thumb to a button by default wld also fix this. the slider supports multiple thumbs so unstyled ranges might look a bit weird here. they would allow Radix to remove some internal BubbleInput logic though which could be nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a11y Related to accessibility request New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants