-
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
Border panel: Don't restore deselected border color when width changed from zero #37049
Border panel: Don't restore deselected border color when width changed from zero #37049
Conversation
Size Change: -17 B (0%) Total Size: 1.11 MB
ℹ️ View Unchanged
|
Pinging @aaronrobertshaw to make sure I didn't break your implementation or misunderstand the original requirements 😄 I traced the discussion around setting zero width in #32080. |
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 fix @stacimc 👍
make sure I didn't break your implementation or misunderstand the original requirements 😄 I traced the discussion around setting zero width in #32080.
I think the restoration of any previous color selection was aimed around needing to have some color set when re-establishing a border so there was a visual border. What the original intent was doesn't matter much here though.
With the recent changes applying fallbacks via CSS :where
for border-style
whenever a width or color are selected, the current behaviour doesn't make much sense.
In case it interests you can follow the original discussion a little further back via:
- Block Support: Update border support UI #31585
- Refine border control panel with design tools #31337
- Image: Add border block support for color, width, and style #31366 (review)
This tests as advertised for me 👌
I've left a few minor comments as I think we could minimise the changes here to achieve the same result as well as remove some nested conditionals. Below is a patch in line with those comments and after applying, this still tests well with the PR's test instructions.
I'll leave the final call to you.
Patch for possible refinements
diff --git a/packages/block-editor/src/hooks/border-width.js b/packages/block-editor/src/hooks/border-width.js
index 8c7338c152..f2edd7089e 100644
--- a/packages/block-editor/src/hooks/border-width.js
+++ b/packages/block-editor/src/hooks/border-width.js
@@ -62,9 +62,7 @@ export const BorderWidthEdit = ( props ) => {
// changes to a non-zero value.
setColorSelection( borderColor );
setCustomColorSelection( customBorderColor );
- if ( borderStyle !== 'none' ) {
- setStyleSelection( borderStyle );
- }
+ setStyleSelection( borderStyle );
// Clear style and color attributes.
borderPaletteColor = undefined;
@@ -72,21 +70,19 @@ export const BorderWidthEdit = ( props ) => {
newStyle.border.style = 'none';
}
- if ( ! hasZeroWidth && hadPreviousZeroWidth ) {
- // Restore previous border style selection if width is now not zero and
- // border style was 'none'. This is to support changes to the UI which
- // change the border style UI to a segmented control without a "none"
- // option.
- if ( borderStyle === 'none' ) {
- newStyle.border.style = styleSelection;
- }
-
- // Restore previous border color selection if width is no longer zero
- // and current border color is undefined.
- if ( borderColor === undefined ) {
- borderPaletteColor = colorSelection;
- newStyle.border.color = customColorSelection;
- }
+ // Restore previous border style selection if width is now not zero and
+ // border style was 'none'. This is to support changes to the UI which
+ // change the border style UI to a segmented control without a "none"
+ // option.
+ if ( ! hasZeroWidth && borderStyle === 'none' ) {
+ newStyle.border.style = styleSelection;
+ }
+
+ // Restore previous border color selection if width is no longer zero
+ // and current border color is undefined.
+ if ( ! hasZeroWidth && borderColor === undefined ) {
+ borderPaletteColor = colorSelection;
+ newStyle.border.color = customColorSelection;
}
// If width was reset, clean out undefined styles.
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've given this another test and it is working well.
LGTM 🚢
The failing e2es and PHP unit tests appear unrelated. They are being addressed elsewhere so this should be right to merge soon.
If you deselect a color value before setting the width to zero, when the width is changed to a non-zero value that color should not be restored (because it was explicitly deselected). This was happening because the state that tracked previous values would not update when the value was set to undefined.
54a944f
to
639a146
Compare
Fixes #37046
Description
When border width is set to zero, any selections for the color and style controls should be cleared -- and then restored if the width value is updated to a non-zero value. This PR fixes an issue where previously selected colors were being restored even if the user had explicitly deselected them.
How has this been tested?
Verify that the normal use case is still working:
Screenshots
Types of changes
Checklist:
*.native.js
files for terms that need renaming or removal). <!-- React Native mobile Gutenberg guidelines: https://github.com/WordPress/gutenberg/blob/HEAD/docs/contributors/code/native-mobile.md --