createOverflow
A composable for computing how many items fit in a container based on available width, enabling responsive truncation for pagination, breadcrumbs, and similar components.
Usage
The createOverflow composable provides reactive container width tracking and capacity calculation. Variable-width mode measures each mounted item. Uniform-width mode uses one itemWidth when every item really is that width. Probe mode asks for a count that is not mounted yet, then checks the row that renders.
Context / DI
Use createOverflowContext to share an overflow instance across a component tree:
import { createOverflowContext } from '@vuetify/v0'
export const [useNavOverflow, provideNavOverflow, navOverflow] =
createOverflowContext({ namespace: 'my:nav-overflow' })
// In parent component
provideNavOverflow()
// In child component
const overflow = useNavOverflow()
overflow.capacity.value // number of items that fitUse useOverflow to inject the default (unnamespaced) overflow context provided by a parent:
import { useOverflow } from '@vuetify/v0'
const overflow = useOverflow() // Injects the nearest provided overflow contextArchitecture
createOverflow uses ResizeObserver to compute container capacity:
Options
| Option | Type | Default | Notes |
|---|---|---|---|
gap | MaybeRefOrGetter<number> | 0 | Gap between items in pixels |
reserved | MaybeRefOrGetter<number> | 0 | Reserved space in pixels (nav buttons, ellipsis, etc.) |
itemWidth | MaybeRefOrGetter<number> | — | Uniform item width; enables uniform mode |
probe | boolean | false | Ask for a count beyond the mounted children, then correct it with settle() |
max | MaybeRefOrGetter<number> | — | Largest count probe mode may ask for |
budget | MaybeRefOrGetter<number> | — | Content-box width in pixels. When omitted, probe mode claims free space in the parent |
Reactivity
| Property/Method | Reactive | Notes |
|---|---|---|
container | ShallowRef, assign element for tracking | |
width | ShallowRef, readonly (from ResizeObserver) | |
capacity | Computed from width and measurements | |
total | Computed, sum of all item widths | |
isOverflowing | Computed from total vs available width | |
settle() | — | Probe mode only. Call after measuring the row you were asked to render |
Examples
- Visible
- 7 / 7
- Overflowing
- false
- Container
- 0px
Shrink the container to watch trailing destinations collapse into the overflow menu, then widen it to see them return.
FAQ
createOverflow measures how many items fit one row and hides the rest — overflow menus, breadcrumb ellipsis, responsive toolbars. createVirtual windows a long scrollable list, rendering only the rows in view. Horizontal truncation vs vertical windowing.
Items must keep their measured widths. If you unmount overflowing items (e.g. slice(0, capacity)) their widths are thrown away and capacity can’t recompute upward. Measure every item once, then hide with v-show so the widths stay in the map.
Variable-width measures each mounted item, such as breadcrumbs and nav links. Uniform-width uses one itemWidth when every item is that width. Probe mode is for a fitting count that is not mounted yet: render capacity, measure the row, and call settle(). Pagination uses probe mode so a wide page number can shrink the row and a narrower page can grow it back. Use reserved to keep room for controls that are not part of the counted items.
Reach for createOverflow when you need full control over how truncation is presented — a custom overflow menu, breadcrumb ellipsis, or responsive toolbar. The Overflow component wraps it with item registration and an indicator slot when the default presentation is enough.