Skip to content
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

Block inserter: Improve alignment of block inserter search and close icons #50439

Merged

Conversation

juanfra
Copy link
Member

@juanfra juanfra commented May 8, 2023

What?

Improve alignment of block inserter search and close icons.

Fixes: #49756

Why?

When using the block inserter search and clearing the search it's pretty much noticeable that the icons are not aligned and it creates a strange experience.

Testing Instructions

  1. Open a post or page.
  2. Open the block inserter, and check the search icon position.
  3. Type in your search, and confirm that the search and close icons are aligned.

Screenshots or screencast

Screen.Recording.2023-05-08.at.18.14.18.mov

@juanfra juanfra requested a review from ellatrix as a code owner May 8, 2023 16:19
@juanfra juanfra added [Type] Enhancement A suggestion for improvement. [Feature] Inserter The main way to insert blocks using the + button in the editing interface labels May 22, 2023
@juanfra juanfra self-assigned this May 22, 2023
@juanfra juanfra requested a review from richtabor May 22, 2023 09:01
@richtabor richtabor requested a review from a team May 22, 2023 19:23
@jasmussen
Copy link
Contributor

Seems good to me, thanks for the PR, happy to approve. Just a quick ping by @ciampo in case there's a better way.

Copy link
Contributor

@ciampo ciampo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @juanfra for working on this, and thank you for the ping, @jasmussen !

The currently proposed solution has a few issues:

  • the bug that we're trying to solve affects the SearchControl component, and not just this specific instance in the block inserter. We should therefore apply a solution to the component directly if possible.
  • we should not be using .components-* class names for style overrides, especially outside the @wordpress/components package
  • in general, we should avoid style overrides when possible (like the padding rule here), since they make the UI much more prone to breakage any time there's a change upstream
  • changing the min-width also affect the focus style of the close icon button:
trunk this PR
Screenshot 2023-05-24 at 09 38 11 Screenshot 2023-05-24 at 09 37 04

A better solution could be to:

  • apply a fix directly to SearchControl
  • centering the search button via flex layout, regardless of the button's width and padding (thus avoiding style overrides on the button component)
Here's how those code changes would look like
diff --git a/packages/block-editor/src/components/inserter/style.scss b/packages/block-editor/src/components/inserter/style.scss
index 5579e17bc9..d6cf148724 100644
--- a/packages/block-editor/src/components/inserter/style.scss
+++ b/packages/block-editor/src/components/inserter/style.scss
@@ -109,11 +109,6 @@ $block-inserter-tabs-height: 44px;
 
 	.components-search-control__icon {
 		right: $grid-unit-10 + ($grid-unit-60 - $icon-size) * 0.5;
-
-		.components-button.has-icon {
-			min-width: initial;
-			padding: 0;
-		}
 	}
 }
 
diff --git a/packages/components/src/search-control/style.scss b/packages/components/src/search-control/style.scss
index c02250de4f..5acc4fcc24 100644
--- a/packages/components/src/search-control/style.scss
+++ b/packages/components/src/search-control/style.scss
@@ -43,8 +43,10 @@
 	top: 0;
 	right: ( $grid-unit-60 - $icon-size ) * 0.5;
 	bottom: 0;
+	width: $icon-size;
 	display: flex;
 	align-items: center;
+	justify-content: center;
 
 	> svg {
 		margin: $grid-unit-10 0;

@juanfra juanfra requested a review from ajitbohra as a code owner May 24, 2023 09:49
@juanfra
Copy link
Member Author

juanfra commented May 24, 2023

Thanks @ciampo for the thoughtful review. I'm new to the codebase, this is really helpful. I've adjusted the PR to address the changes with the proposed approach.

@juanfra juanfra requested a review from ciampo May 24, 2023 09:51
Copy link
Contributor

@ciampo ciampo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ciampo for the thoughtful review. I'm new to the codebase, this is really helpful. I've adjusted the PR to address the changes with the proposed approach.

Thank you, @juanfra ! It's my pleasure to help — feel free to ping me again next time you need a review, especially if related to the editor's UI and @wordpress/components specifically.

Before merging, could you also add an entry to the CHANGELOG, under the "Bug Fix" sub-section?

Otherwise, code changes LGTM 🚀

@ciampo
Copy link
Contributor

ciampo commented May 24, 2023

Thank you! Will merge once all checks have passed.

@chad1008 you may want to take a look into the CI failure for the CHANGELOG check — the task is having some issues fetching trunk, it may have to do with the fact that this PR originates from a fork of the repo?

@ciampo ciampo enabled auto-merge (squash) May 24, 2023 14:06
@juanfra
Copy link
Member Author

juanfra commented May 24, 2023

Grazie a te, Marco! I appreciate it 😄

@ciampo
Copy link
Contributor

ciampo commented May 24, 2023

Es un placer!

@chad1008
Copy link
Contributor

you may want to take a look into the CI failure for the CHANGELOG check — the task is having some issues fetching trunk, it may have to do with the fact that this PR originates from a fork of the repo?

Thanks for the ping. I'll take a look! Forked repos should be fine, as we fixed that a while back, but I'll look into what's happening here. Maybe there's something more that needs to be added to cover all forks.

@ciampo ciampo merged commit 487104b into WordPress:trunk May 24, 2023
@github-actions github-actions bot added this to the Gutenberg 15.9 milestone May 24, 2023
@juanfra juanfra deleted the fix/49756-fix-alignment-icons-inserter branch May 24, 2023 14:38
@chad1008
Copy link
Contributor

🤔 I'm not sure why the CI check wasn't able to properly fetch trunk here. I've tested from a fork of my own with no issues. I also looked through a handful of other Components-related PRs from forked repos, and they similarly appear to be running without issue. It looks like this was either an odd edge case that we'll need more examples of try and find a pattern, or perhaps something unique to this fork/PR.

@juanfra, please do let me know if you see any more fatal: couldn't find remote ref trunk failures on this check. Happy to dig in more if it becomes a pattern!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Inserter The main way to insert blocks using the + button in the editing interface [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve alignment of block inserter search and close icons
4 participants