Skip to content

Tabs: Keep a horizontal list within its container - #87400

Merged
t-hamano merged 10 commits into
trunkfrom
fix/ui-tabs-list-shrink-in-flex
Dec 1, 2026
Merged

t-hamano merged 10 commits into
trunkfrom
fix/ui-tabs-list-shrink-in-flex

Conversation

@t-hamano

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

Copy link
Copy Markdown
Contributor

What?

Follow up to #84572

Adds min-width: 0 to a horizontal Tabs.List in @wordpress/ui, so the list shrinks inside a flex container and the tabs that do not fit scroll.

Update: Adds min-width: 0 and max-width: 100% to a horizontal Tabs.List in @wordpress/ui, so the list stays within its container, whether it is a flex container or a regular block container, and the tabs that do not fit scroll.

Why?

In the editor settings sidebar, the header row is a flex container that holds the tab list and the close button.

<div class="interface-complementary-area editor-sidebar"> <!-- 280px, scrolls -->
	<div class="components-panel__header editor-sidebar__panel-tabs"> <!-- display: flex -->
		<div role="tablist">
			<button role="tab">Template Part</button>
			<button role="tab">Block</button>
		</div>
		<button aria-label="Close Settings">×</button>
	</div>
	<!-- Panels -->
</div>

When the tabs are wider than the space left, the list does not scroll. It pushes the header wider than the sidebar, and the sidebar gets a horizontal scrollbar that cuts off the close button.

image

#84572 added overflow: visible to the list while it is not scrolling. The list only gets is-scrolling when its own scrollWidth is larger than its clientWidth. Before #84572, overflow-inline: auto always made the list a scroll container, so its automatic minimum size as a flex item was 0, and it shrank to the space it had. With overflow: visible, the automatic minimum size is its content width. The list now stays as wide as its tabs, its scrollWidth never exceeds its clientWidth, is-scrolling is never set, and the overflow goes to the parent.

Update: As pointed out in review, a list in a regular block container also overflows when the tabs do not fit, because width: fit-content never goes below the tabs' combined width. That was already the case before #84572.

How?

  • Set min-width: 0 on .tablist[data-orientation="horizontal"]. The list can shrink again as a flex item. Once it is narrower than its tabs, is-scrolling is set and the existing scroll and fade behavior takes over. Set min-width: 0 and max-width: 100% on the horizontal list, so it stays within both flex and block containers and scrolls when the tabs do not fit. The maxWidth: '100%' in the SizeAndOverflowPlayground and MinimalTabsOverflow stories is removed, and browser tests cover both cases.

Testing Instructions

  1. Register a post type with a long singular name, for example:
    add_action( 'init', function () {
    	register_post_type( 'faq', array(
    		'labels'       => array( 'name' => 'Frequently Asked Questions', 'singular_name' => 'Frequently Asked Question' ),
    		'public'       => true,
    		'show_in_rest' => true,
    	) );
    } );
  2. Create a post of that type, select a block, and open the Block tab.
  3. On trunk, the sidebar scrolls horizontally and the close button is cut off. With this PR, the tabs scroll in the header and the sidebar does not scroll horizontally.

Screenshots or screencast

faq-before-after (1)

Use of AI Tools

I used Claude Code to find the cause, reproduce it in Playground and Storybook, and write the change and this description. I reviewed the result.


Generated by Claude Code

claude and others added 2 commits November 25, 2026 12:53
Since the list paints with `overflow: visible` until it scrolls, its automatic
minimum size as a flex item is its content width. It never got narrower than
its tabs, so it never started scrolling and pushed its flex parent wider.
Add `min-width: 0` so it shrinks and the existing scroll behavior takes over.

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_011g9URwkkn2HthVZbFNci9B
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_011g9URwkkn2HthVZbFNci9B
@t-hamano t-hamano self-assigned this Nov 25, 2026
@github-actions github-actions Bot added the [Package] UI /packages/ui label Nov 25, 2026
@github-actions

github-actions Bot commented Nov 25, 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: ciampo <mciampini@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: +17 B (0%)

Total Size: 8.73 MB

📦 View Changed
Filename Size Change
build/scripts/block-editor/index.min.js 561 kB -3 B (0%)
build/scripts/block-library/index.min.js 433 kB +11 B (0%)
build/scripts/editor/index.min.js 576 kB +9 B (0%)

