-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
ColorPicker: store internal HSLA state for better slider UX #57555
Conversation
64d48bd
to
4161915
Compare
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'm guessing this is an artefact of colord
, but it feels really awkward that we drop the hue and saturation values in some circumstances; is there any way we can maintain them a little more consistently?
I know that H
is irrelevant when S
is 0
, and both are irrelevant when L
is {0,100}
, but the UX of dropping values just because the colour system doesn't need them isn't great.
Not a blocker for this PR, but something to think about.
I 100% share the sentiment. ColorPicker's |
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.
This is a much better user experience, thanks. ❤️
Would be worth optimizing the useEffect()
, and one way to do it could be to rely on the string representation of the HSL instead of on the HSL object. Could be done separately in a follow-up if you prefer.
It would also be nice to add some tests. Could be similar to what you demonstrated on the video preview in the PR description.
4161915
to
cb3303d
Compare
Feedback should be addressed. @chad1008 may be also taking a look and smoke test color pickers around the editor. I've also started exploring a more general solution which affects the whole |
Still looking great to me, thanks! |
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.
This looks good and tests well for me, both in Storybook and in the editor! 🚀 🚢
Fixes #57209
What?
Improve the UX of the
ColorPicker
when using HSL sliders, so that the use can move each slider freely even when that doesn't result in a change to the final colorWhy?
The way sliders work currently represents a bad UX
How?
The issue that we're trying to solve is caused by the fact that, when a slider's value changes, we convert from HSLA to a
colord
object in theonChange
function, and then we convert the receivedcolor
prop back to HSLA. Converting to acolord
object was necessary to have a universal representation of the color, regardless of the color space that the user chooses (RGB, HSL..). But doing so causes the H and S values to get "stuck" on0
if changing them wouldn't affect the final color value (see detailed explanation in #57209 (comment)).To get around this limitation, this PR stores the individual H/S/L/A values in local state. When the received color and the internal values produce the same resulting color, we can safely use the local H/S/L/A values (instead of the received color prop), which retain the values that the user selected by dragging the slider.
Testing Instructions
ColorPicker
storybook exampleNumberControl
should also update accordingly. The color should stay unchanged (since, for pure white and black, changing H and S values doesn't make a difference). TheonChange
function should not fire multiple times either, since the resulting color is not changing.onChange
callback should be fired as expected.Screenshots or screencast
,
Trunk
Kapture.2023-12-22.at.11.31.40.mp4
This PR
Kapture.2024-01-04.at.23.46.47.mp4