Skip to content

UI Badge: Stop a link underline from reaching the label - #87074

Open
t-hamano wants to merge 5 commits into
trunkfrom
fix/ui-badge-inherited-underline
Open

t-hamano wants to merge 5 commits into
trunkfrom
fix/ui-badge-inherited-underline

Conversation

@t-hamano

@t-hamano t-hamano commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

I found this while exploring the approach suggested in #86937 (comment).

What?

Stops the underline of a surrounding link from reaching the ui/Badge label, including when the badge is a flex or grid item.

Why?

In Site Editor v2, the page list renders titles as links, so the "Privacy Policy Page" badge next to the title is underlined too.

ui/Badge has no inner element to block the underline, unlike components/Badge, which fixed the same issue in #72097. This latent issue surfaced when #82499 migrated the page title badge to ui/Badge.

Setting display: inline-block; text-decoration: none on the badge itself is not enough: a flex or grid item is always blockified, and text-decoration: none cannot remove an underline inherited from an ancestor.

How?

  • Wraps the label in a span rendered as an inline block, which an underline does not propagate into.
  • Makes the badge an inline block with max-width: 100%, so a long label wraps inside the badge.
  • Adds overflow: hidden and text-overflow: ellipsis to the label, so a badge with white-space: nowrap still truncates with an ellipsis.

The existing stories render pixel-identical before and after. A single word longer than the badge now ends with an ellipsis instead of overflowing the border.

Testing Instructions

  1. Open the ui/Badge stories in Storybook and confirm they look unchanged.
  2. Enable the "Extensible Site Editor" experiment, set a page as the privacy policy page in Settings > Privacy, and open the page list in the table or grid layout. Confirm the title is underlined and the "Privacy Policy Page" badge is not.
  3. Switch to the list layout, make it narrow, and confirm the badge still truncates with an ellipsis.

Screenshots or screencast

ui-badge-compare

Use of AI Tools

This PR was authored with Claude Code (Claude Opus 5.5), including the investigation, the fix and the screenshots, and reviewed by the author.

claude and others added 2 commits November 19, 2026 09:56
Wrap the label in an inline block, which an underline from a surrounding
link does not propagate into. The badge itself cannot block it when it is
a flex or grid item, because those are always blockified.

Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URyKcjmHwMrNzohTbkh
Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URyKcjmHwMrNzohTbkh
@t-hamano t-hamano self-assigned this Nov 19, 2026
@github-actions github-actions Bot added the [Package] UI /packages/ui label Nov 19, 2026
@github-actions

github-actions Bot commented Nov 19, 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: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>
Co-authored-by: jameskoster <jameskoster@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 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: +565 B (+0.01%)

Total Size: 8.68 MB

📦 View Changed
Filename Size Change
build/modules/core-fields/page.min.js 7.12 kB +67 B (+0.95%)
build/scripts/block-editor/index.min.js 556 kB +89 B (+0.02%)
build/scripts/block-library/index.min.js 427 kB +120 B (+0.03%)
build/scripts/edit-site/index.min.js 383 kB +110 B (+0.03%)
build/scripts/editor/index.min.js 572 kB +87 B (+0.02%)
build/scripts/media-utils/index.min.js 238 kB +92 B (+0.04%)