e97f5b7 Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric c5d25e4 trunk % Change
timeToFirstByte 45.8 ms +11.03% -4.15% 46.8 ms +8.76% -6.62% -2.14%
largestContentfulPaint 76 ms +7.89% -10.53% 76 ms +7.89% -7.89% 0%
lcpMinusTtfb 29.45 ms +9.34% -20.88% 30.15 ms +2.65% -20.23% -2.32%
wpBeforeTemplate 23.67 ms +11.45% -2.03% 23.92 ms +12.37% -3.72% -1.05%
wpTemplate 18.37 ms +4.68% -5.12% 18.12 ms +7.01% -4.97% 1.38%
wpTotal 41.99 ms +12.69% -3.48% 43.04 ms +9.67% -6.16% -2.44%
wpMemoryUsage 7.75 MB +0% -0% 7.72 MB +0% -0% 0.45%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric c5d25e4 trunk % Change
timeToFirstByte 36.05 ms +7.21% -1.8% 36.4 ms +6.59% -2.75% -0.96%
largestContentfulPaint 64 ms +6.25% -0% 64 ms +6.25% -0% 0%
lcpMinusTtfb 28.55 ms +0.88% -1.75% 28.45 ms +2.28% -2.81% 0.35%
wpBeforeTemplate 20.07 ms +4.63% -0.3% 19.97 ms +5.66% -1.15% 0.5%
wpTemplate 13 ms +6.31% -2.31% 13.3 ms +2.78% -4.89% -2.26%
wpTotal 33.22 ms +7.89% -1.75% 33.53 ms +6.95% -2.56% -0.92%
wpMemoryUsage 6.44 MB +0% -0% 6.41 MB +0% -0% 0.56%
wpDbQueries 13 +0% -0% 13 +0% -0% 0%

media-processing

Metric c5d25e4 trunk % Change
mediaProcessingJpeg 328.18 ms +0.66% -0.84% 327.44 ms +1.2% -0.86% 0.23%
mediaProcessingAvif 4854.75 ms +0.44% -0.25% 4843.03 ms +0.23% -0.17% 0.24%
mediaProcessingJpegToAvif 3397.98 ms +0.25% -0.3% 3391.55 ms +0.12% -0.29% 0.19%

media-upload

Metric c5d25e4 trunk % Change
jpegUploadProcessing 1476.12 ms +1.42% -1.27% 1471.51 ms +1.66% -0.56% 0.31%
pngUploadProcessing 249.67 ms +5.24% -7.53% 243.46 ms +3.18% -3.12% 2.55%
largeJpegUploadProcessing 1442.64 ms +1.38% -0.75% 1453.41 ms +0.34% -0.48% -0.74%
multipleImageUploadProcessing 1552.5 ms +0.77% -0.92% 1562.19 ms +0.78% -1.7% -0.62%

post-editor

Metric c5d25e4 trunk % Change
serverResponse 328.96 ms +2.87% -5.2% 334.25 ms +0.98% -9.07% -1.58%
firstPaint 350.49 ms +9.74% -7.91% 367.82 ms +2.14% -11.36% -4.71%
domContentLoaded 676.54 ms +2.41% -1.12% 662.75 ms +0.66% -1.05% 2.08%
loaded 677.5 ms +2.39% -1.13% 663.52 ms +0.71% -1.04% 2.11%
firstContentfulPaint 378.03 ms +2.86% -5.5% 375.17 ms +0.56% -0.8% 0.76%
firstBlock 1817.42 ms +1.68% -1.34% 1773.86 ms +1.09% -0.76% 2.46%
type 16.59 ms +3.68% -10.19% 15.57 ms +2.76% -9.38% 6.55%
typeWithoutInspector 15.93 ms +11.86% -6.28% 15.61 ms +3.4% -8.58% 2.05%
typeWithTopToolbar 20.41 ms +6.81% -2.11% 20.64 ms +3.39% -6.93% -1.11%
typeContainer 7.77 ms +8.37% -11.2% 7.13 ms +2.81% -11.92% 8.98%
focus 89.99 ms +6.7% -3.77% 85.98 ms +11.58% -3.42% 4.66%
firstFocus 222.73 ms +0% -0% 202.96 ms +0% -0% 9.74%
selectAll 320.73 ms +0.69% -1.84% 312.92 ms +0.28% -3.41% 2.5%
undo 25.41 ms +5.04% -4.13% 23.91 ms +7.61% -4.39% 6.27%
listViewOpen 33.37 ms +2.37% -1.98% 34.28 ms +14.96% -2.65% -2.65%
inserterOpen 34.99 ms +13.86% -8.15% 33.99 ms +4.38% -9.74% 2.94%
inserterHover 9.79 ms +6.74% -9.81% 10.1 ms +2.08% -2.57% -3.07%
inserterSearch 6.98 ms +5.16% -5.44% 7.41 ms +6.34% -4.59% -5.8%
loadPatterns 517.26 ms +1.25% -4.36% 508.91 ms +1.81% -1.48% 1.64%
wpTotal 320.22 ms +2.89% -5.29% 325.13 ms +1.18% -9.19% -1.51%
wpMemoryUsage 14.80 MB +0% -0% 14.77 MB +0% -0% 0.25%
wpDbQueries 55 +0% -0% 55 +0% -0% 0%

site-editor

Metric c5d25e4 trunk % Change
serverResponse 315.34 ms +1.33% -9.53% 312.64 ms +1.55% -8.97% 0.86%
firstPaint 323.69 ms +15.08% -9.84% 335.49 ms +10.91% -11.43% -3.52%
domContentLoaded 658.24 ms +0.31% -0.91% 652 ms +0.92% -0.67% 0.96%
loaded 658.94 ms +0.33% -0.9% 652.77 ms +0.92% -0.68% 0.95%
firstContentfulPaint 373.67 ms +1.79% -2.88% 369.81 ms +3.63% -2.56% 1.04%
firstBlock 2054.65 ms +5.54% -1.84% 2016.65 ms +0.75% -0.56% 1.88%
type 14.21 ms +4.29% -5.28% 14.24 ms +7.87% -3.3% -0.21%
navigate 94.01 ms +4.01% -0.51% 81.54 ms +13.77% -4.89% 15.29%
loadPatterns 1212.19 ms +9.71% -6.98% 925.53 ms +17.17% -6.12% 30.97%
loadPages 1005.11 ms +2.05% -1.41% 1008.94 ms +0.65% -1.75% -0.38%
wpTotal 306.97 ms +1.42% -9.87% 304.42 ms +1.55% -9.25% 0.84%
wpMemoryUsage 12.84 MB +0% -0% 12.80 MB +0% -0% 0.28%
wpDbQueries 45 +0% -0% 45 +0% -0% 0%

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

should keep the overlay intact when reopened before the close cleanup runs in /test/e2e/specs/editor/blocks/image.spec.js, passed after 1 failed attempt.
Error: clock.pauseAt: Error: Cannot fast-forward to the past
    at ClockController._innerFastForwardTo (eval at evaluate (:370:30), <anonymous>:206:13)
    at ClockController.pauseAt (eval at evaluate (:370:30), <anonymous>:132:16)
    at async <anonymous>:381:23
    at ClockController._innerFastForwardTo (eval at evaluate (:370:30), <anonymous>:206:13)
    at ClockController.pauseAt (eval at evaluate (:370:30), <anonymous>:132:16)
    at async <anonymous>:381:23
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/image.spec.js:1403:21
shows a Global Styles scale and lets a heading override it in /test/e2e/specs/editor/various/block-transform.spec.ts, passed after 1 failed attempt.
Error: Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/block-transform.spec.ts:280:6
stores relocated text and background colors under the selected viewport state in /test/e2e/specs/editor/various/block-style-state-colors.spec.js, passed after 1 failed attempt.
Error: locator.click: Error: strict mode violation: getByRole('option', { name: 'Vivid cyan blue' }) resolved to 2 elements:
    1) <button type="button" role="option" tabindex="-1" aria-selected="false" aria-label="Vivid cyan blue" id="components-circular-option-picker-0-10" class="components-button components-circular-option-picker__option is-next-40px-default-size"></button> aka locator('#components-circular-option-picker-0-10')
    2) <button type="button" role="option" tabindex="-1" aria-selected="false" aria-label="Vivid cyan blue" id="components-circular-option-picker-1-22" class="components-button components-circular-option-picker__option is-next-40px-default-size"></button> aka locator('#components-circular-option-picker-1-22')

