Skip to content

When multiple slider thumbs are visually collapsed, the thumb with the highest index captures all pointer interaction. #6408

Open
@robin-kestrel

Description

@robin-kestrel

Provide a general summary of the issue here

Suppose a user is looking at a slider rendered with <Slider min={0} max={100} value={[50, 50]} {...etc} />, and wants to change the currently selected range from [50, 50] to [25, 50]. Because both thumbs are initially at 50, the slider appears to have just one thumb.

One might expect that clicking on that thumb and dragging it to the left would change the selected range, but it does not, because it's the second thumb that gets the pointer events, and that second thumb can only be dragged to the right. If our hypothetical user wants to use the thumbs to change the selected range from [50, 50] to [25, 50], they would need to:

  1. Click on the collapsed thumb and drag it to the right, changing the value from [50, 50] to [50, n] for some value of n between 51 and 100.
  2. Click on the left thumb and drag it to 25, changing the value from [50, n] to [25, n].
  3. Click on the right thumb and drag it back to 50, changing the value from [25, n] to [25, 50].

Usually this is merely annoying, but it gets particularly nasty if both the thumbs are set to the slider's maximum value, e.g. <Slider max={100} value={[100, 100]} {...etc} />. In that case, both thumbs will be collapsed at the end of the slider's track; clicking on that collapsed thumb selects the second thumb, which cannot move at all. In this state, the slider appears completely stuck. It is possible to escape from this state by either clicking on the slider's track or using keyboard controls, but these workarounds may be far from obvious to an end user.

🤔 Expected Behavior?

When both thumbs in a range slider are collapsed to the same value, it should be possible to click on that collapsed thumb and drag it in either direction.

😯 Current Behavior

When both thumbs in a range slider are collapsed to the same value, it is only possible to to drag it to the right — or not at all, if that value is also the slider's maximum.

💁 Possible Solution

Neither Radix UI not MUI Base have this bug; both of those allow the two thumbs of a range slider to swap positions.

That said, those libraries only support one-thumb and two-thumb sliders, whereas react-aria supports sliders with an arbitrary number of thumbs, which does complicate things. (I am kind of curious — how often are sliders with more than two thumbs actually used? It seems pretty niche.) [Edit: I was mistaken; Radix also supports multiple thumbs.]

I think the cleanest solution would be to remove the restriction on thumbs moving past their neighbors — allowing any thumb to move to any value — and having the value of a multi-thumb slider be equal to the sorted values of its thumbs. I think this should be the default behavior; perhaps the current behavior, where thumbs are restricted from moving past their neighbors, could be enabled with a prop.

Edit: I noticed that react-spectrum includes a partial workaround for this. If a thumb is in focus, it gets a higher z-index, which means that if you drag both thumbs to the same value, the next time you click on that visually collapsed thumb, you'll target the last thumb you used. This can help to keep the thumbs from getting stuck at one end of the slider — but only as long as you maintain focus.

🔦 Context

See also mui/material-ui#6338 for more reasons to allow thumbs to swap positions.

🖥️ Steps to Reproduce

  1. Look at any RAC range slider, e.g. the one just under https://react-spectrum.adobe.com/react-aria/Slider.html#reusable-wrappers.
  2. Drag the second thumb all the way to the right.
  3. Drag the first thumb all the way to the right.
  4. Click and drag the single visible thumb, and enjoy the sense of futility that washes over you as you fail to move it.

Or:

  1. Look at any RS range slider, e.g. the one just under https://react-spectrum.adobe.com/react-spectrum/RangeSlider.html#example.
  2. Drag the second thumb all the way to the right.
  3. Drag the first thumb all the way to the right.
  4. Click somewhere else to lose the focus on the first thumb.
  5. Click and drag the single visible thumb, and contemplate with equanimity its failure to give one hoot about your heart's desire.

Version

latest

What browsers are you seeing the problem on?

Firefox, Chrome, Safari

What operating system are you using?

OS X

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions