Overflow
A single row (or column) that hides the items which do not fit and shows an overflow button instead.
Wrap each entry in OverflowItem with a unique itemId; the row holds only items and OverflowDividers (other content is not measured, see children). Items are measured while visible and hidden while they do not fit: by ascending priority (equal priorities from the end of the DOM order, or from its start with overflowDirection="start"), never a pinned item and never below minimumVisible. Until an item sets priority or pinned, the first item (end) or the last one (start) always stays, as in 0.13. orientation="vertical" lays the items out in a column and measures heights; the column needs a definite height. The room is the row's own box, so it must not depend on the items shown: in a container as wide as its content, such as a Toolbar at its default width, the row narrows as items hide and never gets the room back to show them again; give the Overflow a width of its own, or put it in a row that takes its width from its parent and let it fill that row.
Items with the same groupId form a group that is 'visible', 'hidden' or 'overflow' (some members hidden): a divider with that groupId hides with a hidden group, useIsOverflowGroupVisible reads a group and useHasHiddenItems whether anything is hidden. onOverflowChange reports the hidden itemIds and the group visibility when the hidden items change. Hidden items get data-overflow-hidden, an inline display: none, aria-hidden and inert. Reordered items (for example a keyed sort) are re-measured in their new order. overflowButton(count, hiddenIds) renders the button after the visible items, or just before the first hidden item with buttonPosition="before-hidden" (its measured size is reserved); components inside it can use useOverflowMenu to list the hidden items (e.g. in a Menu), and useIsOverflowItemVisible reports a single item. In a horizontal row the button sticks to the inline end, so a first item wider than the room beside it cannot push it out of view: it then covers the end of that item and gets data-overflow-pinned, with the background token behind it (a vertical column sticks it to the bottom). (In a right-to-left row, WebKit stops the pinned button short of the end, still inside the row.)
The row clips what does not fit. So that the focus indicators of its items are not cut off, it has a 4px padding: the items sit 4px in from its edges, and the row is 8px taller than they are. An explicit width (such as w-full or a style width) includes that padding. The row never reaches past its own box, so an edge-to-edge row adds no scrollbar to the page or to a scroll container around it. A negative margin of 4px lines the items up with the content around the row; add it only where nothing within 4px of the row scrolls (the row's box then reaches 4px past its container on every side). p-0 removes the room (focus indicators at the row's edges are then clipped).
Works without ResizeObserver (jsdom, old browsers): it then re-measures on window resize and when items mount, unmount or move.
The item is also Overflow.Item and the divider Overflow.Divider. The same components are exported as OverflowItem and OverflowDivider; React Server Components import those flat names (dotted access needs a client file).
Examples
Default
export const Default: Story = {
render: (args) => (
<div className="w-[400px] max-w-full">
<Overflow {...args} />
</div>
),
};Narrow Container
export const NarrowContainer: Story = {
render: (args) => (
<div className="w-[200px]">
<Overflow {...args} />
</div>
),
};First Item Wider Than Row
export const FirstItemWiderThanRow: Story = {
args: {
children: ['Quarterly planning overview', ...pages].map((page) => (
<OverflowItem key={page} itemId={page}>
<Button appearance="subtle" className="whitespace-nowrap">
{page}
</Button>
</OverflowItem>
)),
},
render: (args) => (
<div className="w-[220px]">
<Overflow {...args} />
</div>
),
};End Aligned
export const EndAligned: Story = {
args: { className: 'gap-1 justify-end' },
render: (args) => (
<div className="w-[400px] max-w-full">
<Overflow {...args} />
</div>
),
};Short Items
export const ShortItems: Story = {
args: {
children: pages.map((page) => (
<OverflowItem key={page} itemId={page}>
<Badge appearance="tint">{page}</Badge>
</OverflowItem>
)),
},
render: (args) => (
<div className="w-[300px] max-w-full">
<Overflow {...args} />
</div>
),
};Priority And Pinned
export const PriorityAndPinned: Story = {
args: {
'aria-label': 'Document actions',
children: [
<OverflowItem key="Export" itemId="Export" priority={0}>
{subtleButton('Export')}
</OverflowItem>,
<OverflowItem key="History" itemId="History" priority={1}>
{subtleButton('History')}
</OverflowItem>,
<OverflowItem key="Share" itemId="Share" priority={2}>
{subtleButton('Share')}
</OverflowItem>,
<OverflowItem key="Comments" itemId="Comments" priority={3}>
{subtleButton('Comments')}
</OverflowItem>,
<OverflowItem key="Save" itemId="Save" pinned>
<Button appearance="primary" className="whitespace-nowrap">
Save
</Button>
</OverflowItem>,
],
},
render: (args) => (
<div className="w-[320px] max-w-full">
<Overflow {...args} />
</div>
),
};Groups With Dividers
export const GroupsWithDividers: Story = {
args: {
'aria-label': 'Editing tools',
overflowDirection: 'start',
children: [
<OverflowItem key="Cut" itemId="Cut" groupId="clipboard" priority={3}>
{subtleButton('Cut')}
</OverflowItem>,
<OverflowItem key="Copy" itemId="Copy" groupId="clipboard" priority={3}>
{subtleButton('Copy')}
</OverflowItem>,
<OverflowItem key="Paste" itemId="Paste" groupId="clipboard" priority={3}>
{subtleButton('Paste')}
</OverflowItem>,
<OverflowDivider key="divider-format" groupId="format">
<Divider orientation="vertical" className="h-6" />
</OverflowDivider>,
<OverflowItem key="Bold" itemId="Bold" groupId="format" priority={2}>
{subtleButton('Bold')}
</OverflowItem>,
<OverflowItem key="Italic" itemId="Italic" groupId="format" priority={2}>
{subtleButton('Italic')}
</OverflowItem>,
<OverflowDivider key="divider-view" groupId="view">
<Divider orientation="vertical" className="h-6" />
</OverflowDivider>,
<OverflowItem key="Zoom" itemId="Zoom" groupId="view" priority={1}>
{subtleButton('Zoom')}
</OverflowItem>,
<OverflowItem key="Outline" itemId="Outline" groupId="view" priority={1}>
{subtleButton('Outline')}
</OverflowItem>,
],
},
render: (args) => (
<div className="w-[480px] max-w-full">
<Overflow {...args} />
</div>
),
};In Toolbar With Groups
export const InToolbarWithGroups: Story = {
args: {
className: 'min-w-0 flex-1 gap-1',
children: [
<OverflowItem key="Undo" itemId="Undo" groupId="history" priority={2}>
<Toolbar.Button>Undo</Toolbar.Button>
</OverflowItem>,
<OverflowItem key="Redo" itemId="Redo" groupId="history" priority={2}>
<Toolbar.Button>Redo</Toolbar.Button>
</OverflowItem>,
<OverflowDivider key="divider-history" groupId="history">
<Toolbar.Divider />
</OverflowDivider>,
<OverflowItem key="Image" itemId="Image" groupId="insert" priority={1}>
<Toolbar.Button>Image</Toolbar.Button>
</OverflowItem>,
<OverflowItem key="Table" itemId="Table" groupId="insert" priority={1}>
<Toolbar.Button>Table</Toolbar.Button>
</OverflowItem>,
<OverflowItem key="Link" itemId="Link" groupId="insert" priority={1}>
<Toolbar.Button>Link</Toolbar.Button>
</OverflowItem>,
<OverflowDivider key="divider-insert" groupId="insert">
<Toolbar.Divider />
</OverflowDivider>,
<OverflowItem key="Share" itemId="Share" groupId="share" pinned>
<Toolbar.Button>Share</Toolbar.Button>
</OverflowItem>,
],
},
render: (args) => (
<div className="w-[420px] max-w-full">
<Toolbar aria-label="Document tools" className="flex">
<Overflow {...args} />
</Toolbar>
</div>
),
};Button Before Hidden Items
export const ButtonBeforeHiddenItems: Story = {
args: {
'aria-label': 'Sections',
buttonPosition: 'before-hidden',
overflowDirection: 'start',
children: pages.map((page, index) => (
<OverflowItem key={page} itemId={page} pinned={index === 0 || index === pages.length - 1}>
{subtleButton(page)}
</OverflowItem>
)),
},
render: (args) => (
<div className="w-[360px] max-w-full">
<Overflow {...args} />
</div>
),
};Vertical
export const Vertical: Story = {
args: {
'aria-label': 'Sidebar shortcuts',
orientation: 'vertical',
className: 'h-[160px] gap-1',
overflowButton: () => <HiddenItemsMenu />,
children: pages.map((page) => (
<OverflowItem key={page} itemId={page}>
{subtleButton(page)}
</OverflowItem>
)),
},
render: (args) => <Overflow {...args} />,
};Props
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
overflowButton | (count: number, hiddenIds: string[]) => React.ReactNode | No | Renders the overflow button (for example a "+3" menu trigger) while at least one item is hidden. Receives the number of hidden items and their | |
children | React.ReactNode | Yes | The OverflowItems (and OverflowDividers) to lay out in one row or column. Only items, dividers and the overflow button are measured: the container's whole content box is the room for them, so other content placed in the row is not accounted for and could clip items that still count as visible. Keep fixed content outside the Overflow (for example in a surrounding flex row), or wrap it in an | |
overflowDirection | 'end' | 'start' | No | 'end' | Which end of the row overflows first ( |
buttonPosition | 'end' | 'before-hidden' | No | 'end' | Where the overflow button goes while items are hidden: |
orientation | 'horizontal' | 'vertical' | No | 'horizontal' | The axis items are laid out on. |
minimumVisible | number | No | 0 | The number of items that stay visible however little room there is (pinned items count). |
hasHiddenItems | boolean | No | false | Renders the overflow button before the first measurement (for example in the server HTML) so the row reserves its room; |
onOverflowChange | (hiddenItems: string[], details: OverflowChangeDetails) => void | No | Called, from an effect, when the set of hidden items changes (not for the initial, empty set), with the hidden | |
ref | React.Ref<HTMLDivElement> | No | ||
slotProps | { overflowButton?: SlotPart<'div'> } | No | Props for the wrapper the row draws around what |
Any other prop is passed to the element it renders (HTMLDivElement).
Parts
overflowButtonOverflow.ItemOverflow.Divider
Stable class names
| Part | Class |
|---|---|
root | wave-overflow |
overflowButton | wave-overflow__overflow-button |