Skip to content

[Slider] Expose getThumbIndex prop + API to Slider component #45577

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

Open
brandonscript opened this issue Mar 16, 2025 · 1 comment
Open

[Slider] Expose getThumbIndex prop + API to Slider component #45577

brandonscript opened this issue Mar 16, 2025 · 1 comment
Labels
component: slider This is the name of the generic UI component, not the React module! new feature New feature or request

Comments

@brandonscript
Copy link

brandonscript commented Mar 16, 2025

Summary

(I admit I don't know if there's a way to do this in v6, or planned in v7, but putting it out here just in case).

With the v5 Slider, there's no way to tell it which thumb index should respond to a value change event – it automatically determines this using closest proximity, via the findClosest function. This is troublesome for cases where you need fine-grained control over this, e.g. if the left/right thumbs are "trim" controls for video playback, while the middle thumb handles scrubbing.

To solve this, I modified the original Slider v5 source here (Gist) where I exposed a getThumbIndex function prop to the Slider component and useSlider hook. Now I can pass this function into the slider so it can determine which thumb should be triggered. I've also augmented it to pass min/max values to this function so that I can determine the % of total slider position.

Would be nice to see this prop exposed in future versions!

Examples

Source code of example: https://gist.github.com/brandonscript/f8d1aa0ec648a5da7fc684fa860f27b0 (modified Slider v5)

Motivation

Image

Search keywords: slider thumb index

@brandonscript brandonscript added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Mar 16, 2025
@zannager zannager added the component: slider This is the name of the generic UI component, not the React module! label Mar 17, 2025
@ZeeshanTamboli ZeeshanTamboli changed the title Expose getThumbIndex prop + API to Slider component [Slider] Expose getThumbIndex prop + API to Slider component Mar 25, 2025
@ZeeshanTamboli
Copy link
Member

ZeeshanTamboli commented Mar 29, 2025

We can introduce this prop, but we should also provide a demo in the docs showing how to use it with a custom method having a valid use-case like yours.

@ZeeshanTamboli ZeeshanTamboli added new feature New feature or request and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Mar 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: slider This is the name of the generic UI component, not the React module! new feature New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants