Skip to content

[Slider] Fix sticky value with keyboard #733

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

Merged
merged 2 commits into from
Jun 22, 2021
Merged

Conversation

jjenzz
Copy link
Contributor

@jjenzz jjenzz commented Jun 21, 2021

Fixes #732

@@ -117,7 +117,7 @@ const Slider = React.forwardRef((props, forwardedRef) => {
const nextValues = getNextSortedValues(prevValues, nextValue, atIndex);
if (hasMinStepsBetweenValues(nextValues, minStepsBetweenThumbs * step)) {
valueIndexToChangeRef.current = nextValues.indexOf(nextValue);
return nextValues[atIndex] !== prevValues[atIndex] ? nextValues : prevValues;
return String(nextValues) === String(prevValues) ? prevValues : nextValues;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the change, but I can't wrap my head around why the previous way would create the keyboard bug yet this wouldn't. 🤔

Copy link
Contributor Author

@jjenzz jjenzz Jun 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For anyone else following along, without this change we ended up with something like this:

- arrow press, values [15,16,20] (atIndex = 0, valueIndexToChange = 0)
- arrow press, values [16,16,20] (atIndex = 0, valueIndexToChange = 0)
- arrow press, values [16,17,20] (atIndex = 0, valueIndexToChange = 1)

That last array would then check nextValues[0] !== prevValues[0] (16 !== 16) which would be equal and return the prevValues.

I could have changed this to return nextValues[valueIndexToChangeRef.current] !== prevValues[valueIndexToChangeRef.current] ? nextValues : prevValues; but all we actually care about is whether the array changes so that unnecessary renders from state updates don't trigger.

Base automatically changed from fix-slider-key-focus to main June 22, 2021 10:59
@jjenzz jjenzz force-pushed the fix-slider-sticky-value branch from fd490b4 to 53690a0 Compare June 22, 2021 11:13
@jjenzz jjenzz merged commit e65ff73 into main Jun 22, 2021
@jjenzz jjenzz deleted the fix-slider-sticky-value branch June 22, 2021 11:24
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.

[Slider] Extra keypress required to move thumb
2 participants