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] onValueCommit not called when start/end are equal #3329

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

emmavray
Copy link

onValueCommit not called when start/end are equal

Description

For multi-value sliders where two values are allowed to overlap, onValueCommit will not be called for overlapping values.

#1760

Steps to reproduce

<Slider.Root
	defaultValue={[10, 30]}
	minStepsBetweenThumbs={0}
>
	<Slider.Track>
		<Slider.Range />
	</Slider.Track>
	<Slider.Thumb />
	<Slider.Thumb />
</Slider.Root>

Dragging the END value equal to the START value will trigger onValueChange but will not trigger onValueCommit, despite the end value having changed.

Screen.Recording.2025-01-18.at.3.07.16.PM.mov

Cause

updateValues() is responsible for setting valueIndexToChangeRef, which is used later by handleSlideEnd() to determine if changes have been made. The problem is that updateValues() will attempt to find the relevant index by searching for the current value -- using the first index found. If the array contains multiple identical values, this strategy will fail.

Effectively when multiple Thumbs have identical values, the first index is always used. This means that handleSlideEnd() will only check for changes in the first Thumb's value.

Changing values using the keyboard works as expected, this bug only affects dragging behavior. Changing the first value always works as expected.

Fix

updateValues() already receives an index parameter; it's used to validate that the minSteps has been satisfied, and in some cases used for change detection. Using this index instead of trying to infer it by searching the first occurrence of the value solves the issue.

@emmavray emmavray changed the title [Slider] onValueCommit not called when start/end are equal #1760 [Slider] onValueCommit not called when start/end are equal Jan 18, 2025
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