Skip to main content
Vuetify0 is now in alpha!
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.

Usage

The createOverflow 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).

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:

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
gapAccepts MaybeRefOrGetter
reservedAccepts MaybeRefOrGetter
itemWidthAccepts MaybeRefOrGetter (uniform mode)

Examples

API Reference

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

Ctrl+/