d1fe42e Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric 148fe57 trunk % Change
timeToFirstByte 42.8 ms +8.41% -3.5% 43.45 ms +9.78% -3.22% -1.5%
largestContentfulPaint 72 ms +2.78% -8.33% 70 ms +8.57% -2.86% 2.86%
lcpMinusTtfb 25.85 ms +18.57% -11.8% 25.95 ms +15.61% -8.67% -0.39%
wpBeforeTemplate 22.34 ms +7.83% -3.09% 22.17 ms +11.95% -2.07% 0.77%
wpTemplate 16.93 ms +3.72% -3.48% 17.35 ms +4.21% -3.34% -2.42%
wpTotal 39.57 ms +8.57% -3.64% 40.22 ms +9.42% -3.61% -1.62%
wpMemoryUsage 7.75 MB +0% -0% 7.71 MB +0% -0% 0.45%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric 148fe57 trunk % Change
timeToFirstByte 34.45 ms +13.21% -1.31% 35.25 ms +10.5% -3.12% -2.27%
largestContentfulPaint 64 ms +6.25% -3.13% 64 ms +3.13% -6.25% 0%
lcpMinusTtfb 29.2 ms +3.25% -7.02% 27.4 ms +4.2% -4.93% 6.57%
wpBeforeTemplate 19.09 ms +10.11% -1.15% 19.3 ms +16.27% -2.18% -1.09%
wpTemplate 12.73 ms +6.13% -2.44% 13.05 ms +3.3% -3.07% -2.45%
wpTotal 31.83 ms +13.76% -1.82% 32.48 ms +11.27% -2.92% -2%
wpMemoryUsage 6.44 MB +0% -0% 6.40 MB +0% -0% 0.56%
wpDbQueries 13 +0% -0% 13 +0% -0% 0%

media-processing

Metric 148fe57 trunk % Change
mediaProcessingJpeg 326.72 ms +0.55% -0.24% 325.09 ms +0.81% -0.45% 0.5%
mediaProcessingAvif 4884.61 ms +0.15% -0.33% 4907.13 ms +0.76% -0.99% -0.46%
mediaProcessingJpegToAvif 3386.65 ms +0.61% -0.15% 3388.6 ms +0.45% -0.05% -0.06%

media-upload

Metric 148fe57 trunk % Change
jpegUploadProcessing 1474.94 ms +1.56% -1.57% 1458.63 ms +1.23% -1.21% 1.12%
pngUploadProcessing 242.2 ms +7% -4.5% 245.58 ms +2.92% -4.63% -1.38%
largeJpegUploadProcessing 1436.02 ms +0.82% -0.51% 1451.21 ms +0.17% -0.69% -1.05%
multipleImageUploadProcessing 1496.73 ms +2% -0.62% 1502.8 ms +0.89% -0.81% -0.4%

post-editor

Metric 148fe57 trunk % Change
serverResponse 483.98 ms +2.82% -8.57% 489.02 ms +1.05% -9.94% -1.03%
firstPaint 459.65 ms +1.6% -14.95% 420.47 ms +7.26% -8.59% 9.32%
domContentLoaded 836.35 ms +3.54% -1.7% 846.19 ms +2.3% -1.34% -1.16%
loaded 837.41 ms +3.55% -1.69% 847.48 ms +2.28% -1.35% -1.19%
firstContentfulPaint 465.72 ms +5.17% -1.49% 468.61 ms +1.49% -2.84% -0.62%
firstBlock 2249.45 ms +2.32% -1.14% 2239.18 ms +1.22% -0.66% 0.46%
type 18.38 ms +3.48% -3.05% 18.16 ms +8.7% -8.59% 1.21%
typeWithoutInspector 18.93 ms +7.29% -6.71% 18.04 ms +6.76% -12.14% 4.93%
typeWithTopToolbar 23.64 ms +4.65% -8.93% 22.52 ms +8.66% -6.62% 4.97%
typeContainer 8.57 ms +9.22% -13.42% 8.15 ms +10.67% -5.15% 5.15%
focus 122.47 ms +8.66% -3.82% 118.77 ms +6.3% -3.6% 3.12%
firstFocus 264.16 ms +0% -0% 277.06 ms +0% -0% -4.66%
selectAll 423.05 ms +0.69% -1.6% 431.86 ms +1.27% -5.39% -2.04%
undo 29.6 ms +6.62% -5.51% 29.16 ms +3.6% -4.84% 1.51%
listViewOpen 82.14 ms +16.87% -10.77% 76.4 ms +10.22% -4.86% 7.51%
inserterOpen 46.53 ms +4.3% -17.41% 39.37 ms +9.55% -1.24% 18.19%
inserterHover 12.27 ms +8.15% -10.11% 11.34 ms +4.32% -4.94% 8.2%
inserterSearch 9.11 ms +3.84% -8.89% 7.85 ms +4.71% -8.41% 16.05%
loadPatterns 678.63 ms +1.72% -2.79% 667.45 ms +1.69% -6.6% 1.68%
wpTotal 474.36 ms +2.88% -8.75% 479.39 ms +0.85% -10.19% -1.05%
wpMemoryUsage 14.81 MB +0% -0% 14.77 MB +0% -0% 0.25%
wpDbQueries 55 +0% -0% 55 +0% -0% 0%

