DataViews/Font Library: Give search fields a fixed width to stop layout shift - #80315
Conversation
|
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: +179 B (0%) Total Size: 7.73 MB 📦 View Changed
|
aduth
left a comment
There was a problem hiding this comment.
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?
|
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? |
|
Thanks for looking into this 🙏
@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.
@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.
^ 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. |
|
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? |
|
My first question would be whether this is really something that should be addressed in 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 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 |
|
Thanks for catching all these layout shifts by the way! Good to see these rough edges being polished. |
|
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 |
|
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 |
# Conflicts: # packages/components/CHANGELOG.md
|
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:
The delay you mentioned in your previous comment should be unrelated to this fix, we can probably investigate that separately. |
|
Flaky tests detected in 3de7116. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/29566420105
|
| .dataviews-search { | ||
| width: fit-content; | ||
| // Fixed width to ensure the control doesn't resize with the reset button. | ||
| width: 210px; |
There was a problem hiding this comment.
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;
}There was a problem hiding this comment.
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.
There was a problem hiding this comment.
No strong opinion! The CSS architecture doesn't seem particularly clear in here to begin with.
|
Thank you all! Merging to fix the layout shift issue. |



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 anySearchControlin 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. Usingvisibility: hiddenalso 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