Skip to main content
You are viewing Pre-Alpha documentation.
Vuetify0 Logo
Theme
Mode
Accessibility
Vuetify

Sign in

Sign in with your preferred provider to access your account.

useStack

A composable for managing overlay z-index stacking with automatic calculation, scrim integration, and parent/child tracking for nested overlays.


Intermediate98.3% coverageFeb 4, 2026

Installation

Install the Stack plugin in your app’s entry point:

main.ts
import { createApp } from 'vue'
import { createStackPlugin } from '@vuetify/v0'
import App from './App.vue'

const app = createApp(App)

app.use(createStackPlugin())

app.mount('#app')
Tip

For client-side only apps, you can skip plugin installation and use the default stack singleton directly. The plugin is required for SSR to ensure each request gets its own stack instance.

Scrim Integration

Use the Scrim component alongside useStack to provide a backdrop for your overlays. The Scrim automatically positions itself below the topmost overlay:

vue
<script setup lang="ts">
import { Scrim } from '@vuetify/v0'
</script>

<template>
  <Scrim class="fixed inset-0 bg-black/50" />
</template>

The Scrim reads from the same stack context, so its z-index is always coordinated with your registered overlays.

Usage

Use the useStack composable to register an overlay and receive its z-index and position in the stack:

ts
import { shallowRef, watch } from 'vue'
import { useStack } from '@vuetify/v0'

const isOpen = shallowRef(false)

const stack = useStack()
const ticket = stack.register({
  onDismiss: () => { isOpen.value = false }
})

// Activate when opening, deactivate when closing
watch(isOpen, open => {
  if (open) ticket.select()
  else ticket.unselect()
})

// ticket.zIndex.value = 2000 when first overlay
// ticket.zIndex.value = 2010 when second overlay
// ticket.globalTop.value = true when this is the topmost overlay

Architecture

createStack extends createRegistry with z-index management and scrim coordination:

Stack Hierarchy

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

Stack Hierarchy

Examples

Overlay Stack

This example demonstrates overlay stacking with createStack. Each overlay gets an automatically calculated z-index, and the scrim appears below the topmost overlay.

Stack Data Flow

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

Stack Data Flow

File breakdown:

FileRole
context.tsDefines overlay context with open/close methods
StackProvider.vueProvides stack context and renders scrim
StackConsumer.vueDisplays buttons to open overlays at different stack levels
overlays.vueEntry point that composes Provider around Consumer

Key patterns:

  • stack.register({ onDismiss }) creates a ticket for the overlay

  • ticket.select() / ticket.unselect() activates/deactivates the overlay

  • ticket.globalTop determines if this overlay should handle escape key

  • ticket.zIndex provides the z-index value

  • Scrim reads from the stack context to position below the top overlay

Click a button to open an overlay. Open multiple overlays to observe z-index layering.

Stack:
empty

Reactivity

Stack state and ticket properties are reactive for automatic UI updates.

PropertyReactiveNotes
isActiveAny overlays selected
topTopmost overlay ticket
scrimZIndexZ-index for scrim element
isBlockingTop overlay blocks dismissal
ticket zIndexComputed from selection order
ticket globalTopTrue if topmost
ticket isSelectedOverlay active state

API Reference

The following API details are for the useStack composable.

Functions

createStack

(_options?: StackOptions) => R

Creates a new stack instance for managing overlay z-indexes.

createStackContext

(_options?: StackContextOptions) => ContextTrinity<R>

Creates a stack context trinity for provide/inject usage.

createStackPlugin

(_options?: StackPluginOptions) => any

Creates a Vue plugin to provide stack context at app level.

useStack

(namespace?: string) => R

Returns the current stack context.

Options

events

boolean

Enable event emission for registry operations

Default: false

reactive

boolean

Enable reactive behavior for registry operations

Default: false

disabled

MaybeRefOrGetter<boolean>

When true, the entire selection instance is disabled.

enroll

MaybeRefOrGetter<boolean>

When true, newly registered items are automatically selected if not disabled. Useful for pre-selecting items in multi-select scenarios.

mandatory

MaybeRefOrGetter<boolean | "force">

Controls mandatory selection behavior: - `false` (default): No mandatory selection enforcement - `true`: Prevents deselecting the last selected item (user must always have one selected) - `'force'`: Automatically selects the first non-disabled item on registration

multiple

MaybeRefOrGetter<boolean>

When true, treats the selection as an array

baseZIndex

number

Base z-index when stack is empty

Default: 2000

increment

number

Z-index increment between overlays

Default: 10

Properties

collection

ReadonlyMap<ID, Z>

The collection of tickets in the registry

size

number

The number of tickets in the registry

selectedIds

Reactive<Set<ID>>

Set of selected ticket IDs

selectedItems

ComputedRef<Set<E>>

Set of selected ticket instances

selectedValues

ComputedRef<Set<unknown>>

Set of selected ticket values

disabled

MaybeRef<boolean>

Disable state for the entire selection instance

isActive

Readonly<Ref<boolean, boolean>>

Whether any overlays are selected (active)

top

Readonly<Ref<E, E>>

The topmost selected overlay ticket

scrimZIndex

Readonly<Ref<number, number>>

Z-index for the scrim (one below top overlay)

isBlocking

Readonly<Ref<boolean, boolean>>

Whether the topmost overlay blocks scrim clicks

Methods

clear

() => void

Clear the entire registry

has

(id: ID) => boolean

Check if a ticket exists by ID

keys

() => readonly ID[]

Get all registered IDs

browse

(value: Z["value"]) => ID[] | undefined

Browse for an ID(s) by value

lookup

(index: number) => ID | undefined

lookup a ticket by index number

get

(id: ID) => Z | undefined

Get a ticket by ID

upsert

(id: ID, ticket?: Partial<Z>) => Z

Update or insert a ticket by ID

values

() => readonly Z[]

Get all values of registered tickets

entries

() => readonly [ID, Z][]

Get all entries of registered tickets

unregister

(id: ID) => void

Unregister a ticket by ID

reindex

() => void

Reset the index directory and update all tickets

seek

(direction?: "first" | "last", from?: number, predicate?: (ticket) => boolean) => Z | undefined

Seek for a ticket based on direction and optional predicate

on

<K extends Extensible<RegistryEventName>>(event: K, cb: EventHandler<Z, K>) => void

Listen for registry events

off

<K extends Extensible<RegistryEventName>>(event: K, cb: EventHandler<Z, K>) => void

Stop listening for registry events

emit

<K extends Extensible<RegistryEventName>>(event: K, data: EventPayload<Z, K>) => void

Emit an event with data

dispose

() => void

Clears the registry and removes all listeners

offboard

(ids: ID[]) => void

Offboard multiple tickets at once

batch

<R>(fn: () => R) => R

Execute operations in a batch, deferring cache invalidation and event emission until complete

reset

() => void

Clear all selected IDs and reindexes

select

(id: ID) => void

Select a ticket by ID (Toggle ON)

unselect

(id: ID) => void

Unselect a ticket by ID (Toggle OFF)

toggle

(id: ID) => void

Toggles a ticket ON and OFF by ID

selected

(id: ID) => boolean

Check if a ticket is selected by ID

mandate

() => void

Mandates selected ID based on "mandatory" Option

onboard

(registrations: Partial<Z>[]) => E[]

Onboard multiple tickets at once

register

(input?: Partial<Z>) => E

Register an overlay ticket

Was this page helpful?

© 2016-1970 Vuetify, LLC
Ctrl+/