Skip to content

Tooltip: Limit the popup width and wrap long words - #87918

Merged
ciampo merged 4 commits into
trunkfrom
fix/ui-tooltip-max-width
Dec 3, 2026
Merged

ciampo merged 4 commits into
trunkfrom
fix/ui-tooltip-max-width

Conversation

@ciampo

@ciampo ciampo commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

What?

Follow-up to #86732.

Limits the @wordpress/ui Tooltip popup to 240px, or to the space left in the viewport when that is less, and wraps long words.

Why?

A tooltip was as wide as its text. In the Selecting Local Files pattern from #86732, a remove button named after a long filename widened the page to 452px at a 320px viewport. In a right-to-left layout, the same tooltip ran off the screen edge, and part of its text could not be seen. Production tooltips show the same kind of text, such as the filename tooltip in media-fields and truncated Breadcrumb items.

How?

Two rules on Tooltip.Popup:

  • max-width: min(var(--available-width), var(--wpds-dimension-surface-width-xs)). Base UI sets --available-width on the positioner: the space between the trigger and the viewport edge, less the collision padding. Menu and the shared item popup already limit their width this way.
  • overflow-wrap: anywhere, so a word with no break opportunity, such as a filename with underscores, wraps instead of overflowing.

Tooltips longer than about 40 characters now wrap at 240px. A side="left" or side="right" tooltip next to the viewport edge can get narrow, as Menu already does.

Alternatives measured in Chromium
Option 320px viewport, long filename A 112-character sentence at 1280px
Trunk Page widens to 452px One 650px line
Wrap only Still overflows by 5px: the popup fills the viewport, then Base UI moves it in by the collision padding 650px
Width cap only An unbroken word spills out of the box and widens the page 240px
Cap and overflow-wrap: break-word Fits only while the viewport is wider than the cap plus the padding 240px
--available-width and wrap, no cap Fits 650px
This PR Fits 240px

Fixing it in each consumer does not work: IconButton renders its own Tooltip.Popup and exposes only the positioner slot, so callers cannot style the popup.

Testing Instructions

  1. In Storybook, open the "Drop area for several files" example on its own: iframe.html?id=design-system-patterns-file-picker-multiple--choose-files&viewMode=story. It is also on the Design System → Patterns → Selecting Local Files page. Make the window about 320px wide.
  2. Choose a file with a long name and no spaces, such as quarterly_financial_report_final_version_reviewed_and_approved_2026.pdf.
  3. Hover the remove button.
    • On trunk, the tooltip is one long line and the page scrolls sideways.
    • With this PR, the tooltip wraps inside the viewport and the page does not scroll sideways.
  4. Add &globals=direction:rtl to the URL and repeat. On trunk, the tooltip runs off the right edge and its start is cut off. With this PR, it wraps inside the viewport.
  5. Widen the window and hover the remove button again. The tooltip wraps at 240px.
  6. Open Components → @wordpress-ui → Tooltip → Default and hover the button. The short "Save" tooltip looks the same as on trunk.

Testing Instructions for Keyboard

In step 3, press Tab until the remove button has focus. The tooltip opens and wraps the same way.

Screenshots or screencast

Storybook, File Picker Multiple, at 320px. The trunk image is as wide as the page became.

Before After
On trunk at 320px, the remove button tooltip is one 447px line that extends past the 320px viewport With this PR at 320px, the tooltip wraps over three lines, 240px wide, inside the viewport

The same story in right-to-left at 320px:

Before After
On trunk in right-to-left, the tooltip runs off the right edge, cutting off the word Remove and the end of the filename With this PR in right-to-left, the tooltip wraps over three lines inside the viewport, aligned to the right
Desktop width and short labels

File Picker Multiple at 1280px, cropped to the right 720px:

Before After
On trunk at 1280px, the remove button tooltip is one 496px line With this PR at 1280px, the tooltip wraps over three lines at 240px

Tooltip, Default story, at 1280px:

Before After
On trunk, the Save tooltip is 45px wide With this PR, the Save tooltip is unchanged at 45px

Use of AI Tools

Claude Code (Claude Opus 5.5) compared the options, wrote the change and its browser tests, and captured the screenshots.

🤖 Generated with Claude Code

ciampo and others added 2 commits December 3, 2026 18:08
A long label, such as a remove button named after a filename, made the
popup as wide as its text, so it widened the page at 320px.

