-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
fix: Outline selected blocks with a single border #59415
fix: Outline selected blocks with a single border #59415
Conversation
This mirrors the web editor's behavior, which relies upon a CSS selector of non-`contenteditable` blocks for applying the outline.
The Spacer block includes it own selected outline.
The Spacer block does not house a rich text field, but still should not have an outline.
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: +757 B (0%) Total Size: 1.71 MB
ℹ️ View Unchanged
|
Additional logic is required to selectively highlight blocks that appear in the root list.
Deeply nested tests are difficult to comprehend and the selected state is fairly top-level, so testing each block by its selection feels like unnecessary complexity.
Reduce complexity by reducing the length of the logic and negate the need for tracking the root list property. This also avoids media category blocks rendering an duplicative border atop each media block's self-provided border.
These media blocks differ from the other media blocks who provide their own outline.
The Cover block provides its own outline style.
The proposed changes now address issues outside the design block category.
const shoudlShowOutline = | ||
isSelected && | ||
( ( hasBlockTextCategory && hasInnerBlocks ) || | ||
( ! hasBlockTextCategory && hasInnerBlocks ) || | ||
( ! hasBlockTextCategory && isRootList ) || | ||
socialBlockWithOutline || | ||
textBlockWithOutline ); | ||
|
||
return ( | ||
shoudlShowOutline && ( | ||
<View pointerEvents="box-none" style={ styleSolidBorder } /> | ||
) | ||
); |
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.
While I started out addressing #59380, I encountered additional block outline oddities along the way during testing. That led me to consider refactoring this code further to address an oddity — specifically, 7fc46d6.
Ultimately, I began refactoring the entirety of this logic in ef94d34 in an effort to reduce its complexity. Further refactors and fixes followed. The final form can be seen here in the pull request diff.
Obviously, complexity is somewhat subjective. So, I welcome feedback on the current approach and whether we should/prefer to reinstate any of the original code structure. The automated tests should help with any future refactors.
@geriux I'd like to request your review specifically as one of the original authors of this code. 🙇🏻
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! Thank you for improving the logic and for adding tests. These will be super helpful whenever we need to tweak the BlockOutline component.
Should we open a Gutenberg Mobile PR to run the full E2E tests? I'm not sure if we will need to update some snapshots or not.
That is a good thought. I will open a Gutenberg Mobile PR to avoid any unexpected breakages before merging this PR. |
What?
Outline "design" category blocks (Groups) when selected, if the block is not a rich text block, e.g., Button. Additionally, avoid duplicative outlines for blocks that provide their own border (Image, Cover, Spacer).
Why?
Fixes #59380. Mirror the web editor for a consistent UX and avoid user confusion as to which block is currently selected.
How?
Add additional logic selectively enabling the outline for "design" category blocks that do not house rich text inputs.
Testing Instructions
Perform the following for both the grouped and un-grouped initial HTML examples provide below.
Un-grouped
Grouped
Testing Instructions for Keyboard
N/A, proposed changes only impact visual styling.
Screenshots or screencast
Not provided.