-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Slider component for @react-stately and @react-aria #809
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
Skimmed this just now and it looks awesome! Will take a more in depth look tomorrow. 😍 |
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.
Looks really great so far! Will discuss a couple API things with the team tomorrow, but here's a few suggestions/comments to start with. 😄
@devongovett Many thanks for the quick response! Makes sense to me; will get back to this soon 😅 Re: overlapping handles -- this seems like an opinionated decision that perhaps should be made by the component author (so, for example, would live in react-spectrum and not react-aria)? react-aria will give you the offset percentages of each handle, and it is up to you to decide how you want to render those handles (like doing a slight translateX if two handles have the same offset)... |
That makes sense to me! |
I've taken a pass at addressing the feedback. Once there's consensus on the API and the behavior, I can start writing up some tests 😄 |
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.
Looks great. A couple of small API things. Other than that, looks good to move forward on tests when you have time! 😄
onIncrement: () => state.setValue(index, value + step), | ||
onDecrement: () => state.setValue(index, value - step), | ||
onIncrementToMax: () => state.setValue(index, maxValue), | ||
onDecrementToMin: () => state.setValue(index, minValue) |
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 these are working right now? Home and End aren't doing anything for me. I think you may need to pass through the onKeyDown
handler to the input element?
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.
Maybe we could add methods for incrementing/decrementing a thumb to stately? Then you wouldn't need to pass through minValue
and maxValue
as well. These are somewhat confusing since they are the minimum/maximum of the whole slider rather than the individual thumb. Setting the value only works because it is clamped in state.setValue
. So maybe having a method like state.incrementToMax(index)
would be clearer?
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.
Hmm, weird; Home and End do work for me (Mac/Chrome, Mac/Safari, Linux/Chrome). The focus is on the input[type=range]
control, so as long as the browser handles those shortcuts, we should see the changes in the onChange handler on the input... 🤔
We actually don't need to pass in onIncrement/onIncrementMax/etc. at all now, since we're just letting the browser handle the stepping... Will remove!
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.
(Could you let me know the browser/OS combo where you're seeing the Home/End issue?)
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.
It was macOS safari. But let me check again.
Hi all! Just took another pass addressing the feedback, as well as adding tests for The only piece of feedback I'm still hesitating about is this: #809 (comment) Again, happy to do what you believe is most conventional here, just wanted to point out a few things! |
(else once focus is on a draggable, you cannot tab out of it)
Example components built from them are in @react-aria/slider/stories, with some Storybook stories as well. No unit tests yet.
Instead of handling keyboard interactions ourselves via useDrag1D's onKeyDown handler
5881e60
to
a075c63
Compare
I believe I've resolved all the remaining comments (except for keyboard shortcuts not working for @devongovett when he tried it last). Thanks for the feedback! |
Excellent! Will take one final look tomorrow morning and get it merged. 😄 |
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.
Nice work! Thanks again. 😄
Yay! It's clear you folks really prioritize community involvement, and working on this PR was an awesome experience 😍 |
This creates:
useMultiSliderState
for @react-stately/slider for managing slider state for multiple valuesuseMultiSlider
for @react-aria/slider for managing interactions and accessibility for slider componentsIncludes some Storybook stories and toy components using the above hooks to build sliders.
Does not include slider implementations for @react-aria/spectrum.
Closes #763
✅ Pull Request Checklist:
📝 Test Instructions:
For now, just visual tests on Storybook under the "Slider" group, starting here: http://localhost:9003/?path=/story/slider--single
🧢 Your Project:
Plasmic