Limit the popup to the extra small surface width and to the space Base UI
reports in `--available-width`, and wrap long words with
`overflow-wrap: anywhere`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the [Package] UI /packages/ui label Dec 3, 2026
@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground Preview in Storybook

🎉 Props

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: ciampo <mciampini@git.wordpress.org>
Co-authored-by: aduth <aduth@git.wordpress.org>

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


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

📦 Bundle size

Size Change: +381 B (0%)

Total Size: 8.86 MB

📦 View Changed
Filename Size Change
build/modules/boot/index.min.js 54.9 kB +31 B (+0.06%)
build/modules/core-fields/attachment.min.js 44 kB +38 B (+0.09%)
build/modules/core-fields/wp_block.min.js 32.6 kB +38 B (+0.12%)
build/modules/core-fields/wp_template_part.min.js 39.2 kB +39 B (+0.1%)
build/scripts/block-directory/index.min.js 42.3 kB +33 B (+0.08%)
build/scripts/block-editor/index.min.js 563 kB +15 B (0%)
build/scripts/block-library/index.min.js 434 kB +42 B (+0.01%)
build/scripts/components/index.min.js 358 kB +28 B (+0.01%)
build/scripts/edit-post/index.min.js 45.1 kB +41 B (+0.09%)
build/scripts/edit-site/index.min.js 377 kB +14 B (0%)
build/scripts/editor/index.min.js 579 kB +17 B (0%)
build/scripts/media-utils/index.min.js 235 kB +18 B (+0.01%)
build/scripts/notices/index.min.js 47.6 kB +27 B (+0.06%)

d3a1ee5 Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric a3f0643 trunk % Change
timeToFirstByte 59.8 ms +6.52% -3.09% 65.4 ms +4.82% -5.73% -8.56%
largestContentfulPaint 92 ms +6.52% -4.35% 98 ms +10.2% -2.04% -6.12%
lcpMinusTtfb 30.8 ms +11.85% -4.22% 36.15 ms +16.32% -16.04% -14.8%
wpBeforeTemplate 31.52 ms +10.5% -3.81% 32.46 ms +6.32% -2.5% -2.9%
wpTemplate 23.92 ms +3.55% -2.59% 26.46 ms +6.12% -2.46% -9.6%
wpTotal 55.74 ms +6.48% -3.3% 61.3 ms +4.55% -6% -9.07%
wpMemoryUsage 7.76 MB +0% -0% 7.72 MB +0% -0% 0.45%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric a3f0643 trunk % Change
timeToFirstByte 50.05 ms +7.59% -2.2% 53.45 ms +6.17% -3.37% -6.36%
largestContentfulPaint 88 ms +4.55% -0% 92 ms +0% -4.35% -4.35%
lcpMinusTtfb 38 ms +3.95% -1.05% 37.15 ms +4.85% -3.77% 2.29%
wpBeforeTemplate 28.83 ms +1.18% -2.15% 29.79 ms +14.4% -1.95% -3.22%
wpTemplate 18.01 ms +2.55% -4.83% 19.25 ms +7.69% -5.04% -6.44%
wpTotal 46.66 ms +4.65% -2.19% 50.07 ms +6.51% -3.54% -6.81%
wpMemoryUsage 6.47 MB +0% -0% 6.43 MB +0% -0% 0.55%
wpDbQueries 13 +0% -0% 13 +0% -0% 0%

media-processing

Metric a3f0643 trunk % Change
mediaProcessingJpeg 403 ms +0.41% -0.29% 408.19 ms +1.55% -1.11% -1.27%
mediaProcessingAvif 6220.64 ms +0.18% -0.96% 6168.89 ms +0.42% -0.53% 0.84%
mediaProcessingJpegToAvif 4285.82 ms +0.17% -0.5% 4247.77 ms +0.66% -0.09% 0.9%

media-upload

Metric a3f0643 trunk % Change
jpegUploadProcessing 1982.87 ms +3.68% -2.24% 1501.45 ms +2.34% -0.68% 32.06%
pngUploadProcessing 277.17 ms +2.3% -3.39% 281.91 ms +0.57% -4.15% -1.68%
largeJpegUploadProcessing 1524.72 ms +27.94% -1.26% 1539.96 ms +29.23% -2.37% -0.99%
multipleImageUploadProcessing 2143.5 ms +2.36% -5.94% 2118.57 ms +1.1% -0.7% 1.18%

