Skip to content

Overflow

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

Home
Products
Services
About
Blog
Contact
Careers
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

NameTypeRequiredDefaultDescription
overflowButton(count: number, hiddenIds: string[]) => React.ReactNodeNo

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 itemIds in DOM order, so the button can open a menu of the hidden items. hiddenIds is the button's own array (sorting it in place affects nobody else). Its size on the row's axis (width, or height for a vertical row) is measured and reserved when items overflow. In a list row (role="list", with asChild <li> items) the button's wrapper is a list item (role="listitem"). Components rendered by it can also read the hidden items with useOverflowMenu.

childrenReact.ReactNodeYes

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 OverflowItem and pin it with pinned.

overflowDirection'end' | 'start'No'end'

Which end of the row overflows first (start is the start of the DOM order, so the right side of a right-to-left row). While no item sets priority or pinned (pinned={false} does not count) the first item (end) or the last one (start) is never hidden, as in 0.13; once any item pins itself or sets a priority, only pinned items are protected, the first one included.

buttonPosition'end' | 'before-hidden'No'end'

Where the overflow button goes while items are hidden: 'end' after every item, sticking to the end of the axis; 'before-hidden' just before the first hidden item in DOM order, so it stands in for the hidden items (a breadcrumb trail), and takes the row's gap as the items do. With 'before-hidden' the items must be children of the Overflow (Fragments and arrays are opened): when the first hidden item is rendered by another component the button stays at the end, with a development warning. The button moves without remounting. While nothing is hidden there is no button, except the one hasHiddenItems reserves, at the end.

orientation'horizontal' | 'vertical'No'horizontal'

The axis items are laid out on. 'vertical' stacks them in a column and measures heights (Fluent's overflowAxis); the column needs a definite height (a height, or a flex or grid cell with one), since it has no room to measure otherwise.

minimumVisiblenumberNo0

The number of items that stay visible however little room there is (pinned items count).

hasHiddenItemsbooleanNofalse

Renders the overflow button before the first measurement (for example in the server HTML) so the row reserves its room; overflowButton then receives 0 and []. It goes away after the first measurement when every item fits.

onOverflowChange(hiddenItems: string[], details: OverflowChangeDetails) => voidNo

Called, from an effect, when the set of hidden items changes (not for the initial, empty set), with the hidden itemIds in DOM order and the OverflowChangeDetails. Called once per change in StrictMode, and only for a set that has been rendered. The Overflow always passes details; a handler of the hidden ids alone fits.

refReact.Ref<HTMLDivElement>No
slotProps{ overflowButton?: SlotPart<'div'> }No

Props for the wrapper the row draws around what overflowButton returns, merged into its own: your classes after its classes (yours win a conflict), your styles over its styles, your attributes and handlers added, your ref attached beside the row's own. Every attribute the row sets on it is locked. A part takes no children (overflowButton renders them) and carries no handler of the row. Fluent UI has no such part: its overflow menu is rendered by you.

Any other prop is passed to the element it renders (HTMLDivElement).

Parts

  • overflowButton
  • Overflow.Item
  • Overflow.Divider

Stable class names

PartClass
rootwave-overflow
overflowButtonwave-overflow__overflow-button