site-editor

Metric 148fe57 trunk % Change
serverResponse 326.88 ms +1.33% -7.93% 320.07 ms +2.42% -7.21% 2.13%
firstPaint 376.27 ms +5.13% -11.88% 345.54 ms +10.86% -11.07% 8.89%
domContentLoaded 693.51 ms +4.68% -3.21% 697.34 ms +2.39% -1.29% -0.55%
loaded 694.38 ms +4.67% -3.22% 698.29 ms +2.38% -1.28% -0.56%
firstContentfulPaint 394.49 ms +5.59% -3.21% 390.7 ms +3.29% -1.19% 0.97%
firstBlock 2086.6 ms +5.35% -2.65% 2099.52 ms +2.2% -0.07% -0.62%
type 14.15 ms +9.61% -8.34% 16.61 ms +5.3% -11.26% -14.81%
navigate 90.81 ms +9.49% -3.22% 91.64 ms +16.5% -3.61% -0.91%
loadPatterns 1071.44 ms +10.81% -9.08% 1028.97 ms +23.17% -7.09% 4.13%
loadPages 927.54 ms +1.2% -0.75% 990.95 ms +1.81% -7.11% -6.4%
wpTotal 318.46 ms +1.4% -8.21% 311.66 ms +2.45% -7.42% 2.18%
wpMemoryUsage 12.82 MB +0% -0% 12.79 MB +0% -0% 0.25%
wpDbQueries 45 +0% -0% 45 +0% -0% 0%

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

Navigates the list via UP/DOWN arrow keys from action buttons in /test/e2e/specs/site-editor/dataviews-list-layout-keyboard.spec.js, passed after 1 failed attempt.
Error: expect(locator).toBeFocused() failed

Locator:  getByRole('row', { name: 'Page Two Edit Actions' }).getByRole('button', { name: 'Edit' })
Expected: focused
Received: inactive
Timeout:  5000ms

Call log:
  - Expect "toBeFocused" getByRole('row', { name: 'Page Two Edit Actions' }).getByRole('button', { name: 'Edit' }) with timeout 5000ms
  - waiting for getByRole('row', { name: 'Page Two Edit Actions' }).getByRole('button', { name: 'Edit' })
    14 × locator resolved to <button type="button" tabindex="-1" class="components-button is-small" id="view-list-0-176-primary-action-edit-post">Edit</button>
       - unexpected value "inactive"

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/dataviews-list-layout-keyboard.spec.js:243:5
Submenu interactions on Safari (@WebKit) 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('region', { name: 'Editor top bar' }).getByRole('button', { name: 'Save', exact: true })
    - locator resolved to <button type="button" aria-disabled="true" class="components-button editor-post-publish-button editor-post-publish-button__button is-primary is-compact">Save</button>
  - attempting click action
    2 × waiting for element to be visible, enabled and stable
      - element is not enabled
    - retrying click action
    - waiting 20ms
    2 × waiting for element to be visible, enabled and stable
      - element is not enabled
    - retrying click action
      - waiting 100ms
    16 × waiting for element to be visible, enabled and stable
       - element is not enabled
     - retrying click action
       - waiting 500ms

    at Editor.saveSiteEditorEntities (/home/runner/work/gutenberg/gutenberg/packages/e2e-test-utils-playwright/src/editor/site-editor.ts:39:22)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/navigation-frontend-interactivity.spec.js:386:4
