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.
Import
import { Overflow } from "@tarve/core";Usage
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 |
|---|---|---|
id required Remembers the measured sizes across renders. | string | — |
items required | readonly T[] | — |
renderItem required | (item: T, index: number) => Child | — |
direction Main axis. Default `"row"`. | "row" | "column" | "row" |
gap | number | 0 |
itemKey Stable key of an item. Default: its index. | (item: T, index: number) => string | number | — |
max 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). | number | — |
renderOverflow The control for the items that do not fit (a "more" button); not shown while everything fits. | (hidden: T[]) => Child | — |
Inherited from ViewProps 12 props
| Prop | Type | Default |
|---|---|---|
align | Style["align"] | — |
autoFocus Focus this control when it first appears (HTML `autofocus`); interactive views only (Pressable). | boolean | — |
dismissOnOutside 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. | boolean | — |
dragRegion | boolean | — |
flex CSS `flex`: `1` is `1 1 0`; strings take any CSS value, e.g. `"1 1 176px"`. | number | string | — |
focusable | boolean | — |
justify | Style["justify"] | — |
onOutsideClick With `dismissOnOutside`: a press (or right click) outside the box. | () => void | — |
padding | Style["padding"] | — |
portal | boolean | — |
style Values may be signals: setting one restyles this box without a render. | Reactive<Style> | — |
windowAction | "minimize" | "toggleMaximize" | "toggleFullscreen" | "close" | — |
Common props
Shared by every component. See descriptions →
classclassNamedropTargetfileDropTargethighlightkeymotionFromonDragEnteronDragLeaveonDroponFileDragEnteronFileDragLeaveonFileDroponHighlightonPasteonPointerLeaveonPointerMoveonSizeonTransitionEndrovingGroupTypes
type Reactive<S> = { [K in keyof S]: S[K] | Signal<Exclude<S[K], undefined>> };