-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Add reset button to color control #67116
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: +222 B (+0.01%) Total Size: 1.83 MB
ℹ️ View Unchanged
|
I tested this PR in the Gutenberg PR reviewer, and it works perfectly, resetting the color with a single click. I’ve also attached a video of the testing process below for reference. 67116.mp4 |
This feels like a good ergonomic addition. However I wonder if this reset button shouldn't be part of the ItemGroup component itself, rather than a separate piece like this. CC: @WordPress/gutenberg-components |
Eventually yes I think so; #64445. |
@jasmussen @jameskoster should we move forward with this improvement and then eventually implement the changes in the component? |
Component first or this use case first, I'm personally okay either way. Though I'd love a components-group chime in just to be sure we aren't building up drift. |
I'd lean on going use-case first, and then we can always add it as an API to the |
packages/block-editor/src/components/colors-gradients/style.scss
Outdated
Show resolved
Hide resolved
packages/block-editor/src/components/colors-gradients/style.scss
Outdated
Show resolved
Hide resolved
right: 0; | ||
top: 0; | ||
bottom: 0; | ||
opacity: 0; |
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.
Can we confirm that it's better if the button is hidden by default?
I'm having second thoughts if this is good for discovery. A user might be wondering how to reset the color and wouldn't know unless they hover on the tools panel item.
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.
The intention was to show the reset button only on hover or focus, making it easier to reset colors with fewer clicks.
From my perspective, showing the button on hover is a subtle and unobtrusive way to achieve this without adding visual clutter to the UI. As for discoverability, I think users will naturally figure it out when they try resetting colors the usual way, which should be sufficient.
packages/block-editor/src/components/colors-gradients/style.scss
Outdated
Show resolved
Hide resolved
packages/block-editor/src/components/global-styles/color-panel.js
Outdated
Show resolved
Hide resolved
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.
From an accessibility perspective, it's important that focus shouldn't be lost. Currently in this PR, the reset button is conditionally rendered, so focus is lost when the reset button is pressed:
339d87eef495bf9206bbd9f4c60f27c2.mp4
- If we always want the reset button to be visible: I think we need the
accessibleWhenDisabled
prop because we would expect the reset button to be disabled when we press it. - If we conditionally render the reset button: When we press the reset button, we probably want to return focus to the color control.
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.
Thanks for addressing the feedback @juanfra 👍
There are a few minor issues to be addressed before this one is ready to be shipped.
packages/block-editor/src/components/global-styles/color-panel.js
Outdated
Show resolved
Hide resolved
packages/block-editor/src/components/global-styles/color-panel.js
Outdated
Show resolved
Hide resolved
packages/block-editor/src/components/global-styles/color-panel.js
Outdated
Show resolved
Hide resolved
packages/block-editor/src/components/global-styles/color-panel.js
Outdated
Show resolved
Hide resolved
packages/block-editor/src/components/global-styles/color-panel.js
Outdated
Show resolved
Hide resolved
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.
Thanks for the update! I've confirmed that the focus is never lost.
Below are my two suggestions, but I think they are not blockers and can be addressed with follow-up.
Apply focus styling like the palette edit component, i.e. make the buttons 24px in size:
This PR | PaletteEdit component |
---|---|
We might also need a similar reset button for the ColorGradientSettingsDropdown
component. For example, the Social Icons block supports two custom colors: Icon color and Icon background;
packages/block-editor/src/components/global-styles/color-panel.js
Outdated
Show resolved
Hide resolved
Thank you all for the reviews ✨
I had to update some styles to make it work. I also removed the border-radius of that button because by default it was having a mix, let me know if you prefer keeping that.
I can try to work on that in the coming weeks.
I went in this direction. |
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.
Thanks for the PR! I would be happy if we could improve the code a bit more before shipping this PR.
packages/block-editor/src/components/colors-gradients/style.scss
Outdated
Show resolved
Hide resolved
packages/block-editor/src/components/global-styles/color-panel.js
Outdated
Show resolved
Hide resolved
packages/block-editor/src/components/colors-gradients/style.scss
Outdated
Show resolved
Hide resolved
I've also applied the same style to the remove button in the Shadow panel as in this PR: #67705 |
Thank you! I've applied the suggestions. |
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.
LGTM! Styles, focus management, screen reader reading - everything works correctly 👍
50ce6ac552f08d051a00d459ca378851.mp4
Thank you all! |
Congrats, this is an impactful one! |
Will this same reset icon/pattern be used in other places? The whole editor could use more consistent reset controls: |
@cbirdsong I think adding a consistent reset pattern for the whole editor is out of the scope of this issue and will need to be discussed separately. However, a similar reset pattern will be added for color-related dropdowns in #67800. |
* Add reset button to color control * Apply suggestions from code review. * Keep focus on the toggle button when hitting reset. * Apply suggestions from code review. * Add `exact` to specify which element to resolve. * Apply suggestions from code review. * Remove inclusion of `sprintf` Co-authored-by: juanfra <[email protected]> Co-authored-by: tyxla <[email protected]> Co-authored-by: t-hamano <[email protected]> Co-authored-by: mirka <[email protected]> Co-authored-by: ciampo <[email protected]> Co-authored-by: dhruvang21 <[email protected]> Co-authored-by: jasmussen <[email protected]> Co-authored-by: jameskoster <[email protected]>
What?
Add an inline reset button to the color control, shown on hover/focus, if there's a value. Picked changes from this PR with a few tweaks. The original PR was closed as stale, but I believe this is a nice improvement that will improve the overall experience for creators.
Props @kevin940726
Why?
To make it easier to reset a color selection, reduce the number of clicks as it doesn't require opening the color options panel.
Fixes #41866
How?
Adding a button if there's a color value, and adjusting the CSS so that it looks like the proposed designs.
Testing Instructions
Screenshots or screencast
Screen.Recording.2024-11-19.at.15.16.09.mov