Skip to content

DataViews/Font Library: Give search fields a fixed width to stop layout shift - #80315

Merged
juanfra merged 7 commits into
trunkfrom
fix/search-control-suffix-width-issue
Jul 21, 2026
Merged

DataViews/Font Library: Give search fields a fixed width to stop layout shift#80315
juanfra merged 7 commits into
trunkfrom
fix/search-control-suffix-width-issue

Conversation

@juanfra

@juanfra juanfra commented Jul 15, 2026

Copy link
Copy Markdown
Member

What?

Fixes a layout shift in SearchControl where the input width would change when the reset button appeared or disappeared. It's not noticeable when the input is taking the full width.

Can be clearly seen in the "Install fonts" screen, or the patterns screen in the site editor but affects any SearchControl in an auto width layout (I saw it a few times with dataviews)

Update: Updated the PR title and the changes to better reflect the changes. The PR fixes a layout shift in SearchControl where the input width would change when the reset button appeared or disappeared. We're changing the consumers (Dataviews, font library) to have a width and avoid the layout shift.

Why?

The reset button was only mounted when a value was entered, so in certain scenarios typing into the search field made the control grow, and clearing it made it shrink back.

The layout shift makes the search look unpolished.

How?

The reset button suffix is now always mounted, and what changes is the visibility instead of unmounting. This reserves the space and avoids the width change. Using visibility: hidden also keeps it out of the tab order and accessibility tree, so existing behavior is unaffected.

Update: moved this to the consumer level instead, after discussion below. The two spots that actually showed the bug (The ones I could identify: DataViews search styles, and font-library) get a fixed width, so the box stops resizing without SearchControl having to reserve space for the button.

Testing Instructions

  1. Go to Appearance > Fonts > Install Fonts (authorize google fonts if necessary)
  2. Type something into the "Font name..." search input and confirm the input doesn't change width when the X button shows.
  3. Remove what's in the input confirm it doesn't change the width.
  4. Open a DataViews screen (e.g. Pages/Templates/Patterns in the Site Editor), type into the search field and confirm the same, no width change.

@juanfra
juanfra requested a review from ajitbohra as a code owner July 15, 2026 13:04
@juanfra juanfra added the [Type] Enhancement A suggestion for improvement. label Jul 15, 2026
@juanfra
juanfra requested a review from a team as a code owner July 15, 2026 13:05
@juanfra juanfra added the [Package] Components /packages/components label Jul 15, 2026
@github-actions

github-actions Bot commented Jul 15, 2026

Copy link
Copy Markdown

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: juanfra <juanfra@git.wordpress.org>
Co-authored-by: aduth <aduth@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: fcoveram <fcoveram@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

github-actions Bot commented Jul 15, 2026

Copy link
Copy Markdown

Size Change: +179 B (0%)

Total Size: 7.73 MB

📦 View Changed
Filename Size Change
build/scripts/editor/index.min.js 499 kB +3 B (0%)
build/styles/edit-site/style-rtl.css 21.4 kB +23 B (+0.11%)
build/styles/edit-site/style-rtl.min.css 17.5 kB +23 B (+0.13%)
build/styles/edit-site/style.css 21.4 kB +24 B (+0.11%)
build/styles/edit-site/style.min.css 17.5 kB +24 B (+0.14%)
build/styles/editor/style-rtl.css 31.3 kB +23 B (+0.07%)
build/styles/editor/style-rtl.min.css 26.6 kB +19 B (+0.07%)
build/styles/editor/style.css 31.3 kB +19 B (+0.06%)
build/styles/editor/style.min.css 26.6 kB +21 B (+0.08%)

compressed-size-action

@aduth aduth left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this makes sense 👍 I wondered if we could do this with some better flex styling, but I suppose the challenge is that some of these text inputs have unassigned width so we can't always necessarily know the extent of the width that it might be shown as.

On the implementation itself, I'd be curious for @mirka 's thoughts as the resident expert on the form controls suffixing and prefixing. At the very least, I think we might want to avoid introducing a new Emotion-styled component, as we've documented that "new Emotion usage should not be added". Maybe it's enough to just pass a style prop with conditional visibility directly to the existing InputControlSuffixWrapper , and skip the new component?

@ciampo

ciampo commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

can we also get a screenshot of what the input looks like with a long string of text, colliding with the hidden search button? And also how that looks like when revealing the hidden button on top of the long string of text?

@ciampo
ciampo requested a review from a team July 15, 2026 13:51
@juanfra

juanfra commented Jul 15, 2026

Copy link
Copy Markdown
Member Author

Thanks for looking into this 🙏

At the very least, I think we might want to avoid introducing a new Emotion-styled component, as we've documented that "new Emotion usage should not be added". Maybe it's enough to just pass a style prop with conditional visibility directly to the existing InputControlSuffixWrapper , and skip the new component?

@aduth sure thing! I missed the styling section. Actually my first attempt was to have inline styles, but then I saw we were using emotions in other spots and tried to make it consistent with that. I pushed the changes here.

can we also get a screenshot of what the input looks like with a long string of text, colliding with the hidden search button? And also how that looks like when revealing the hidden button on top of the long string of text?

@ciampo when the input has a value the reset icon is shown. So when there's content, the "X" icon will be visible. The scenario you're describing could be a possibility with long placeholders.

