Skip to content

useDrawer

Open a drawer panel programmatically from anywhere.

useDrawer() mirrors useModal exactly, for <SDrawer> instead - a panel sliding in from an edge of the screen, draggable and snap-point aware, rather than a centered dialog.

Usage

vue
<script setup lang="ts">
const { open } = useDrawer()

async function handleFilters() {
  const applied = await open(FilterPanel, {
    props: { category: 'shoes' },
    side: 'bottom',
  })
}
</script>

API

ts
function useDrawer(): {
  open: <T = void>(component: Component, options?: UseDrawerOpenOptions) => Promise<T | undefined>
}

UseDrawerOpenOptions

Same options as useModal, plus a few more unique to a draggable, snap-point-aware panel:

OptionTypeDescription
side'top' | 'right' | 'bottom' | 'left'Which edge the panel slides in from.
handlebooleanWhether a grip bar shows at the top, signaling it's draggable.
snapPoints(number | string)[]Resting heights/widths the panel snaps to while dragging - fractions (0-1), pixels (>1), or CSS length strings.
snapPointnumber | string | nullThe currently active snap point.
snapToSequentialPointsbooleanSnap to the next sequential point one step at a time, instead of whichever is nearest by drag distance.
modalboolean | 'trap-focus''trap-focus' traps focus but allows outside pointer events - see Drawer.
props, title, description, dismissible, overlay, transitionSame as useModal.

Setup

Same as useModal - wrap your app's root with <SApp> once and useDrawer() works anywhere underneath.

Edit this page