page-list submenu user interactions 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('region', { name: 'Editor top bar' }).getByRole('button', { name: 'Save', exact: true })
    - locator resolved to <button type="button" aria-disabled="true" class="components-button editor-post-publish-button editor-post-publish-button__button is-primary is-compact">Save</button>
  - attempting click action
    2 × waiting for element to be visible, enabled and stable
      - element is not enabled
    - retrying click action
    - waiting 20ms
    2 × waiting for element to be visible, enabled and stable
      - element is not enabled
    - retrying click action
      - waiting 100ms
    13 × waiting for element to be visible, enabled and stable
       - element is not enabled
     - retrying click action
       - waiting 500ms

    at Editor.saveSiteEditorEntities (/home/runner/work/gutenberg/gutenberg/packages/e2e-test-utils-playwright/src/editor/site-editor.ts:39:22)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/navigation-frontend-interactivity.spec.js:705:4
should select synced pattern in /test/e2e/specs/editor/various/writing-flow.spec.js, passed after 1 failed attempt.
Error: expect(locator).toBeFocused() failed

Locator:  locator('[name="editor-canvas"]').contentFrame().locator('[data-type="core/block"]')
Expected: focused
Received: inactive
Timeout:  5000ms

Call log:
  - Expect "toBeFocused" locator('[name="editor-canvas"]').contentFrame().locator('[data-type="core/block"]') with timeout 5000ms
  - waiting for locator('[name="editor-canvas"]').contentFrame().locator('[data-type="core/block"]')
    14 × locator resolved to <div tabindex="0" role="document" draggable="true" data-title="Pattern" data-type="core/block" data-is-drop-zone="true" aria-label="Block: Pattern" id="block-67ac4196-056c-43e7-b296-6eada2a204a8" data-block="67ac4196-056c-43e7-b296-6eada2a204a8" class="block-editor-block-list__block wp-block is-selected is-reusable block-library-block__reusable-block-container wp-block-block block-editor-block-list__layout">…</div>
       - unexpected value "inactive"

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/writing-flow.spec.js:1464:5

d1fe42e Run

@t-hamano t-hamano added the [Type] Bug An existing feature does not function as intended label Nov 19, 2026
claude and others added 2 commits November 19, 2026 10:11
Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URyKcjmHwMrNzohTbkh
@t-hamano
t-hamano marked this pull request as ready for review November 19, 2026 10:12
@t-hamano
t-hamano requested a review from a team as a code owner November 19, 2026 10:12
@github-actions
github-actions Bot requested review from aduth and ciampo November 19, 2026 10:13
Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URyKcjmHwMrNzohTbkh

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

It's a bit questionable whether the new wrapping behavior would still make the badge read as a badge. It's now ambiguous whether it could be a small input or button. But unfortunately the fix seems to require it, and I agree it's worth fixing.

However, the truncation isn't required for the fix, right? The decision not to add truncation by default was a conscious decision, so I'd prefer not adding it here if it's not necessary.

variant="body-sm"
>
{ children }
<span className={ styles.label }>{ children }</span>

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.

DataViews' grid and pickerGrid layouts hide empty badge fields with :empty. The label span makes those badges non-empty even when the field renders null or '', so an empty pill becomes visible. Can we keep the empty-field hiding in both layouts? Maybe like :has(> :only-child:empty).

.label {
display: inline-block;
max-width: 100%;
overflow: hidden;

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.

(May not be needed if we drop the truncation)

overflow: hidden clips glyphs that extend past the 16px line box. Thai tone marks lose about a pixel at the top. Extending the clip area keeps the layout the same and avoids that:

Suggested change
overflow: hidden;
overflow: hidden;
padding-block: var(--wpds-dimension-padding-xs);
margin-block: calc(-1 * var(--wpds-dimension-padding-xs));
compare-thai

@jameskoster

Copy link
Copy Markdown
Contributor

Agree that's a shame but I think it's an acceptable trade-off; wrapping badges should really be an edge case.

This branch has not been deployed

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

Labels

[Package] UI /packages/ui [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants