Skip to content

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

Merged
merged 12 commits into from
Aug 5, 2020

Conversation

chungwu
Copy link
Contributor

@chungwu chungwu commented Jul 21, 2020

This creates:

  • useMultiSliderState for @react-stately/slider for managing slider state for multiple values
  • useMultiSlider for @react-aria/slider for managing interactions and accessibility for slider components

Includes 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:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 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

@devongovett
Copy link
Member

Skimmed this just now and it looks awesome! Will take a more in depth look tomorrow. 😍

Copy link
Member

@devongovett devongovett left a 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
Copy link
Member

A couple other high level things:

  1. Should handles be able to overlap? Noticed that you can drag them directly on top of one another. Should we limit dragging so it can only come within some minimum distance (or touching)?
    image

  2. We'll need to adjust things so it works on touch devices. At the moment the handles don't move. I imagine this has more to do with the existing useDrag1D hook than anything you've implemented, so totally not your fault. And we can get this PR in as an initial implementation and follow up with touch support later as well. I think eventually we'll want to move that hook into @react-aria/interactions and add the touch support there. This will also apply to the mouse events that you've added in slider eventually as well.

Thanks again for this awesome (and quick) work! 😍

@chungwu
Copy link
Contributor Author

chungwu commented Jul 24, 2020

@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)...

@devongovett
Copy link
Member

That makes sense to me!

@chungwu
Copy link
Contributor Author

chungwu commented Jul 28, 2020

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 😄

Copy link
Member

@devongovett devongovett left a 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)
Copy link
Member

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?

Copy link
Member

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?

Copy link
Contributor Author

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!

Copy link
Contributor Author

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?)

Copy link
Member

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.

@chungwu
Copy link
Contributor Author

chungwu commented Aug 3, 2020

Hi all! Just took another pass addressing the feedback, as well as adding tests for useSliderState, useSlider, and useSliderThumb.

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!

@chungwu chungwu force-pushed the main branch 3 times, most recently from 5881e60 to a075c63 Compare August 5, 2020 05:05
@chungwu
Copy link
Contributor Author

chungwu commented Aug 5, 2020

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!

@devongovett
Copy link
Member

Excellent! Will take one final look tomorrow morning and get it merged. 😄

Copy link
Member

@devongovett devongovett left a 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. 😄

@devongovett devongovett merged commit 591c284 into adobe:main Aug 5, 2020
@chungwu
Copy link
Contributor Author

chungwu commented Aug 5, 2020

Yay! It's clear you folks really prioritize community involvement, and working on this PR was an awesome experience 😍

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.

useSlider() and useSliderState() for a Slider component
2 participants