-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix(#2664): useColorSlider: refine PageUp/PageDown behaviors #2666
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
Conversation
61a13d3
to
8e9b59b
Compare
Build successful! 🎉 |
8e9b59b
to
8573563
Compare
Build successful! 🎉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, tested in storybook. Also, link in the test instructions should probably be updated to go the ColorArea story
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels kinda weird that onChangeEnd happens when pressing Left/Right/Up/Down at either extremes but PageUp/Down/End/Home don't but I'm fine with addressing that in a separate PR
EDIT: Ah never mind, I see that you've fixed the above behavior in #2661
Build successful! 🎉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
cc @snowystinger if you wanna take a quick look since this is pointed towards your color area branch |
Build successful! 🎉 |
Build successful! 🎉 |
d2d0fc7
to
8256492
Compare
Build successful! 🎉 |
8256492
Build successful! 🎉 |
state.setValue(state.value.withChannelValue(channel, newValue)); | ||
} | ||
// wait a frame to ensure value has changed then unset this so that onChangeEnd is fired | ||
requestAnimationFrame(() => state.setThumbDragging(0, false)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should be able to structure this the same way as useSlider https://github.com/adobe/react-spectrum/blob/main/packages/%40react-aria/slider/src/useSliderThumb.ts#L115
so that we don't need the raf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#2570 (comment) might be a concern, lemme double check
let newValue = channelValue; | ||
switch (e.key) { | ||
case 'PageUp': | ||
newValue = channelValue + pageStep > maxValue ? maxValue : snapValueToStep(channelValue + pageStep, minValue, maxValue, pageStep); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useColorSliderState should have increment/decrement thumb functions https://github.com/adobe/react-spectrum/blob/main/packages/%40react-stately/color/src/useColorSliderState.ts
see
https://github.com/adobe/react-spectrum/blob/main/packages/%40react-stately/slider/src/useSliderState.ts#L125
We should try to match this logic to useSlider as best we can
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a heads up, but I think @majornista was running into some issues w/ using the setThumbValue
not updating the color value here, need to double check myself
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interesting, I reopened that PR with a pared-down set of changes, #2887
it's passing the tests, I think I need more info on what was going wrong
Build successful! 🎉 |
- Omit change events when value doesn't change. - Refine snapValueToStep for incrementing or decrementing from max.
c61bbb6
to
f533056
Compare
Build successful! 🎉 |
…Size If the channel range step is less than 1, like 0.01, and stepSize is not passed as a prop, the slider will always increment or decrement by 1.
Build successful! 🎉 |
Build successful! 🎉 |
Build successful! 🎉 |
Build successful! 🎉 |
// wait a frame to ensure value has changed then unset this so that onChangeEnd is fired | ||
state.setThumbDragging(0, false); | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't useSliderThumb handle this? I saw the above discussion but I'm not sure why it is resolved?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had readded it cuz the behavior broke with the removal of pageSize from useSliderState props in #2917, but I can re-remove it since we want to keep pageSize prop in useSliderState
EDIT: re-removed since we now overwrite useSliderState's step/pageSize with the color channel's specific step/pageSize in useColorSliderState
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
62c7693
to
bebd2cc
Compare
Build successful! 🎉 |
function incrementThumb(index: number, stepSize: number = 1) { | ||
let {maxValue, minValue, step} = color.getChannelRange(channel); | ||
let channelValue = color.getChannelValue(channel); | ||
let s = Math.max(stepSize, step); | ||
sliderState.setThumbValue(index, channelValue + s > maxValue ? maxValue : snapValueToStep(channelValue + s, minValue, maxValue, s)); | ||
} | ||
|
||
function decrementThumb(index: number, stepSize: number = 1) { | ||
let {maxValue, minValue, step} = color.getChannelRange(channel); | ||
let channelValue = color.getChannelValue(channel); | ||
let s = Math.max(stepSize, step); | ||
sliderState.setThumbValue(index, snapValueToStep(channelValue - s, minValue, maxValue, s)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we actually need these increment/decrementThumb functions? Think we don't need them now that ColorSliderState exposes the correct step/pageStep size?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did some testing, I think we don't need these, I believe useSliderState
's increment/decrementThumb
+ useSliderThumb
is now getting the correct step/pageStep size with the changes to ColorSliderState. I'll go ahead and push the changes, note I needed to modify
react-spectrum/packages/@react-spectrum/color/test/ColorSlider.test.tsx
Lines 304 to 306 in 03d5ebe
expect(onChangeSpy.mock.calls[4][0].toString('hexa')).toBe(defaultColor.withChannelValue('red', 0).toString('hexa')); | |
expect(onChangeEndSpy).toHaveBeenCalledTimes(5); | |
expect(onChangeEndSpy.mock.calls[4][0].toString('hexa')).toBe(defaultColor.withChannelValue('red', 0).toString('hexa')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah wait, nevermind, we want this snapping behavior onPageUp/Down.
EDIT: actually do we want this snapping behavior for onPageUp/Down? Original issue doesn't describe the desired behavior, ColorArea doesn't work like this but ColorWheel does?
eg. Red slider, current value is 2, pageStep is 17 as per channelValue pageStep. Press pageUp -> value snaps to 17 rather than 19?
cc @majornista @snowystinger @devongovett
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if a step is provided, we snap to the step, is that what you're asking?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about if a pageSize is provided? Should pageUp/Down always snap to a pageSize value or should it just increment/decrement by the pageSize value? Right now in this PR, ColorSlider will snap to a pageStep value upon using pageUp/Down (see the example I listed about) but this diverges from the behavior on main where pageUp/Down will increment by the pageSize value.
If it shouldn't snap to the pageStep value then I'll go ahead and remove the increment/decrementThumb functions but if that behavior is correct, then should we update the ColorArea to behave the same way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a step cannot be supplied to a colorslider, nor can a page size, those are determined in the color space
pageSize should always snap to the step
…/react-spectrum into Issue-2664-useColorSlider-pageSize
Build successful! 🎉 |
Build successful! 🎉 |
Build successful! 🎉 |
Build successful! 🎉 |
Build successful! 🎉 |
Build successful! 🎉 |
Closes #2664
✅ Pull Request Checklist:
📝 Test Instructions:
PageUp/Down should work for ColorSlider and should increment and decrement the value by the pageStep size. pageStep size is determined by the color channel.
For rgb channels, pageStep is 17
For alpha/satuaration/other percentage channesl, pageStep is .1
For hue, pageStep is 15 degrees
values reached via pageUp/Down should always be values reachable via the step
🧢 Your Project:
Adobe/Accessibility