post-editor

Metric a3f0643 trunk % Change
serverResponse 335.32 ms +3.57% -10.02% 329.17 ms +0.97% -9.97% 1.87%
firstPaint 364.71 ms +7.77% -2.04% 351.14 ms +2.24% -9.79% 3.86%
domContentLoaded 674.94 ms +2.4% -4.14% 645.95 ms +1.63% -0.89% 4.49%
loaded 676.2 ms +2.4% -4.16% 647.07 ms +1.63% -0.9% 4.5%
firstContentfulPaint 377.15 ms +5.26% -4.37% 367.35 ms +1.52% -4.27% 2.67%
firstBlock 1811.03 ms +9.24% -2.94% 1749.99 ms +0.86% -2.05% 3.49%
type 16.21 ms +1.67% -10.24% 15.08 ms +2.52% -15.19% 7.49%
typeWithoutInspector 15.58 ms +12.84% -6.23% 14.41 ms +5.27% -8.54% 8.12%
typeWithTopToolbar 20.35 ms +7.03% -8.7% 18.8 ms +2.93% -2.34% 8.24%
typeContainer 6.97 ms +4.73% -10.62% 7.3 ms +2.6% -10.82% -4.52%
focus 87.58 ms +10.36% -8.52% 83.92 ms +8.32% -5.54% 4.36%
firstFocus 227.55 ms +0% -0% 203.94 ms +0% -0% 11.58%
selectAll 316.03 ms +0.26% -2.42% 303.28 ms +0.07% -1.13% 4.2%
undo 26.76 ms +4.19% -6.2% 24.81 ms +4.19% -5.16% 7.86%
listViewOpen 34.24 ms +9% -8.12% 32.54 ms +5.32% -12.26% 5.22%
inserterOpen 32.79 ms +1.46% -5.49% 31.8 ms +7.3% -1.35% 3.11%
inserterHover 9.97 ms +6.42% -13.54% 9.28 ms +11.42% -8.3% 7.44%
inserterSearch 7.16 ms +1.54% -6.42% 6.67 ms +6.15% -1.35% 7.35%
loadPatterns 521.94 ms +2.96% -1.56% 511.46 ms +0.52% -4.26% 2.05%
wpTotal 326.7 ms +3.64% -10.38% 320.57 ms +0.78% -10.23% 1.91%
wpMemoryUsage 14.86 MB +0% -0% 14.82 MB +0% -0% 0.25%
wpDbQueries 55 +0% -0% 55 +0% -0% 0%

site-editor

Metric a3f0643 trunk % Change
serverResponse 312.46 ms +0.74% -10.47% 297.78 ms +5.11% -5.61% 4.93%
firstPaint 367.57 ms +11.45% -4.29% 364.09 ms +1.61% -5.8% 0.96%
domContentLoaded 665.07 ms +4.58% -1.71% 652.61 ms +1.08% -0.48% 1.91%
loaded 665.99 ms +4.58% -1.7% 653.61 ms +1.08% -0.49% 1.89%
firstContentfulPaint 388.85 ms +5.35% -5.94% 368.1 ms +0.92% -1.46% 5.64%
firstBlock 2045.05 ms +6.36% -1.17% 2024.2 ms +1.17% -1.31% 1.03%
type 14.39 ms +4.03% -10.77% 14.13 ms +6.3% -11.39% 1.84%
navigate 91.27 ms +3.63% -6.14% 91.78 ms +8.49% -4.8% -0.56%
loadPatterns 1230.03 ms +2.37% -3.82% 1270.97 ms +3.25% -7.12% -3.22%
loadPages 1001.41 ms +0.41% -2.37% 997.1 ms +2.83% -0.48% 0.43%
wpTotal 304.15 ms +0.78% -10.76% 289.49 ms +5.26% -5.79% 5.06%
wpMemoryUsage 12.84 MB +0% -0% 12.80 MB +0% -0% 0.28%
wpDbQueries 45 +0% -0% 45 +0% -0% 0%

d3a1ee5 Run

🏁 Flaky tests

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.

