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. |
aaronrobertshaw
left a comment
There was a problem hiding this comment.
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:
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.
aaronrobertshaw
left a comment
There was a problem hiding this comment.
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.jsfiles 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 --