Skip to content

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

Conversation

snowystinger
Copy link
Member

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:

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

🧢 Your Project:

@adobe-bot
Copy link

Build successful! 🎉

@@ -77,44 +77,79 @@ export function useSliderThumb(
stateRef.current = state;
let reverseX = direction === 'rtl';
let currentPosition = useRef<number>(null);

let pageSize = 1;
Copy link
Collaborator

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

Copy link
Collaborator

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.

Copy link
Member Author

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.

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 that PageUp/PageDown behaves like a native input[type=range]?

Interesting, I didn't pick up that that was what native was doing. I think that'd be ok.

Copy link
Collaborator

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.

@adobe-bot
Copy link

Build successful! 🎉

Copy link
Collaborator

@majornista majornista left a 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)?

@adobe-bot
Copy link

Build successful! 🎉

Copy link
Member

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

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?

Copy link
Member Author

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') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

@adobe-bot
Copy link

Build successful! 🎉

Copy link
Collaborator

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

@majornista majornista merged commit 92cb6ee into Issue-2659-useSliderThumb-onChangeEnd Feb 11, 2022
@majornista majornista deleted the have-slider-work-like-color-area branch February 11, 2022 16:29
majornista added a commit to majornista/react-spectrum-v3 that referenced this pull request Feb 14, 2022
snowystinger added a commit that referenced this pull request Feb 17, 2022
…/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]>
majornista added a commit to majornista/react-spectrum-v3 that referenced this pull request Feb 18, 2022
majornista added a commit to majornista/react-spectrum-v3 that referenced this pull request Feb 18, 2022
…/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]>
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.

4 participants