Skip to content

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

Merged
merged 18 commits into from
Mar 4, 2022

Conversation

majornista
Copy link
Collaborator

@majornista majornista commented Dec 9, 2021

  • Refine snapValueToStep for incrementing or decrementing from max.
  • Remove step/pageSize from ColorSlider and ColorField API
  • Fixes same thing this PR and its predecessor addressed Fix useNumberFieldStately dep on aria #2918, the flicker of the previous value before showing the new value

Closes #2664

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue 2664.
  • 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:

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

@majornista majornista force-pushed the Issue-2664-useColorSlider-pageSize branch from 61a13d3 to 8e9b59b Compare December 9, 2021 02:55
@adobe-bot
Copy link

Build successful! 🎉

@majornista majornista force-pushed the Issue-2664-useColorSlider-pageSize branch from 8e9b59b to 8573563 Compare December 9, 2021 16:30
@adobe-bot
Copy link

Build successful! 🎉

reidbarber
reidbarber previously approved these changes Dec 21, 2021
Copy link
Member

@reidbarber reidbarber left a 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

Copy link
Member

@LFDanLu LFDanLu left a 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

@adobe-bot
Copy link

Build successful! 🎉

LFDanLu
LFDanLu previously approved these changes Jan 28, 2022
Copy link
Member

@LFDanLu LFDanLu left a comment

Choose a reason for hiding this comment

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

LGTM

@LFDanLu
Copy link
Member

LFDanLu commented Jan 28, 2022

cc @snowystinger if you wanna take a quick look since this is pointed towards your color area branch

@adobe-bot
Copy link

Build successful! 🎉

@adobe-bot
Copy link

Build successful! 🎉

@majornista majornista force-pushed the Issue-2664-useColorSlider-pageSize branch from d2d0fc7 to 8256492 Compare February 24, 2022 01:33
@adobe-bot
Copy link

Build successful! 🎉

Base automatically changed from color-area to main February 25, 2022 00:07
@snowystinger snowystinger dismissed stale reviews from LFDanLu and reidbarber via 8256492 February 25, 2022 00:07
@adobe-bot
Copy link

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));
Copy link
Member

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

Copy link
Member

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);
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

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

Copy link
Member

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

@adobe-bot
Copy link

Build successful! 🎉

- Omit change events when value doesn't change.
- Refine snapValueToStep for incrementing or decrementing from max.
@majornista majornista force-pushed the Issue-2664-useColorSlider-pageSize branch from c61bbb6 to f533056 Compare February 28, 2022 23:01
@adobe-bot
Copy link

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.
@adobe-bot
Copy link

Build successful! 🎉

@adobe-bot
Copy link

Build successful! 🎉

@adobe-bot
Copy link

Build successful! 🎉

@adobe-bot
Copy link

Build successful! 🎉

// wait a frame to ensure value has changed then unset this so that onChangeEnd is fired
state.setThumbDragging(0, false);
}
});
Copy link
Member

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?

Copy link
Member

@LFDanLu LFDanLu Mar 4, 2022

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

reidbarber
reidbarber previously approved these changes Mar 4, 2022
Copy link
Member

@reidbarber reidbarber left a comment

Choose a reason for hiding this comment

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

LGTM

@LFDanLu LFDanLu force-pushed the Issue-2664-useColorSlider-pageSize branch from 62c7693 to bebd2cc Compare March 4, 2022 17:39
@adobe-bot
Copy link

Build successful! 🎉

Comment on lines 61 to 73
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));
}
Copy link
Member

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?

Copy link
Member

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

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'));
, those should be expecting 1 rather than 0 since the step is 17 for PageUp/Down

Copy link
Member

@LFDanLu LFDanLu Mar 4, 2022

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

Copy link
Member

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?

Copy link
Member

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

Copy link
Member

@snowystinger snowystinger Mar 4, 2022

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

@adobe-bot
Copy link

Build successful! 🎉

@adobe-bot
Copy link

Build successful! 🎉

@adobe-bot
Copy link

Build successful! 🎉

@adobe-bot
Copy link

Build successful! 🎉

@adobe-bot
Copy link

Build successful! 🎉

@adobe-bot
Copy link

Build successful! 🎉

@snowystinger snowystinger merged commit 3c89231 into main Mar 4, 2022
@snowystinger snowystinger deleted the Issue-2664-useColorSlider-pageSize branch March 4, 2022 21:31
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.

useColorSlider should increment/decrement by channel pageSize using PageUp/PageDown
7 participants