useStack

Commons
stable

Manages z-index stacking order for overlay components (Dialog, Menu, Tooltip, Drawer, …). Registers the component in the global GLOBAL_STACK array when it becomes active and auto-computes a z-index 10 units above the current topmost overlay. Exposes globalTop (is this the topmost overlay worldwide?) and localTop (does this overlay have no active child overlays?) for pointer-event and close-on-outside-click decisions.

API

Signature

Signature TypeScript complète extraite du fichier du composable.

typescript

useStack uses Vue provide/inject to propagate the local stack context to child overlays. globalTop is updated with a microtask delay to avoid synchronous read-during-write cycles during the activation phase.

Interfaces consommées

IStackProvide

API

Paramètres

Paramètres d'entrée acceptés par ce composable.

isActive
requis
Readonly<Ref<boolean>>
Reactive open/closed state. When it flips to true, useStack registers the component in the global stack and computes a new z-index. When false, the entry is removed and z-index is released.
zIndex
requis
Readonly<Ref<string | number>>
Base z-index to start from when no other overlays are open. Typically comes from the component props (e.g. zIndex="200").
disableGlobalStack
requis
Readonly<Ref<boolean>>
When true, skips registration in GLOBAL_STACK. Use for overlays that manage their own z-index independently (e.g. nested teleport roots) and should not compete with the global stacking order.

API

Valeurs de retour

Propriétés et méthodes exposées par l'objet retourné par le composable.

globalTop
True when this component is the last entry in GLOBAL_STACK (topmost overlay on the page). Updated asynchronously via setTimeout to avoid synchronous circular reads during stack registration.
localTop
True when this overlay has no active child overlays (nothing opened on top of it within its own sub-tree). Used to decide whether clicks on the backdrop should close this overlay.
stackStyles
Style object containing the computed zIndex. Spread onto the overlay root element so it automatically rises above the previous topmost overlay.

Usage

Exemples

Extraits de code prêts à coller.

Overlay component using useStack

vue