chevron opens and closes submenu on touch devices in /test/e2e/specs/editor/blocks/navigation-frontend-interactivity.spec.js, passed after 1 failed attempt.
TimeoutError: locator.click: Timeout 10000ms exceeded.
Call log:
  - waiting for getByRole('button', { name: 'Submenu submenu' })
    - locator resolved to <button aria-expanded="false" aria-label="Submenu submenu" data-wp-on--click="actions.toggleMenuOnClick" data-wp-bind--aria-expanded="state.isSubmenuOpen" class="wp-block-navigation__submenu-icon wp-block-navigation-submenu__toggle">…</button>
  - attempting click action
    2 × waiting for element to be visible, enabled and stable
      - element is visible, enabled and stable
      - scrolling into view if needed
      - done scrolling
      - <a class="ab-item" role="menuitem" href="https://wordpress.org/">WordPress.org</a> from <div class="nojq" id="wpadminbar">…</div> subtree intercepts pointer events
    - retrying click action
    - waiting 20ms
    2 × waiting for element to be visible, enabled and stable
      - element is visible, enabled and stable
      - scrolling into view if needed
      - done scrolling
      - <a class="ab-item" role="menuitem" href="https://wordpress.org/">WordPress.org</a> from <div class="nojq" id="wpadminbar">…</div> subtree intercepts pointer events
    - retrying click action
      - waiting 100ms
    19 × waiting for element to be visible, enabled and stable
       - element is visible, enabled and stable
       - scrolling into view if needed
       - done scrolling
       - <a class="ab-item" role="menuitem" href="https://wordpress.org/">WordPress.org</a> from <div class="nojq" id="wpadminbar">…</div> subtree intercepts pointer events
     - retrying click action
       - waiting 500ms

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/navigation-frontend-interactivity.spec.js:948:23
returns focus to the item's Options after adding a submenu link in /test/e2e/specs/editor/blocks/navigation-list-view.spec.js, passed after 1 failed attempt.
Error: expect(locator).toBeFocused() failed

Locator: getByRole('treegrid', { name: 'Block navigation structure', description: 'Structure for navigation menu: Test Menu' }).getByRole('row', { name: 'Top Level Item 1' }).getByRole('button', { name: 'Options' })
Expected: focused
Timeout: 5000ms
Error: element(s) not found

Call log:
  - Expect "toBeFocused" getByRole('treegrid', { name: 'Block navigation structure', description: 'Structure for navigation menu: Test Menu' }).getByRole('row', { name: 'Top Level Item 1' }).getByRole('button', { name: 'Options' }) with timeout 5000ms
  - waiting for getByRole('treegrid', { name: 'Block navigation structure', description: 'Structure for navigation menu: Test Menu' }).getByRole('row', { name: 'Top Level Item 1' }).getByRole('button', { name: 'Options' })

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/navigation-list-view.spec.js:572:34
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/navigation-list-view.spec.js:566:3
should undo without broken temporary state in /test/e2e/specs/editor/blocks/image.spec.js, passed after 1 failed attempt.
Error: expect(received).toBe(expected) // Object.is equality

- Expected  - 2
+ Received  + 2

- <!-- wp:image -->
- <figure class="wp-block-image"><img alt=""/></figure>
+ <!-- wp:image {"id":24,"sizeSlug":"full","linkDestination":"none"} -->
+ <figure class="wp-block-image size-full"><img src="http://localhost:8891/wp-content/uploads/2026/12/0be76b8b-8ea7-4e37-9d77-0e6b4921c1b7.png" alt="" class="wp-image-24"/></figure>
  <!-- /wp:image -->
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/image.spec.js:432:49

d3a1ee5 Run

@ciampo ciampo self-assigned this Dec 3, 2026
@ciampo
ciampo marked this pull request as ready for review December 3, 2026 17:13
@ciampo
ciampo requested a review from a team as a code owner December 3, 2026 17:13
@ciampo
ciampo requested review from a team and Mamaduka December 3, 2026 17:13
@ciampo ciampo added the [Type] Enhancement A suggestion for improvement. label Dec 3, 2026
@github-actions
github-actions Bot requested a review from aduth December 3, 2026 17:14
At 320px the token always wins, so the test passed without the available width part of the rule. At 220px it fails without it.
…lipped

The width limit and short label cases pinned a design value and guarded speculative changes. The reflow test now also fails if the label is clipped instead of wrapped.

@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.

LGTM 👍

@ciampo
ciampo merged commit 7837d26 into trunk Dec 3, 2026
89 checks passed
@ciampo
ciampo deleted the fix/ui-tooltip-max-width branch December 3, 2026 20:58
@github-actions github-actions Bot added this to the Gutenberg 24.7 milestone Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] UI /packages/ui [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants