Repository navigation
Tabs: Keep a horizontal list within its container - #87400
Conversation
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
🤖 PR meta 🤖🎉 PropsIf 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. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the 📦 Bundle sizeSize Change: +17 B (0%) Total Size: 8.73 MB 📦 View Changed
⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
🏁 Flaky testsSome 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
|
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
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
| 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 | ||
| ); | ||
| } ); |
There was a problem hiding this comment.
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?
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
What?
Follow up to #84572
Addsmin-width: 0to a horizontalTabs.Listin@wordpress/ui, so the list shrinks inside a flex container and the tabs that do not fit scroll.Update: Adds
min-width: 0andmax-width: 100%to a horizontalTabs.Listin@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.
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.
#84572 added
overflow: visibleto the list while it is not scrolling. The list only getsis-scrollingwhen its ownscrollWidthis larger than itsclientWidth. Before #84572,overflow-inline: autoalways 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. Withoverflow: visible, the automatic minimum size is its content width. The list now stays as wide as its tabs, itsscrollWidthnever exceeds itsclientWidth,is-scrollingis 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-contentnever goes below the tabs' combined width. That was already the case before #84572.How?
SetSetmin-width: 0on.tablist[data-orientation="horizontal"]. The list can shrink again as a flex item. Once it is narrower than its tabs,is-scrollingis set and the existing scroll and fade behavior takes over.min-width: 0andmax-width: 100%on the horizontal list, so it stays within both flex and block containers and scrolls when the tabs do not fit. ThemaxWidth: '100%'in theSizeAndOverflowPlaygroundandMinimalTabsOverflowstories is removed, and browser tests cover both cases.Testing Instructions
Screenshots or screencast
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