-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Have slider work like color area #2819
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
Have slider work like color area #2819
Conversation
Build successful! 🎉 |
@@ -77,44 +77,79 @@ export function useSliderThumb( | |||
stateRef.current = state; | |||
let reverseX = direction === 'rtl'; | |||
let currentPosition = useRef<number>(null); | |||
|
|||
let pageSize = 1; |
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.
Should default page size be 1
or something like (getThumbMaxValue(index) - getThumbMinValue(index)) / 10
, so that PageUp
/PageDown
behaves like a native input[type=range]
?
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.
Also, should pageSize
be a public API distinct from step
? So that things like ColorSlider can increment or decrement RGB values by 0x10
using PageUp
/PageDown
while step
remains 0x1
.
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.
Also, should
pageSize
be a public API distinct fromstep
? So that things like ColorSlider can increment or decrement RGB values by0x10
usingPageUp
/PageDown
whilestep
remains0x1
.
I think it can be, not sure if we want to open that in this PR just to minimize changes we make. Would it simplify some of our code elsewhere? That would be a reason to do it.
Should default page size be
1
or something like(getThumbMaxValue(index) - getThumbMinValue(index)) / 10
, so thatPageUp
/PageDown
behaves like a nativeinput[type=range]
?
Interesting, I didn't pick up that that was what native was doing. I think that'd be ok.
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.
(getThumbMaxValue(index) - getThumbMinValue(index)) / 10
might be weird for RangeSlider where the min
and max
for each thumb value is constrained. I think this is yet another reason for a public API that distinguishes pageSize
from step
.
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.
Should pageSize
default to Math.max((maxValue - minValue) / 10), step)
?
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.
I don't think we support a vertical slider, but we should probably add a vertical slider story in the hooks section.
Also, a pageSize story.
} else { | ||
stateRef.current.decrementThumb(index, shiftKey ? pageSize : step); | ||
} | ||
} else if (deltaY > 0) { |
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.
Would it make sense to group the deltaX and deltaY portions?
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 am not sure I know what you're saying? I think this is pretty easy to follow, only X direction is influenced by locale direction
if (delta < 0 && currentValue === getThumbMinValue(index)) { | ||
return; | ||
if (deltaX > 0) { | ||
if (direction === 'rtl') { |
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 have reverseX
declared above at https://github.com/adobe/react-spectrum/pull/2819/files#diff-9eebdd2756162e835cc5a37501ce3ccc3decdfd5d1dee4345d2e5f5a06c38703R78
…direction === 'rtl'
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.
Do we need storybook examples of pageSize, or should I just add them in Issue-2659-useSliderThumb-onChangeEnd after merging.
…/End (#2661) * useSliderThumb: fire onChangeEnd for PageUp/PageDown/Home/End * fix(#2659): add onChangeEnd event handler to Slider/RangeSlider stories Per #2661 (review) * Have slider work like color area (#2819) * Match Slider implementation to color area * fix lint * make step optional with a default * add pagesize * Use native slider pagesize calculation * @trivial remove irrelevant comment and use the declared variable for direction === 'rtl' Co-authored-by: Michael Jordan <[email protected]> * fix(#2659): add pageSize stories * simplify slider move logic * a little more cleanup Co-authored-by: Daniel Lu <[email protected]> Co-authored-by: Robert Snow <[email protected]> Co-authored-by: Daniel Lu <[email protected]>
…/Home/End (adobe#2661) * useSliderThumb: fire onChangeEnd for PageUp/PageDown/Home/End * fix(adobe#2659): add onChangeEnd event handler to Slider/RangeSlider stories Per adobe#2661 (review) * Have slider work like color area (adobe#2819) * Match Slider implementation to color area * fix lint * make step optional with a default * add pagesize * Use native slider pagesize calculation * @trivial remove irrelevant comment and use the declared variable for direction === 'rtl' Co-authored-by: Michael Jordan <[email protected]> * fix(adobe#2659): add pageSize stories * simplify slider move logic * a little more cleanup Co-authored-by: Daniel Lu <[email protected]> Co-authored-by: Robert Snow <[email protected]> Co-authored-by: Daniel Lu <[email protected]>
Closes
This matches our work in color area and color slider.
Yes, we could rely on native behavior, but it causes the code to be fairly different and would make it harder in the future to support custom page size steps.
It also allows us to run some tests we couldn't run before.
✅ Pull Request Checklist:
📝 Test Instructions:
🧢 Your Project: