useOverflow
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 useOverflow composable provides reactive container width tracking and capacity calculation. It supports two modes: variable-width (for items with different widths like breadcrumbs) and uniform-width (for same-width items like pagination buttons).
import { useTemplateRef } from 'vue'
import { createOverflow } from '@vuetify/v0'
const containerRef = useTemplateRef('container')
// Pass container as a ref or getter for proper reactive tracking
const overflow = createOverflow({
container: containerRef,
gap: 8,
reserved: 40,
})
// Check capacity
console.log(overflow.capacity.value) // Number of items that fit
console.log(overflow.isOverflowing.value) // true if items exceed containerArchitecture
useOverflow uses ResizeObserver to compute container capacity:
Functions
createOverflow
(options?: OverflowOptions) => ECreates a new overflow context for computing how many items fit in a container.
createOverflowContext
(_options?: OverflowContextOptions) => ContextTrinity<E>Creates an overflow context with dependency injection support.
Options
container
MaybeRefOrGetter<Element>Container element to track. Can be a ref, getter, or MaybeRefOrGetter. When provided, useOverflow tracks this element's width automatically. Accepts null for compatibility with Vue's useTemplateRef.
itemWidth
MaybeRefOrGetter<number>Uniform item width in pixels. When provided, enables uniform mode where capacity is calculated as available space / itemWidth. Use this for same-width items like pagination buttons.
reverse
MaybeRefOrGetter<boolean>Calculate capacity from end instead of start. Useful for breadcrumbs where trailing items take priority. Only affects variable mode (uniform mode capacity is direction-independent).
