# Overflow

> Shows the items that fit on one line and hands the rest to a "more" control.

A row (or column) that shows the leading items that fit and hands the rest to
`renderOverflow(hidden)`, like a toolbar or tab strip's "more" menu.

Native layout has no "hide what does not fit and tell me" rule, so the decision is made in JS
from sizes native reports (`onSize`), with no extra pass: sizes from one layout arrive in one
batch, which re-renders once with the new split, computed during that render (no microtask
re-render). Items keep their last measured size while hidden (`display: none`), so growing back
needs no trial render; an item never measured is shown once to be measured. The box clips
(`overflow: hidden`) so nothing spills meanwhile. Give it a bounded main size (`flex: 1`, a
width), or `max` to let it grow with its items up to a limit.

- Category: [Window & layout](https://tarve.dev/docs.md#layout)
- Import: `import { Overflow } from "@tarve/core";`
- Props type: `OverflowProps<T>` (generic)
- Source: [packages/core/src/components/overflow.ts:70](https://github.com/omarcosr/tarve/blob/main/packages/core/src/components/overflow.ts#L70)

## Usage

```tsx title="Overflow.tsx"
import { Button, Column, DropdownMenu, Overflow, Slider, Text } from "@tarve/core";

const tools = ["Bold", "Italic", "Underline", "Link", "Quote", "Code", "List", "Table"];
let width = 320;
let menu = false;

<Column gap={12}>
  <Slider value={width} min={120} max={560} onValueChange={(value) => (width = value)} />
  <Overflow
    id="toolbar"
    items={tools}
    gap={6}
    style={{ width }}
    renderItem={(tool) => <Button size="sm" variant="outline">{tool}</Button>}
    renderOverflow={(hidden) => (
      <DropdownMenu
        id="toolbar-more"
        open={menu}
        onOpenChange={(next) => (menu = next)}
        trigger={<Button size="sm" variant="ghost">{`+${hidden.length}`}</Button>}
        items={hidden.map((tool) => ({ value: tool, label: tool }))}
      />
    )}
  />
  <Text size={12}>{`${width}px`}</Text>
</Column>
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `id` (required) | `string` | — | Remembers the measured sizes across renders. |
| `items` (required) | `readonly T[]` | — |  |
| `renderItem` (required) | `(item: T, index: number) => Child` | — |  |
| `direction` | `"row" \| "column"` | `"row"` | Main axis. Default `"row"`. |
| `gap` | `number` | `0` |  |
| `itemKey` | `(item: T, index: number) => string \| number` | — | Stable key of an item. Default: its index. |
| `max` | `number` | — | Space available on the main axis, in logical px (border box). When set, the box sizes to its items up to `max` (`maxWidth`/`maxHeight`) and decides what fits against `max` instead of its measured size, so it works in a container that grows with its content (a dock, a taskbar). |
| `renderOverflow` | `(hidden: T[]) => Child` | — | The control for the items that do not fit (a "more" button); not shown while everything fits. |

### Inherited from `ViewProps`

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `align` | `Style["align"]` | — |  |
| `autoFocus` | `boolean` | — | Focus this control when it first appears (HTML `autofocus`); interactive views only (Pressable). |
| `dismissOnOutside` | `boolean` | — | A press outside the box fires `onOutsideClick` instead of reaching what is under it (light dismiss). Works on portals and in-flow boxes; an open portal wins. |
| `dragRegion` | `boolean` | — |  |
| `flex` | `number \| string` | — | CSS `flex`: `1` is `1 1 0`; strings take any CSS value, e.g. `"1 1 176px"`. |
| `focusable` | `boolean` | — |  |
| `justify` | `Style["justify"]` | — |  |
| `onOutsideClick` | `() => void` | — | With `dismissOnOutside`: a press (or right click) outside the box. |
| `padding` | `Style["padding"]` | — |  |
| `portal` | `boolean` | — |  |
| `style` | `Reactive<Style>` | — | Values may be signals: setting one restyles this box without a render. |
| `windowAction` | `"minimize" \| "toggleMaximize" \| "toggleFullscreen" \| "close"` | — |  |

## Common props

Shared by every component (descriptions: https://tarve.dev/docs.md#common-props): `class`, `className`, `dropTarget`, `fileDropTarget`, `highlight`, `key`, `motionFrom`, `onDragEnter`, `onDragLeave`, `onDrop`, `onFileDragEnter`, `onFileDragLeave`, `onFileDrop`, `onHighlight`, `onPaste`, `onPointerLeave`, `onPointerMove`, `onSize`, `onTransitionEnd`, `rovingGroup`.

## Types

```ts title="Reactive"
type Reactive<S> = { [K in keyof S]: S[K] | Signal<Exclude<S[K], undefined>> };
```

Previous: [ScrollArea](https://tarve.dev/docs/components/ScrollArea.md) · Next: [Portal](https://tarve.dev/docs/components/Portal.md)

---

Tarve v0.13.8 · HTML version: https://tarve.dev/docs/components/Overflow · Index for agents: https://tarve.dev/llms.txt