Call log:
  - waiting for getByRole('option', { name: 'Vivid cyan blue' })

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/block-style-state-colors.spec.js:44:65

e97f5b7 Run

@t-hamano t-hamano added the [Type] Bug An existing feature does not function as intended label Nov 25, 2026
claude and others added 4 commits November 25, 2026 13: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_011g9URwkkn2HthVZbFNci9B
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_011g9URwkkn2HthVZbFNci9B
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_011g9URwkkn2HthVZbFNci9B
…ink-in-flex

# Conflicts:
#	packages/ui/CHANGELOG.md
@t-hamano
t-hamano marked this pull request as ready for review November 26, 2026 00:43
@t-hamano
t-hamano requested a review from a team as a code owner November 26, 2026 00:43
@github-actions
github-actions Bot requested review from aduth and ciampo November 26, 2026 00:44

@ciampo ciampo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM 🚀

Comment thread packages/ui/src/tabs/style.module.scss Resolved
Comment thread packages/ui/src/tabs/style.module.scss Resolved
claude and others added 2 commits November 29, 2026 11:18
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_011g9URwkkn2HthVZbFNci9B
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_011g9URwkkn2HthVZbFNci9B
@t-hamano t-hamano changed the title Tabs: Let a horizontal list shrink inside a flex container Tabs: Keep a horizontal list within its container Nov 29, 2026
Comment on lines +56 to +137
it( 'scrolls when the list shrinks inside a flex container', async () => {
await render(
<Tabs.Root defaultValue="one">
<div style={ { display: 'flex', width: 200 } }>
<Tabs.List>
<Tabs.Tab value="one">
<span
style={ {
display: 'inline-block',
width: 100,
} }
>
One
</span>
</Tabs.Tab>
<Tabs.Tab value="two">
<span
style={ {
display: 'inline-block',
width: 100,
} }
>
Two
</span>
</Tabs.Tab>
</Tabs.List>
<button type="button">Close</button>
</div>
<Tabs.Panel value="one">One panel</Tabs.Panel>
<Tabs.Panel value="two">Two panel</Tabs.Panel>
</Tabs.Root>
);
const tablist = screen.getByRole( 'tablist' );

await waitFor( () => {
expect( tablist ).toHaveClass( styles[ 'is-scrolling' ] );
} );
expect( tablist.parentElement?.scrollWidth ).toBe(
tablist.parentElement?.clientWidth
);
} );

it( 'scrolls when the list is inside a narrower block container', async () => {
await render(
<Tabs.Root defaultValue="one">
<div style={ { width: 150 } }>
<Tabs.List>
<Tabs.Tab value="one">
<span
style={ {
display: 'inline-block',
width: 100,
} }
>
One
</span>
</Tabs.Tab>
<Tabs.Tab value="two">
<span
style={ {
display: 'inline-block',
width: 100,
} }
>
Two
</span>
</Tabs.Tab>
</Tabs.List>
</div>
<Tabs.Panel value="one">One panel</Tabs.Panel>
<Tabs.Panel value="two">Two panel</Tabs.Panel>
</Tabs.Root>
);
const tablist = screen.getByRole( 'tablist' );

await waitFor( () => {
expect( tablist ).toHaveClass( styles[ 'is-scrolling' ] );
} );
expect( tablist.parentElement?.scrollWidth ).toBe(
tablist.parentElement?.clientWidth
);
} );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tiny nit, totally optional: these two tests repeat the tab markup from OverflowTabs. Maybe OverflowTabs could take the wrapper as a prop, so each test only sets up its container?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nice idea, fixed in e97f5b7

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_011g9URwkkn2HthVZbFNci9B
@t-hamano
t-hamano merged commit b973cfc into trunk Dec 1, 2026
89 checks passed
@t-hamano
t-hamano deleted the fix/ui-tabs-list-shrink-in-flex branch December 1, 2026 09:35
@github-actions github-actions Bot added this to the Gutenberg 24.6 milestone Dec 1, 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] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants