useStack
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
Full TypeScript signature sourced from the composable file.
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.
Consumed interfaces
API
Parameters
Input parameters accepted by this composable.
- isActiverequiredReadonly<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.
- zIndexrequiredReadonly<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").
- disableGlobalStackrequiredReadonly<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
Return values
Properties and methods exposed by the composable return object.
- 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
Examples
Ready-to-paste usage snippets.
Overlay component using useStack