Skip to main content
Vuetify0 Logo
Theme
Mode
Palettes
Accessibility
Vuetify One
Sign in to Vuetify One

Access premium tools across the Vuetify ecosystem — Bin, Play, Studio, and more.

Not a subscriber? See what's included

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.

Edit
Report a Bug
Issues
Source
Markdown

PreviewIntermediateOct 20, 2026

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.

vue
<script setup lang="ts">
  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 container
</script>

<template>
  <div ref="container">
    <!-- Items go here -->
  </div>
</template>

Context / DI

Use createOverflowContext to share an overflow instance across a component tree:

ts
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 fit

Use useOverflow to inject the default (unnamespaced) overflow context provided by a parent:

ts
import { useOverflow } from '@vuetify/v0'

const overflow = useOverflow()  // Injects the nearest provided overflow context

Architecture

createOverflow uses ResizeObserver to compute container capacity:

Overflow Detection Flow

Use controls to zoom and pan. Click outside or press Escape to close.

Overflow Detection Flow

Options

OptionTypeDefaultNotes
gapMaybeRefOrGetter<number>0Gap between items in pixels
reservedMaybeRefOrGetter<number>0Reserved space in pixels (nav buttons, ellipsis, etc.)
itemWidthMaybeRefOrGetter<number>—Uniform item width; enables uniform mode
probebooleanfalseAsk for a count beyond the mounted children, then correct it with settle()
maxMaybeRefOrGetter<number>—Largest count probe mode may ask for
budgetMaybeRefOrGetter<number>—Content-box width in pixels. When omitted, probe mode claims free space in the parent

Reactivity

Property/MethodReactiveNotes
containerShallowRef, assign element for tracking
widthShallowRef, readonly (from ResizeObserver)
capacityComputed from width and measurements
totalComputed, sum of all item widths
isOverflowingComputed from total vs available width
settle()—Probe mode only. Call after measuring the row you were asked to render

Examples

Collapsing Navigation Bar

A responsive nav bar that shows as many destinations as fit and folds the rest into a +N more Popover menu. The composable owns the destination list and a single createOverflow instance configured with gap and a reserved band that keeps room for the overflow trigger; the display component supplies its <ul> as the tracked container and reads capacity to decide how many items stay inline, isOverflowing to decide whether the trigger renders, and hidden to populate the menu. Use the width presets in the entry to drive the container narrower and wider without resizing the browser.

Each NavItem measures its own element exactly once on mount — while capacity is still Infinity and every item is visible — then toggles with v-show instead of unmounting. Because the measured widths stay in the map after an item is hidden, capacity recomputes correctly in both directions: the bar collapses as the container shrinks and restores items as it grows. A naive slice(0, capacity) that unmounts overflowing items throws their widths away, so the bar can collapse but never recover — measuring every item and hiding with v-show is what makes the demo bidirectional, and it mirrors how the Overflow component works internally.

Reach for createOverflow directly when you need full control over how truncation is presented — an overflow menu, a breadcrumb ellipsis, or a responsive toolbar. When the default presentation is enough, the Overflow component wraps this composable with item registration and an indicator slot. For windowing a long scrollable list instead of a single row, see createVirtual.

FileRole
useOverflowNav.tsOwns the destination data and the createOverflow instance; derives the hidden slice and exposes a measure helper
NavItem.vueRenders one destination and self-measures its element on mount, toggling visibility with v-show
OverflowNav.vueBinds the container, renders the items and the +N more Popover menu, and shows a live capacity readout
overflow-nav.vueEntry point; constrains the container with width presets to demonstrate responsive recalculation
Container width
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.

Theme
Mode
Palettes
Accessibility

FAQ

Discord
Need help? Join our community for support and discussions ↗

API Reference

The following API details are for the createOverflow composable.
Was this page helpful?

© 2016-1970 Vuetify, LLC
Services
Ctrl+/