Before After
Screenshot 2026-07-15 at 16 37 45 Screenshot 2026-07-15 at 16 30 39

^ This mockup is having the following placeholder: "This is how it looks with long placeholders". I believe this fix is more likely fixing scenarios where the searchcontrol wasn't super wide, my assumption is that long placeholders wouldn't work there either. But it's true that there's a white space at the end.

@ciampo

ciampo commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Could we tweak the width of the underlying input so that, when the input is empty (and the close button is hidden), the input spans the whole width?

@mirka

mirka commented Jul 15, 2026

Copy link
Copy Markdown
Member

My first question would be whether this is really something that should be addressed in SearchControl itself, or something that's actually fine (or better) to be addressed at the consumer level.

From a certain standpoint, if the consumer put the component in a flex layout and they care about getting that component's width to behave a certain way, they can add those constraints themselves (in this case, by putting a width or flex-basis on the SearchControl).

I'm leaning towards addressing it in the consumer, unless this is a really common pattern (which may tip the scale in favor of ergonomics). The current complexity for addressing it in the SearchControl doesn't seem too bad, but the placeholder collision is a non-negligible downside.

@mirka

mirka commented Jul 15, 2026

Copy link
Copy Markdown
Member

Thanks for catching all these layout shifts by the way! Good to see these rough edges being polished.

@fcoveram

Copy link
Copy Markdown
Contributor

I just tested and the layout and interaction looks correct to me

CleanShot 2026-07-16 at 10 17 15

I only noticed a small delay when after triggering the clear action that looks like a blink of the focus ring before deleting the text typed.

@juanfra

juanfra commented Jul 16, 2026

Copy link
Copy Markdown
Member Author

Thanks a lot for the reviews!

If the placeholder issue is non-negotiable, moving the fix to the clients means using arbitrary widths, can't think of other way around it. The main places this bug shows up are dataviews (several screens) and the install fonts screen. If we go with arbitrary widths we could try using some design tokens. Would look different than what it looks now, but maybe it's worth considering.

Separately, found a pre existing issue in SearchControl. The right padding for the input is set to 4px whenever a suffix is passed, regardless of whether it's actually visible. So a long placeholder with no button showing looks cramped on the right vs. the padding left on the icon (not the button but the search icon in this case). Will open a separate PR for that one.

@mirka

mirka commented Jul 16, 2026

Copy link
Copy Markdown
Member

No strong opinion on whether a width token is necessary, but I think setting an appropriate width constraint based on the the given layout is a good idea to begin with in these flex layouts, regardless of the clear button issue.

The idea holds even if we were talking about a plain input field inside a space-between container, instead of a search field. There's no intentionality to the default width a raw input element takes anyway. The consumer can (should?) set an appropriate default width based on the use case.

@github-actions github-actions Bot added [Package] DataViews /packages/dataviews and removed [Package] Components /packages/components labels Jul 17, 2026
@juanfra juanfra changed the title SearchControl: Reserve space for reset button to prevent width change DataViews/Font Library: Give search fields a fixed width to stop layout shift Jul 17, 2026
@juanfra

juanfra commented Jul 17, 2026

Copy link
Copy Markdown
Member Author

Thanks! Going with this then. I updated the PR title and description to better reflect what we're finally doing here. Regarding the fix, picked values that are close to what was already rendering there, so it shouldn't look really different, just stop resizing.

@fcoveram could you please re-check this and confirm the sizes are good? 🙏 The best way to test this out would be:

  1. Go to Appearance > Fonts > Install Fonts (authorize google fonts if necessary)
  2. Type something into the "Font name..." search input and confirm the input doesn't change width when the X button shows.
  3. Remove what's in the input confirm it doesn't change the width.
  4. Open a DataViews screen (e.g. Pages/Templates/Patterns in the Site Editor), type into the search field and confirm the same, no width change.

The delay you mentioned in your previous comment should be unrelated to this fix, we can probably investigate that separately.

@github-actions

Copy link
Copy Markdown

Flaky tests detected in 3de7116.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/29566420105
📝 Reported issues:

@mirka mirka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the improvement!

.dataviews-search {
width: fit-content;
// Fixed width to ensure the control doesn't resize with the reset button.
width: 210px;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

flex-basis might be better here so the field can still shrink down.

.dataviews-search {
	// Fixed width to ensure the control doesn't resize with the reset button.
	flex-basis: 210px;
}

// I don't know where this class lives, just putting it here for demonstration purposes
.dataviews__search {
	flex-grow: 1;
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Makes sense, thanks! Missed that you hinted this above.

Any preference on where to locate .dataviews__search?

Given this, I feel packages/dataviews/src/dataviews/style.scss would be the most appropriate. But want to double check before pushing to avoid back and forth.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No strong opinion! The CSS architecture doesn't seem particularly clear in here to begin with.

@juanfra
juanfra merged commit 25d5c72 into trunk Jul 21, 2026
59 checks passed
@juanfra
juanfra deleted the fix/search-control-suffix-width-issue branch July 21, 2026 10:08
@github-actions github-actions Bot added this to the Gutenberg 23.7 milestone Jul 21, 2026
@juanfra

juanfra commented Jul 21, 2026

Copy link
Copy Markdown
Member Author

Thank you all! Merging to fix the layout shift issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] DataViews /packages/dataviews [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

Sponsor
SponsoredKunjungi sekarang
Promo