Drawer
A panel that slides in from the edge of the screen.
<script setup lang="ts">
import { Drawer } from '@vase-ui/vue/drawer';
import styles from './index.module.css';
const backdropHiddenClass = styles.BackdropHidden;
const backdropLeavingClass = styles.BackdropLeaving;
const popupHiddenClass = styles.PopupHidden;
const popupLeavingClass = styles.PopupLeaving;
</script>
<template>
<Drawer.Root swipe-direction="right">
<Drawer.Trigger :class="styles.Button">Open drawer</Drawer.Trigger>
<Drawer.Portal>
<Transition
:enter-from-class="backdropHiddenClass"
:leave-to-class="backdropHiddenClass"
:leave-active-class="backdropLeavingClass"
appear
>
<Drawer.Backdrop :class="styles.Backdrop" />
</Transition>
<Drawer.Viewport :class="styles.Viewport">
<Transition
:enter-from-class="popupHiddenClass"
:leave-to-class="popupHiddenClass"
:leave-active-class="popupLeavingClass"
appear
>
<Drawer.Popup :class="styles.Popup">
<Drawer.Content :class="styles.Content">
<Drawer.Title :class="styles.Title">Drawer</Drawer.Title>
<Drawer.Description :class="styles.Description">
This is a drawer that slides in from the side. You can swipe to dismiss it.
</Drawer.Description>
<div :class="styles.Actions">
<Drawer.Close :class="styles.Button">Close</Drawer.Close>
</div>
</Drawer.Content>
</Drawer.Popup>
</Transition>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
</template>.Button {
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
height: 2rem;
padding: 0 0.75rem;
margin: 0;
border: 1px solid oklch(14.5% 0 0deg);
background-color: white;
font-family: inherit;
font-size: 0.875rem;
font-weight: 400;
line-height: 1;
white-space: nowrap;
color: oklch(14.5% 0 0deg);
-webkit-user-select: none;
user-select: none;
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
@media (hover: hover) {
&:hover:not(:disabled) {
background-color: oklch(97% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
}
}
&:active:not(:disabled) {
background-color: oklch(92.2% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(37.1% 0 0deg);
}
}
&:disabled {
color: oklch(55.6% 0 0deg);
border-color: oklch(55.6% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
border-color: oklch(70.8% 0 0deg);
}
}
&:focus-visible {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Backdrop {
--backdrop-opacity: 0.2;
--bleed: 3rem;
position: fixed;
inset: 0;
background-color: black;
opacity: calc(var(--backdrop-opacity) * (1 - var(--drawer-swipe-progress)));
transition-duration: 450ms;
transition-property: opacity;
transition-timing-function: cubic-bezier(0.32, 0.72, 0, 1);
/* iOS 26+: Ensure the backdrop covers the entire visible viewport. */
@supports (-webkit-touch-callout: none) {
position: absolute;
min-height: 100dvh;
}
@media (prefers-color-scheme: dark) {
--backdrop-opacity: 0.7;
}
&.BackdropHidden {
opacity: 0;
}
&[data-swiping] {
transition-duration: 0ms;
}
&.BackdropLeaving {
transition-duration: calc(var(--drawer-swipe-strength) * 400ms);
}
}
.Viewport {
--viewport-padding: 0px;
position: fixed;
inset: 0;
display: flex;
justify-content: flex-end;
padding: var(--viewport-padding);
@supports (-webkit-touch-callout: none) {
--viewport-padding: 0.625rem;
}
}
.Popup {
--bleed: 3rem;
box-sizing: border-box;
width: calc(20rem + var(--bleed));
max-width: calc(100% - 3rem + var(--bleed));
height: 100%;
padding: 1.5rem;
padding-right: calc(1.5rem + var(--bleed));
margin-right: calc(-1 * var(--bleed));
border-left: 1px solid oklch(14.5% 0 0deg);
background-color: white;
color: oklch(14.5% 0 0deg);
outline: 0;
box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 12%);
overflow-y: auto;
overscroll-behavior: contain;
touch-action: auto;
transition: transform 450ms cubic-bezier(0.32, 0.72, 0, 1);
will-change: transform;
transform: translateX(var(--drawer-swipe-movement-x));
@media (prefers-color-scheme: dark) {
border-left: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
box-shadow: none;
}
&.PopupHidden {
transform: translateX(calc(100% - var(--bleed) + var(--viewport-padding) + 2px));
}
&.PopupLeaving {
transition-duration: calc(var(--drawer-swipe-strength) * 400ms);
}
@supports (-webkit-touch-callout: none) {
--bleed: 0px;
max-width: calc(100vw - 3rem);
margin-right: 0;
border: 1px solid oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
border: 1px solid white;
}
}
}
.Content {
width: 100%;
max-width: 32rem;
margin: 0 auto;
}
.Title {
margin-top: 0;
margin-bottom: 0.25rem;
font-size: 1rem;
line-height: 1.5rem;
font-weight: 700;
}
.Description {
margin: 0 0 1.5rem;
font-size: 0.875rem;
line-height: 1.25rem;
color: oklch(43.9% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
.Actions {
display: flex;
justify-content: flex-end;
gap: 0.75rem;
}<script setup lang="ts">
import { Drawer } from '@vase-ui/vue/drawer';
const backdropHiddenClass = 'opacity-0!';
const backdropLeavingClass = 'duration-[calc(var(--drawer-swipe-strength)*400ms)]!';
const popupHiddenClass =
'[transform:translateX(calc(100%-var(--bleed)+var(--viewport-padding)+2px))]!';
const popupLeavingClass = 'duration-[calc(var(--drawer-swipe-strength)*400ms)]!';
</script>
<template>
<Drawer.Root swipe-direction="right">
<Drawer.Trigger
class="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-disabled:bg-neutral-100 active:not-disabled:bg-neutral-200 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-disabled:bg-neutral-800 dark:active:not-disabled:bg-neutral-700 dark:disabled:border-neutral-400 dark:disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
>Open drawer</Drawer.Trigger
>
<Drawer.Portal>
<Transition
:enter-from-class="backdropHiddenClass"
:leave-to-class="backdropHiddenClass"
:leave-active-class="backdropLeavingClass"
appear
>
<Drawer.Backdrop
class="[--backdrop-opacity:0.2] [--bleed:3rem] dark:[--backdrop-opacity:0.7] fixed inset-0 bg-black opacity-[calc(var(--backdrop-opacity)*(1-var(--drawer-swipe-progress)))] transition-opacity duration-[450ms] ease-[cubic-bezier(0.32,0.72,0,1)] data-swiping:duration-0 supports-[-webkit-touch-callout:none]:absolute supports-[-webkit-touch-callout:none]:min-h-dvh"
/>
</Transition>
<Drawer.Viewport
class="[--viewport-padding:0px] supports-[-webkit-touch-callout:none]:[--viewport-padding:0.625rem] fixed inset-0 flex items-stretch justify-end p-(--viewport-padding)"
>
<Transition
:enter-from-class="popupHiddenClass"
:leave-to-class="popupHiddenClass"
:leave-active-class="popupLeavingClass"
appear
>
<Drawer.Popup
class="[--bleed:3rem] supports-[-webkit-touch-callout:none]:[--bleed:0px] h-full w-[calc(20rem+3rem)] max-w-[calc(100%-3rem+3rem)] -mr-[3rem] border-l border-neutral-950 bg-white p-6 pr-[calc(1.5rem+3rem)] text-neutral-950 outline-none shadow-[0.25rem_0.25rem_0] shadow-black/12 overflow-y-auto overscroll-contain touch-auto [transform:translateX(var(--drawer-swipe-movement-x))] transition-transform duration-[450ms] ease-[cubic-bezier(0.32,0.72,0,1)] data-swiping:select-none supports-[-webkit-touch-callout:none]:mr-0 supports-[-webkit-touch-callout:none]:w-[20rem] supports-[-webkit-touch-callout:none]:max-w-[calc(100vw-3rem)] supports-[-webkit-touch-callout:none]:border supports-[-webkit-touch-callout:none]:pr-6 dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none"
>
<Drawer.Content class="mx-auto w-full max-w-[32rem]">
<Drawer.Title class="mb-1 text-base font-bold">Drawer</Drawer.Title>
<Drawer.Description class="mb-6 text-sm text-neutral-600 dark:text-neutral-400">
This is a drawer that slides in from the side. You can swipe to dismiss it.
</Drawer.Description>
<div class="flex justify-end gap-3">
<Drawer.Close
class="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-disabled:bg-neutral-100 active:not-disabled:bg-neutral-200 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-disabled:bg-neutral-800 dark:active:not-disabled:bg-neutral-700 dark:disabled:border-neutral-400 dark:disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
>Close</Drawer.Close
>
</div>
</Drawer.Content>
</Drawer.Popup>
</Transition>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
</template>Usage guidelines
- Drawer extends Dialog: It adds swipe gestures, snap points and indent effects. If you do not need these, use Dialog. A panel that slides in from the edge of the screen and needs no swipe gestures is a positioned Dialog.
Anatomy
Import the component and assemble its parts:
<script setup lang="ts">
import { Drawer } from '@vase-ui/vue/drawer';
</script>
<template>
<Drawer.Provider>
<Drawer.IndentBackground />
<Drawer.Indent>
<Drawer.Root>
<Drawer.Trigger />
<Drawer.SwipeArea />
<Drawer.Portal>
<Transition name="fade" appear>
<Drawer.Backdrop />
</Transition>
<Drawer.Viewport>
<Transition name="sheet" appear>
<Drawer.Popup>
<Drawer.Content>
<Drawer.Title />
<Drawer.Description />
<Drawer.Close />
</Drawer.Content>
</Drawer.Popup>
</Transition>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
</Drawer.Indent>
</Drawer.Provider>
</template>Examples
State
By default, Drawer is an uncontrolled component that keeps its own state.
<script setup lang="ts">
import { Drawer } from '@vase-ui/vue/drawer';
</script>
<template>
<Drawer.Root>
<Drawer.Trigger>Open</Drawer.Trigger>
<Drawer.Portal>
<Drawer.Viewport>
<Transition name="sheet" appear>
<Drawer.Popup>
<Drawer.Content>
<Drawer.Title>Example drawer</Drawer.Title>
<Drawer.Close>Close</Drawer.Close>
</Drawer.Content>
</Drawer.Popup>
</Transition>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
</template>To read or control the open state, bind it with v-model:open.
<script setup lang="ts">
import { shallowRef } from 'vue';
import { Drawer } from '@vase-ui/vue/drawer';
const open = shallowRef(false);
</script>
<template>
<Drawer.Root v-model:open="open">
<Drawer.Trigger>Open</Drawer.Trigger>
<Drawer.Portal>
<Drawer.Viewport>
<Transition name="sheet" appear>
<Drawer.Popup>
<Drawer.Content>
<Drawer.Title>Example drawer</Drawer.Title>
<Drawer.Close>Close</Drawer.Close>
</Drawer.Content>
</Drawer.Popup>
</Transition>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
</template>Position
Your styles position the drawer. swipeDirection is "down" by default, for a bottom sheet. Use "up", "left" or "right" for the other positions.
<script setup lang="ts">
import { Drawer } from '@vase-ui/vue/drawer';
</script>
<template>
<Drawer.Root swipe-direction="right">
<Drawer.Trigger>Open</Drawer.Trigger>
<Drawer.Portal>
<Drawer.Viewport>
<Transition name="sheet" appear>
<Drawer.Popup>Drawer</Drawer.Popup>
</Transition>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
</template><script setup lang="ts">
import { Drawer } from '@vase-ui/vue/drawer';
import styles from './index.module.css';
const backdropHiddenClass = styles.BackdropHidden;
const backdropLeavingClass = styles.BackdropLeaving;
const popupHiddenClass = styles.PopupHidden;
const popupLeavingClass = styles.PopupLeaving;
</script>
<template>
<Drawer.Root>
<Drawer.Trigger :class="styles.Button">Open bottom drawer</Drawer.Trigger>
<Drawer.Portal>
<Transition
:enter-from-class="backdropHiddenClass"
:leave-to-class="backdropHiddenClass"
:leave-active-class="backdropLeavingClass"
appear
>
<Drawer.Backdrop :class="styles.Backdrop" />
</Transition>
<Drawer.Viewport :class="styles.Viewport">
<Transition
:enter-from-class="popupHiddenClass"
:leave-to-class="popupHiddenClass"
:leave-active-class="popupLeavingClass"
appear
>
<Drawer.Popup :class="styles.Popup">
<div :class="styles.Handle" />
<Drawer.Content :class="styles.Content">
<Drawer.Title :class="styles.Title">Notifications</Drawer.Title>
<Drawer.Description :class="styles.Description">
You are all caught up. Good job!
</Drawer.Description>
<div :class="styles.Actions">
<Drawer.Close :class="styles.Button">Close</Drawer.Close>
</div>
</Drawer.Content>
</Drawer.Popup>
</Transition>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
</template>.Button {
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
height: 2rem;
padding: 0 0.75rem;
margin: 0;
border: 1px solid oklch(14.5% 0 0deg);
background-color: white;
font-family: inherit;
font-size: 0.875rem;
font-weight: 400;
line-height: 1;
white-space: nowrap;
color: oklch(14.5% 0 0deg);
-webkit-user-select: none;
user-select: none;
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
@media (hover: hover) {
&:hover:not(:disabled) {
background-color: oklch(97% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
}
}
&:active:not(:disabled) {
background-color: oklch(92.2% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(37.1% 0 0deg);
}
}
&:disabled {
color: oklch(55.6% 0 0deg);
border-color: oklch(55.6% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
border-color: oklch(70.8% 0 0deg);
}
}
&:focus-visible {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Backdrop {
--backdrop-opacity: 0.2;
--bleed: 3rem;
position: fixed;
inset: 0;
background-color: black;
opacity: calc(var(--backdrop-opacity) * (1 - var(--drawer-swipe-progress)));
transition-duration: 450ms;
transition-property: opacity;
transition-timing-function: cubic-bezier(0.32, 0.72, 0, 1);
/* iOS 26+: Ensure the backdrop covers the entire visible viewport. */
@supports (-webkit-touch-callout: none) {
min-height: 100dvh;
}
@media (prefers-color-scheme: dark) {
--backdrop-opacity: 0.7;
}
&.BackdropHidden {
opacity: 0;
}
&[data-swiping] {
transition-duration: 0ms;
}
&.BackdropLeaving {
transition-duration: calc(var(--drawer-swipe-strength) * 400ms);
}
}
.Viewport {
position: fixed;
inset: 0;
display: flex;
align-items: flex-end;
justify-content: center;
}
.Popup {
--bleed: 3rem;
box-sizing: border-box;
width: 100%;
max-height: calc(80% + var(--bleed));
margin-bottom: calc(-1 * var(--bleed));
padding: 1rem 1.5rem 1.5rem;
padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px) + var(--bleed));
border-top: 1px solid oklch(14.5% 0 0deg);
background-color: white;
color: oklch(14.5% 0 0deg);
outline: 0;
box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 12%);
overflow-y: auto;
overscroll-behavior: contain;
transition: transform 450ms cubic-bezier(0.32, 0.72, 0, 1);
will-change: transform;
transform: translateY(var(--drawer-swipe-movement-y));
@supports (-webkit-touch-callout: none) {
max-height: calc(80vh + var(--bleed));
}
@media (prefers-color-scheme: dark) {
border-top: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
box-shadow: none;
}
&.PopupHidden {
transform: translateY(calc(100% - var(--bleed) + 2px));
}
&.PopupLeaving {
transition-duration: calc(var(--drawer-swipe-strength) * 400ms);
}
}
.Content {
width: 100%;
max-width: 32rem;
margin: 0 auto;
}
.Handle {
width: 3rem;
height: 0.25rem;
margin: 0 auto 1rem;
background-color: oklch(87% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(37.1% 0 0deg);
}
}
.Title {
margin-top: 0;
margin-bottom: 0.25rem;
font-size: 1rem;
line-height: 1.5rem;
font-weight: 700;
text-align: center;
}
.Description {
margin: 0 0 1.5rem;
font-size: 0.875rem;
line-height: 1.25rem;
color: oklch(43.9% 0 0deg);
text-align: center;
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
.Actions {
display: flex;
justify-content: center;
gap: 0.75rem;
}<script setup lang="ts">
import { Drawer } from '@vase-ui/vue/drawer';
const backdropHiddenClass = 'opacity-0!';
const backdropLeavingClass = 'duration-[calc(var(--drawer-swipe-strength)*400ms)]!';
const popupHiddenClass = '[transform:translateY(calc(100%-3rem+2px))]!';
const popupLeavingClass = 'duration-[calc(var(--drawer-swipe-strength)*400ms)]!';
</script>
<template>
<Drawer.Root>
<Drawer.Trigger
class="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-disabled:bg-neutral-100 active:not-disabled:bg-neutral-200 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-disabled:bg-neutral-800 dark:active:not-disabled:bg-neutral-700 dark:disabled:border-neutral-400 dark:disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
>Open bottom drawer</Drawer.Trigger
>
<Drawer.Portal>
<Transition
:enter-from-class="backdropHiddenClass"
:leave-to-class="backdropHiddenClass"
:leave-active-class="backdropLeavingClass"
appear
>
<Drawer.Backdrop
class="[--backdrop-opacity:0.2] [--bleed:3rem] dark:[--backdrop-opacity:0.7] fixed inset-0 bg-black opacity-[calc(var(--backdrop-opacity)*(1-var(--drawer-swipe-progress)))] transition-opacity duration-[450ms] ease-[cubic-bezier(0.32,0.72,0,1)] data-swiping:duration-0 supports-[-webkit-touch-callout:none]:absolute supports-[-webkit-touch-callout:none]:min-h-dvh"
/>
</Transition>
<Drawer.Viewport class="fixed inset-0 flex items-end justify-center">
<Transition
:enter-from-class="popupHiddenClass"
:leave-to-class="popupHiddenClass"
:leave-active-class="popupLeavingClass"
appear
>
<Drawer.Popup
class="-mb-[3rem] w-full max-h-[calc(80%+3rem)] supports-[-webkit-touch-callout:none]:max-h-[calc(80vh+3rem)] border-t border-neutral-950 bg-white px-6 pb-[calc(1.5rem+env(safe-area-inset-bottom,0px)+3rem)] pt-4 text-neutral-950 outline-none shadow-[0.25rem_0.25rem_0] shadow-black/12 overflow-y-auto overscroll-contain touch-auto [transform:translateY(var(--drawer-swipe-movement-y))] transition-transform duration-[450ms] ease-[cubic-bezier(0.32,0.72,0,1)] data-swiping:select-none dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none"
>
<div class="mx-auto mb-4 h-1 w-12 bg-neutral-300 dark:bg-neutral-700" />
<Drawer.Content class="mx-auto w-full max-w-[32rem]">
<Drawer.Title class="mb-1 text-base font-bold text-center"
>Notifications</Drawer.Title
>
<Drawer.Description
class="mb-6 text-sm text-neutral-600 text-center dark:text-neutral-400"
>
You are all caught up. Good job!
</Drawer.Description>
<div class="flex justify-center gap-3">
<Drawer.Close
class="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-disabled:bg-neutral-100 active:not-disabled:bg-neutral-200 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-disabled:bg-neutral-800 dark:active:not-disabled:bg-neutral-700 dark:disabled:border-neutral-400 dark:disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
>Close</Drawer.Close
>
</div>
</Drawer.Content>
</Drawer.Popup>
</Transition>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
</template>Nested drawers
Use the [data-nested-drawer-open] selector and the --nested-drawers CSS variable to style a drawer while a nested drawer is open. A drawer is nested when its Drawer.Root is in another Drawer.Root.
This demo stacks nested drawers with a constant peek. The frontmost drawer stays at the bottom, and the drawers behind it become smaller and move up. The demo also uses the --drawer-height and --drawer-frontmost-height CSS variables for drawers of different heights.
<script setup lang="ts">
import { Drawer } from '@vase-ui/vue/drawer';
import styles from './index.module.css';
</script>
<template>
<Drawer.Root>
<Drawer.Trigger :class="styles.Button">Open drawer stack</Drawer.Trigger>
<Drawer.Portal>
<Transition
:enter-from-class="styles.BackdropHidden"
:leave-to-class="styles.BackdropHidden"
:leave-active-class="styles.BackdropLeaving"
appear
>
<Drawer.Backdrop :class="styles.Backdrop" />
</Transition>
<Drawer.Viewport :class="styles.Viewport">
<Transition
:enter-from-class="styles.PopupHidden"
:leave-to-class="styles.PopupHidden"
:leave-active-class="styles.PopupLeaving"
appear
>
<Drawer.Popup :class="styles.Popup">
<div :class="styles.Handle" />
<Drawer.Content :class="styles.Content">
<Drawer.Title :class="styles.Title">Account</Drawer.Title>
<Drawer.Description :class="styles.Description">
Nested drawers can be styled to stack, while each drawer remains independently focus
managed.
</Drawer.Description>
<div :class="styles.Actions">
<div :class="styles.ActionsLeft">
<Drawer.Root>
<Drawer.Trigger :class="styles.Button">Security settings</Drawer.Trigger>
<Drawer.Portal>
<Drawer.Viewport :class="styles.Viewport">
<Transition
:enter-from-class="styles.PopupHidden"
:leave-to-class="styles.PopupHidden"
:leave-active-class="styles.PopupLeaving"
appear
>
<Drawer.Popup :class="styles.Popup">
<div :class="styles.Handle" />
<Drawer.Content :class="styles.Content">
<Drawer.Title :class="styles.Title">Security</Drawer.Title>
<Drawer.Description :class="styles.Description">
Review sign-in activity and update your security preferences.
</Drawer.Description>
<ul :class="styles.List">
<li>Passkeys enabled</li>
<li>2FA via authenticator app</li>
<li>3 signed-in devices</li>
</ul>
<div :class="styles.Actions">
<div :class="styles.ActionsLeft">
<Drawer.Root>
<Drawer.Trigger :class="styles.Button">
Advanced options
</Drawer.Trigger>
<Drawer.Portal>
<Drawer.Viewport :class="styles.Viewport">
<Transition
:enter-from-class="styles.PopupHidden"
:leave-to-class="styles.PopupHidden"
:leave-active-class="styles.PopupLeaving"
appear
>
<Drawer.Popup :class="styles.Popup">
<div :class="styles.Handle" />
<Drawer.Content :class="styles.Content">
<Drawer.Title :class="styles.Title"
>Advanced</Drawer.Title
>
<Drawer.Description :class="styles.Description">
This drawer is taller to demonstrate variable-height
stacking.
</Drawer.Description>
<div :class="styles.Field">
<label :class="styles.Label" for="device-name">
Device name
</label>
<input
id="device-name"
:class="styles.Input"
value="Personal laptop"
/>
</div>
<div :class="styles.Field">
<label :class="styles.Label" for="notes"
>Notes</label
>
<textarea
id="notes"
:class="styles.Textarea"
value="Rotate recovery codes and revoke older sessions."
rows="3"
/>
</div>
<div :class="styles.Actions">
<Drawer.Close :class="styles.Button"
>Done</Drawer.Close
>
</div>
</Drawer.Content>
</Drawer.Popup>
</Transition>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
</div>
<Drawer.Close :class="styles.Button">Close</Drawer.Close>
</div>
</Drawer.Content>
</Drawer.Popup>
</Transition>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
</div>
<Drawer.Close :class="styles.Button">Close</Drawer.Close>
</div>
</Drawer.Content>
</Drawer.Popup>
</Transition>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
</template>.Button {
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
height: 2rem;
padding: 0 0.75rem;
margin: 0;
border: 1px solid oklch(14.5% 0 0deg);
background-color: white;
font-family: inherit;
font-size: 0.875rem;
font-weight: 400;
line-height: 1;
white-space: nowrap;
color: oklch(14.5% 0 0deg);
-webkit-user-select: none;
user-select: none;
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
@media (hover: hover) {
&:hover:not(:disabled) {
background-color: oklch(97% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
}
}
&:active:not(:disabled) {
background-color: oklch(92.2% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(37.1% 0 0deg);
}
}
&:disabled {
color: oklch(55.6% 0 0deg);
border-color: oklch(55.6% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
border-color: oklch(70.8% 0 0deg);
}
}
&:focus-visible {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Backdrop {
--backdrop-opacity: 0.2;
--bleed: 3rem;
position: fixed;
inset: 0;
background-color: black;
opacity: calc(var(--backdrop-opacity) * (1 - var(--drawer-swipe-progress)));
transition-duration: 450ms;
transition-property: opacity;
transition-timing-function: cubic-bezier(0.32, 0.72, 0, 1);
/* iOS 26+: Ensure the backdrop covers the entire visible viewport. */
@supports (-webkit-touch-callout: none) {
min-height: 100dvh;
}
@media (prefers-color-scheme: dark) {
--backdrop-opacity: 0.7;
}
&.BackdropHidden {
opacity: 0;
}
&[data-swiping] {
transition-duration: 0ms;
}
&.BackdropLeaving {
pointer-events: none;
transition-duration: calc(var(--drawer-swipe-strength) * 400ms);
}
}
.Viewport {
position: fixed;
inset: 0;
display: flex;
align-items: flex-end;
justify-content: center;
}
.Popup {
--bleed: 3rem;
--peek: 1rem;
--stack-progress: clamp(0, var(--drawer-swipe-progress), 1);
--stack-step: 0.05;
--stack-peek-offset: max(
0px,
calc((var(--nested-drawers) - var(--stack-progress)) * var(--peek))
);
--stack-scale-base: max(0, calc(1 - (var(--nested-drawers) * var(--stack-step))));
--stack-scale: calc(var(--stack-scale-base) + (var(--stack-step) * var(--stack-progress)));
--stack-shrink: calc(1 - var(--stack-scale));
--stack-height: max(
0px,
calc(var(--drawer-frontmost-height, var(--drawer-height)) - var(--bleed))
);
--translate-y: calc(
var(--drawer-swipe-movement-y) - var(--stack-peek-offset) -
(var(--stack-shrink) * var(--stack-height))
);
box-sizing: border-box;
position: relative;
width: calc(100% + 2px);
margin-left: -1px;
margin-right: -1px;
max-height: calc(80% + var(--bleed));
height: var(--drawer-height, auto);
margin-bottom: calc(-1 * var(--bleed));
padding: 1rem 1.5rem 1.5rem;
padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px) + var(--bleed));
border-width: 1px 1px 0;
border-style: solid;
border-color: oklch(14.5% 0 0deg);
background-color: white;
color: oklch(14.5% 0 0deg);
outline: 0;
box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 12%);
overflow-y: auto;
overscroll-behavior: contain;
transform-origin: 50% calc(100% - var(--bleed));
transition:
transform 450ms cubic-bezier(0.32, 0.72, 0, 1),
height 450ms cubic-bezier(0.32, 0.72, 0, 1),
opacity 450ms cubic-bezier(0.32, 0.72, 0, 1);
will-change: transform;
transform: translateY(var(--translate-y)) scale(var(--stack-scale));
@supports (-webkit-touch-callout: none) {
max-height: calc(80vh + var(--bleed));
}
@media (prefers-color-scheme: dark) {
border-color: white;
background-color: oklch(14.5% 0 0deg);
color: white;
box-shadow: none;
}
&[data-swiping],
&[data-nested-drawer-swiping] {
transition-duration: 0ms;
}
&::after {
content: '';
inset: 0;
position: absolute;
background-color: transparent;
pointer-events: none;
transition: background-color 450ms cubic-bezier(0.32, 0.72, 0, 1);
}
&[data-nested-drawer-open] {
height: calc(var(--stack-height) + var(--bleed));
overflow: hidden;
&::after {
background-color: rgb(0 0 0 / 0.05);
}
}
&.PopupHidden {
transform: translateY(calc(100% - var(--bleed) + 2px));
}
&.PopupLeaving {
opacity: 0.9999;
transition-duration: calc(var(--drawer-swipe-strength) * 400ms);
}
}
.Content {
width: 100%;
max-width: 32rem;
margin: 0 auto;
transition: opacity 300ms cubic-bezier(0.45, 1.005, 0, 1.005);
[data-nested-drawer-open] & {
opacity: 0;
}
[data-nested-drawer-open][data-nested-drawer-swiping] & {
opacity: 1;
}
}
.Handle {
width: 3rem;
height: 0.25rem;
margin: 0 auto 1rem;
background-color: oklch(87% 0 0deg);
transition: opacity 0.2s;
@media (prefers-color-scheme: dark) {
background-color: oklch(37.1% 0 0deg);
}
[data-nested-drawer-open] & {
opacity: 0;
}
[data-nested-drawer-open][data-nested-drawer-swiping] & {
opacity: 1;
}
}
.Title {
margin-top: 0;
margin-bottom: 0.25rem;
font-size: 1rem;
line-height: 1.5rem;
font-weight: 700;
text-align: center;
}
.Description {
margin: 0 0 1.5rem;
font-size: 0.875rem;
line-height: 1.25rem;
color: oklch(43.9% 0 0deg);
text-align: center;
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
.Actions {
display: flex;
align-items: center;
justify-content: end;
gap: 1rem;
}
.ActionsLeft {
margin-right: auto;
}
.List {
margin: 0 0 1.5rem;
padding-left: 1.25rem;
color: oklch(37.1% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(87% 0 0deg);
}
}
.Field {
display: grid;
gap: 0.5rem;
margin-bottom: 1rem;
}
.Label {
font-size: 0.925rem;
line-height: 1.25rem;
font-weight: 700;
color: oklch(37.1% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(87% 0 0deg);
}
}
.Input {
box-sizing: border-box;
width: 100%;
height: 2rem;
padding: 0 0.5rem;
margin: 0;
border: 1px solid oklch(14.5% 0 0deg);
border-radius: 0;
font-family: inherit;
font-size: 0.875rem;
line-height: 1.25rem;
font-weight: 400;
background-color: white;
color: oklch(14.5% 0 0deg);
@media (any-pointer: coarse) {
font-size: 1rem;
line-height: 1.5rem;
}
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
&::placeholder {
color: oklch(55.6% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
&:focus {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Textarea {
box-sizing: border-box;
width: 100%;
min-height: 8rem;
padding: 0.5rem 0.625rem;
margin: 0;
border: 1px solid oklch(14.5% 0 0deg);
border-radius: 0;
font-family: inherit;
font-size: 0.875rem;
font-weight: 400;
line-height: 1.25rem;
background-color: white;
color: oklch(14.5% 0 0deg);
resize: vertical;
@media (any-pointer: coarse) {
font-size: 1rem;
line-height: 1.5rem;
}
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
&::placeholder {
color: oklch(55.6% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
&:focus {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Input:focus-visible,
.Textarea:focus-visible {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}<script setup lang="ts">
import { Drawer } from '@vase-ui/vue/drawer';
const popupClassName =
"[--bleed:3rem] [--peek:1rem] [--stack-progress:clamp(0,var(--drawer-swipe-progress),1)] [--stack-step:0.05] [--stack-peek-offset:max(0px,calc((var(--nested-drawers)-var(--stack-progress))*var(--peek)))] [--scale-base:calc(max(0,1-(var(--nested-drawers)*var(--stack-step))))] [--scale:clamp(0,calc(var(--scale-base)+(var(--stack-step)*var(--stack-progress))),1)] [--shrink:calc(1-var(--scale))] [--height:max(0px,calc(var(--drawer-frontmost-height,var(--drawer-height))-var(--bleed)))] group/popup relative -mx-px -mb-[3rem] w-[calc(100%+2px)] max-h-[calc(80%+3rem)] supports-[-webkit-touch-callout:none]:max-h-[calc(80vh+3rem)] [height:var(--drawer-height,auto)] border border-neutral-950 border-b-0 bg-white px-6 pt-4 pb-[calc(1.5rem+env(safe-area-inset-bottom,0px)+3rem)] text-neutral-950 outline-none shadow-[0.25rem_0.25rem_0] shadow-black/12 overflow-y-auto overscroll-contain touch-auto [transform-origin:50%_calc(100%-var(--bleed))] [transform:translateY(calc(var(--drawer-swipe-movement-y)-var(--stack-peek-offset)-(var(--shrink)*var(--height))))_scale(var(--scale))] after:pointer-events-none after:absolute after:inset-0 after:bg-transparent after:content-[''] after:transition-[background-color] after:duration-[450ms] after:ease-[cubic-bezier(0.32,0.72,0,1)] data-swiping:select-none data-swiping:duration-0 data-nested-drawer-swiping:duration-0 data-nested-drawer-open:h-[calc(var(--height)+var(--bleed))] data-nested-drawer-open:overflow-hidden data-nested-drawer-open:after:bg-black/5 dark:border-white dark:border-b-0 dark:bg-neutral-950 dark:text-white dark:shadow-none [transition:transform_450ms_cubic-bezier(0.32,0.72,0,1),height_450ms_cubic-bezier(0.32,0.72,0,1),opacity_450ms_cubic-bezier(0.32,0.72,0,1)]";
const popupHiddenClass = '[transform:translateY(calc(100%-var(--bleed)+2px))]!';
const popupLeavingClass =
'opacity-[0.9999]! duration-[calc(var(--drawer-swipe-strength)*400ms)]! data-swiping:duration-[calc(var(--drawer-swipe-strength)*400ms)]! data-nested-drawer-swiping:duration-[calc(var(--drawer-swipe-strength)*400ms)]!';
const contentClassName =
'mx-auto w-full max-w-[32rem] transition-opacity duration-[300ms] ease-[cubic-bezier(0.45,1.005,0,1.005)] group-data-nested-drawer-open/popup:opacity-0 group-data-nested-drawer-swiping/popup:opacity-100';
const handleClassName =
'mx-auto mb-4 h-1 w-12 bg-neutral-300 transition-opacity duration-[200ms] group-data-nested-drawer-open/popup:opacity-0 group-data-nested-drawer-swiping/popup:opacity-100 dark:bg-neutral-700';
</script>
<template>
<Drawer.Root>
<Drawer.Trigger
class="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-disabled:bg-neutral-100 active:not-disabled:bg-neutral-200 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-disabled:bg-neutral-800 dark:active:not-disabled:bg-neutral-700 dark:disabled:border-neutral-400 dark:disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
>Open drawer stack</Drawer.Trigger
>
<Drawer.Portal>
<Transition
enter-from-class="opacity-0!"
leave-to-class="opacity-0!"
leave-active-class="duration-[calc(var(--drawer-swipe-strength)*400ms)]!"
appear
>
<Drawer.Backdrop
class="[--backdrop-opacity:0.2] [--bleed:3rem] dark:[--backdrop-opacity:0.7] fixed inset-0 bg-black opacity-[calc(var(--backdrop-opacity)*(1-var(--drawer-swipe-progress)))] transition-opacity duration-[450ms] ease-[cubic-bezier(0.32,0.72,0,1)] data-swiping:duration-0 supports-[-webkit-touch-callout:none]:absolute supports-[-webkit-touch-callout:none]:min-h-dvh"
/>
</Transition>
<Drawer.Viewport class="fixed inset-0 flex items-end justify-center">
<Transition
:enter-from-class="popupHiddenClass"
:leave-to-class="popupHiddenClass"
:leave-active-class="popupLeavingClass"
appear
>
<Drawer.Popup :class="popupClassName">
<div :class="handleClassName" />
<Drawer.Content :class="contentClassName">
<Drawer.Title class="mb-1 text-base font-bold text-center">Account</Drawer.Title>
<Drawer.Description
class="mb-6 text-sm text-neutral-600 text-center dark:text-neutral-400"
>
Nested drawers can be styled to stack, while each drawer remains independently focus
managed.
</Drawer.Description>
<div class="flex items-center justify-end gap-4">
<div class="mr-auto">
<Drawer.Root>
<Drawer.Trigger
class="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-disabled:bg-neutral-100 active:not-disabled:bg-neutral-200 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-disabled:bg-neutral-800 dark:active:not-disabled:bg-neutral-700 dark:disabled:border-neutral-400 dark:disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
>Security settings</Drawer.Trigger
>
<Drawer.Portal>
<Drawer.Viewport class="fixed inset-0 flex items-end justify-center">
<Transition
:enter-from-class="popupHiddenClass"
:leave-to-class="popupHiddenClass"
:leave-active-class="popupLeavingClass"
appear
>
<Drawer.Popup :class="popupClassName">
<div :class="handleClassName" />
<Drawer.Content :class="contentClassName">
<Drawer.Title class="mb-1 text-base font-bold text-center"
>Security</Drawer.Title
>
<Drawer.Description
class="mb-6 text-sm text-neutral-600 text-center dark:text-neutral-400"
>
Review sign-in activity and update your security preferences.
</Drawer.Description>
<ul
class="mb-6 list-disc pl-5 text-neutral-700 dark:text-neutral-300"
>
<li>Passkeys enabled</li>
<li>2FA via authenticator app</li>
<li>3 signed-in devices</li>
</ul>
<div class="flex items-center justify-end gap-4">
<div class="mr-auto">
<Drawer.Root>
<Drawer.Trigger
class="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-disabled:bg-neutral-100 active:not-disabled:bg-neutral-200 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-disabled:bg-neutral-800 dark:active:not-disabled:bg-neutral-700 dark:disabled:border-neutral-400 dark:disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
>
Advanced options
</Drawer.Trigger>
<Drawer.Portal>
<Drawer.Viewport
class="fixed inset-0 flex items-end justify-center"
>
<Transition
:enter-from-class="popupHiddenClass"
:leave-to-class="popupHiddenClass"
:leave-active-class="popupLeavingClass"
appear
>
<Drawer.Popup :class="popupClassName">
<div :class="handleClassName" />
<Drawer.Content :class="contentClassName">
<Drawer.Title
class="mb-1 text-base font-bold text-center"
>Advanced</Drawer.Title
>
<Drawer.Description
class="mb-6 text-sm text-neutral-600 text-center dark:text-neutral-400"
>
This drawer is taller to demonstrate variable-height
stacking.
</Drawer.Description>
<div class="grid gap-2 mb-4">
<label
class="text-sm font-bold text-neutral-700 dark:text-neutral-300"
for="device-name-tw"
>
Device name
</label>
<input
id="device-name-tw"
class="h-8 w-full border border-neutral-950 bg-white px-2 text-sm any-pointer-coarse:text-base font-normal text-neutral-950 dark:border-white dark:bg-neutral-950 dark:text-white focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
value="Personal laptop"
/>
</div>
<div class="grid gap-2 mb-4">
<label
class="text-sm font-bold text-neutral-700 dark:text-neutral-300"
for="notes-tw"
>Notes</label
>
<textarea
id="notes-tw"
class="min-h-32 w-full resize-y border border-neutral-950 bg-white p-2 text-sm any-pointer-coarse:text-base font-normal text-neutral-950 dark:border-white dark:bg-neutral-950 dark:text-white focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
value="Rotate recovery codes and revoke older sessions."
rows="3"
/>
</div>
<div class="flex justify-end">
<Drawer.Close
class="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-disabled:bg-neutral-100 active:not-disabled:bg-neutral-200 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-disabled:bg-neutral-800 dark:active:not-disabled:bg-neutral-700 dark:disabled:border-neutral-400 dark:disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
>Done</Drawer.Close
>
</div>
</Drawer.Content>
</Drawer.Popup>
</Transition>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
</div>
<Drawer.Close
class="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-disabled:bg-neutral-100 active:not-disabled:bg-neutral-200 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-disabled:bg-neutral-800 dark:active:not-disabled:bg-neutral-700 dark:disabled:border-neutral-400 dark:disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
>Close</Drawer.Close
>
</div>
</Drawer.Content>
</Drawer.Popup>
</Transition>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
</div>
<Drawer.Close
class="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-disabled:bg-neutral-100 active:not-disabled:bg-neutral-200 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-disabled:bg-neutral-800 dark:active:not-disabled:bg-neutral-700 dark:disabled:border-neutral-400 dark:disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
>Close</Drawer.Close
>
</div>
</Drawer.Content>
</Drawer.Popup>
</Transition>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
</template>Snap points
Use snapPoints to snap a bottom sheet to preset heights. A number from 0 to 1 is a fraction of the viewport height, and a number greater than 1 is a number of pixels. A string can have the unit px or rem, such as '148px' or '30rem'. Bind the active snap point with v-model:snap-point.
<script setup lang="ts">
import { shallowRef } from 'vue';
import { Drawer } from '@vase-ui/vue/drawer';
const snapPoints = ['148px', 1];
const snapPoint = shallowRef<Drawer.Root.SnapPoint | null>(snapPoints[0]);
</script>
<template>
<Drawer.Root v-model:snap-point="snapPoint" :snap-points="snapPoints">
<Drawer.Trigger>Open</Drawer.Trigger>
<Drawer.Portal>
<Drawer.Viewport>
<Transition name="sheet" appear>
<Drawer.Popup>Drawer</Drawer.Popup>
</Transition>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
</template>Apply the snap point offset in your styles for a vertical drawer:
.DrawerPopup {
transform: translateY(calc(var(--drawer-snap-point-offset) + var(--drawer-swipe-movement-y)));
}<script setup lang="ts">
import { Drawer } from '@vase-ui/vue/drawer';
import styles from './index.module.css';
const TOP_MARGIN_REM = 1;
const VISIBLE_SNAP_POINTS_REM = [30];
function toViewportSnapPoint(heightRem: number) {
return `${heightRem + TOP_MARGIN_REM}rem`;
}
const snapPoints = [...VISIBLE_SNAP_POINTS_REM.map(toViewportSnapPoint), 1];
const backdropHiddenClass = styles.BackdropHidden;
const backdropLeavingClass = styles.BackdropLeaving;
const popupHiddenClass = styles.PopupHidden;
const popupLeavingClass = styles.PopupLeaving;
</script>
<template>
<Drawer.Root :snap-points="snapPoints">
<Drawer.Trigger :class="styles.Button">Open snap drawer</Drawer.Trigger>
<Drawer.Portal>
<Transition
:enter-from-class="backdropHiddenClass"
:leave-to-class="backdropHiddenClass"
:leave-active-class="backdropLeavingClass"
appear
>
<Drawer.Backdrop :class="styles.Backdrop" />
</Transition>
<Drawer.Viewport :class="styles.Viewport">
<Transition
:enter-from-class="popupHiddenClass"
:leave-to-class="popupHiddenClass"
:leave-active-class="popupLeavingClass"
appear
>
<Drawer.Popup :class="styles.Popup" :style="{ '--top-margin': `${TOP_MARGIN_REM}rem` }">
<div :class="styles.DragArea">
<div :class="styles.Handle" />
<Drawer.Title :class="styles.Title">Snap points</Drawer.Title>
</div>
<Drawer.Content :class="styles.Scroll">
<div :class="styles.Content">
<Drawer.Description :class="styles.Description">
Drag the sheet to snap between a compact peek and a near full-height view.
</Drawer.Description>
<div :class="styles.Cards" aria-hidden="true">
<div v-for="index in 20" :key="index" :class="styles.Card" />
</div>
<div :class="styles.Actions">
<Drawer.Close :class="styles.Button">Close</Drawer.Close>
</div>
</div>
</Drawer.Content>
</Drawer.Popup>
</Transition>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
</template>.Button {
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
height: 2rem;
padding: 0 0.75rem;
margin: 0;
border: 1px solid oklch(14.5% 0 0deg);
background-color: white;
font-family: inherit;
font-size: 0.875rem;
font-weight: 400;
line-height: 1;
white-space: nowrap;
color: oklch(14.5% 0 0deg);
-webkit-user-select: none;
user-select: none;
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
@media (hover: hover) {
&:hover:not(:disabled) {
background-color: oklch(97% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
}
}
&:active:not(:disabled) {
background-color: oklch(92.2% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(37.1% 0 0deg);
}
}
&:disabled {
color: oklch(55.6% 0 0deg);
border-color: oklch(55.6% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
border-color: oklch(70.8% 0 0deg);
}
}
&:focus-visible {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Backdrop {
--backdrop-opacity: 0.2;
--bleed: 3rem;
position: fixed;
inset: 0;
background-color: black;
opacity: calc(var(--backdrop-opacity) * (1 - var(--drawer-swipe-progress)));
transition-duration: 450ms;
transition-property: opacity;
transition-timing-function: cubic-bezier(0.32, 0.72, 0, 1);
/* iOS 26+: Ensure the backdrop covers the entire visible viewport. */
@supports (-webkit-touch-callout: none) {
min-height: 100dvh;
}
@media (prefers-color-scheme: dark) {
--backdrop-opacity: 0.7;
}
&.BackdropHidden {
opacity: 0;
}
&[data-swiping] {
transition-duration: 0ms;
}
&.BackdropLeaving {
transition-duration: calc(var(--drawer-swipe-strength) * 400ms);
}
}
.Viewport {
--bleed: 3rem;
position: fixed;
inset: 0;
display: flex;
align-items: flex-end;
justify-content: center;
touch-action: none;
&::after {
content: '';
position: fixed;
inset-inline: 0;
bottom: 0;
height: var(--bleed);
background-color: white;
pointer-events: none;
@media (prefers-color-scheme: dark) {
background-color: oklch(14.5% 0 0deg);
}
}
&:has(> .PopupLeaving)::after {
opacity: 0;
}
}
.Content {
width: 100%;
max-width: 22.5rem;
margin: 0 auto;
}
.Popup {
box-sizing: border-box;
position: relative;
z-index: 1;
display: flex;
flex-direction: column;
width: 100%;
max-height: calc(100% - var(--top-margin));
padding-bottom: max(0px, calc(var(--drawer-snap-point-offset) + var(--drawer-swipe-movement-y)));
border-top: 1px solid oklch(14.5% 0 0deg);
background-color: white;
color: oklch(14.5% 0 0deg);
outline: 0;
overflow: visible;
touch-action: none;
box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 12%);
transition:
transform 450ms cubic-bezier(0.32, 0.72, 0, 1),
box-shadow 450ms cubic-bezier(0.32, 0.72, 0, 1);
transform: translateY(calc(var(--drawer-snap-point-offset) + var(--drawer-swipe-movement-y)));
will-change: transform;
@supports (-webkit-touch-callout: none) {
max-height: calc(100dvh - var(--top-margin));
}
@media (prefers-color-scheme: dark) {
border-top: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
box-shadow: none;
}
&::after {
content: '';
position: absolute;
inset-inline: 0;
top: 100%;
height: var(--bleed);
background-color: inherit;
pointer-events: none;
}
&.PopupHidden {
transform: translateY(calc(100% + 2px));
padding-bottom: 0;
box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 0%);
}
&.PopupLeaving {
transition-duration: calc(var(--drawer-swipe-strength) * 400ms);
}
}
.DragArea {
flex-shrink: 0;
padding: 0.875rem 1.5rem 1rem;
border-bottom: 1px solid oklch(87% 0 0deg);
touch-action: none;
-webkit-user-select: none;
user-select: none;
@media (prefers-color-scheme: dark) {
border-bottom: 1px solid oklch(37.1% 0 0deg);
}
}
.Scroll {
flex: 1 1 auto;
min-height: 0;
overflow-y: auto;
overscroll-behavior: contain;
touch-action: auto;
padding: 1rem 1.5rem calc(1.5rem + env(safe-area-inset-bottom, 0px));
}
.Handle {
width: 3rem;
height: 0.25rem;
margin: 0 auto 0.625rem;
flex-shrink: 0;
background-color: oklch(87% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(37.1% 0 0deg);
}
}
.Title {
margin: 0;
font-size: 1rem;
line-height: 1.5rem;
font-weight: 700;
text-align: center;
cursor: default;
}
.Description {
margin: 0 0 1.5rem;
font-size: 0.875rem;
line-height: 1.25rem;
color: oklch(43.9% 0 0deg);
text-align: center;
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
.Cards {
display: grid;
gap: 0.75rem;
margin: 0 0 1.5rem;
}
.Card {
height: 3rem;
background-color: oklch(92.2% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(37.1% 0 0deg);
}
}
.Actions {
display: flex;
align-items: center;
justify-content: end;
gap: 1rem;
}<script setup lang="ts">
import { Drawer } from '@vase-ui/vue/drawer';
const TOP_MARGIN_REM = 1;
const VISIBLE_SNAP_POINTS_REM = [30];
function toViewportSnapPoint(heightRem: number) {
return `${heightRem + TOP_MARGIN_REM}rem`;
}
const snapPoints = [...VISIBLE_SNAP_POINTS_REM.map(toViewportSnapPoint), 1];
const backdropHiddenClass = 'opacity-0!';
const backdropLeavingClass = 'duration-[calc(var(--drawer-swipe-strength)*400ms)]!';
const popupHiddenClass =
'[transform:translateY(calc(100%+2px))]! [padding-bottom:0]! shadow-[0.25rem_0.25rem_0]! shadow-black/0!';
const popupLeavingClass = 'leaving duration-[calc(var(--drawer-swipe-strength)*400ms)]!';
</script>
<template>
<Drawer.Root :snap-points="snapPoints">
<Drawer.Trigger
class="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-disabled:bg-neutral-100 active:not-disabled:bg-neutral-200 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-disabled:bg-neutral-800 dark:active:not-disabled:bg-neutral-700 dark:disabled:border-neutral-400 dark:disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
>Open snap drawer</Drawer.Trigger
>
<Drawer.Portal>
<Transition
:enter-from-class="backdropHiddenClass"
:leave-to-class="backdropHiddenClass"
:leave-active-class="backdropLeavingClass"
appear
>
<Drawer.Backdrop
class="[--backdrop-opacity:0.2] [--bleed:3rem] dark:[--backdrop-opacity:0.7] fixed inset-0 bg-black opacity-[calc(var(--backdrop-opacity)*(1-var(--drawer-swipe-progress)))] transition-opacity duration-[450ms] ease-[cubic-bezier(0.32,0.72,0,1)] data-swiping:duration-0 supports-[-webkit-touch-callout:none]:absolute supports-[-webkit-touch-callout:none]:min-h-dvh"
/>
</Transition>
<Drawer.Viewport
class="fixed inset-0 flex items-end justify-center touch-none [--bleed:3rem] after:pointer-events-none after:fixed after:inset-x-0 after:bottom-0 after:h-[var(--bleed)] after:bg-white after:content-[''] has-[>.leaving]:after:opacity-0 dark:after:bg-neutral-950"
>
<Transition
:enter-from-class="popupHiddenClass"
:leave-to-class="popupHiddenClass"
:leave-active-class="popupLeavingClass"
appear
>
<Drawer.Popup
class="relative z-1 flex w-full max-h-[calc(100%-var(--top-margin))] supports-[-webkit-touch-callout:none]:max-h-[calc(100dvh-var(--top-margin))] min-h-0 flex-col overflow-visible border-t border-neutral-950 bg-white text-neutral-950 outline-none touch-none shadow-[0.25rem_0.25rem_0] shadow-black/12 [padding-bottom:max(0px,calc(var(--drawer-snap-point-offset)+var(--drawer-swipe-movement-y)))] [transform:translateY(calc(var(--drawer-snap-point-offset)+var(--drawer-swipe-movement-y)))] transition-[transform,box-shadow] duration-[450ms] ease-[cubic-bezier(0.32,0.72,0,1)] after:pointer-events-none after:absolute after:inset-x-0 after:top-full after:h-[var(--bleed)] after:bg-[inherit] after:content-[''] dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none"
:style="{ '--top-margin': `${TOP_MARGIN_REM}rem` }"
>
<div
class="shrink-0 border-b border-neutral-300 px-6 pt-3.5 pb-4 touch-none select-none dark:border-neutral-700"
>
<div class="mx-auto mb-2.5 h-1 w-12 shrink-0 bg-neutral-300 dark:bg-neutral-700" />
<Drawer.Title class="cursor-default text-center text-base font-bold"
>Snap points</Drawer.Title
>
</div>
<Drawer.Content
class="min-h-0 flex-1 overflow-y-auto overscroll-contain touch-auto px-6 pt-4 pb-[calc(1.5rem+env(safe-area-inset-bottom,0px))]"
>
<div class="mx-auto w-full max-w-90">
<Drawer.Description
class="mb-4 text-sm text-neutral-600 text-center dark:text-neutral-400"
>
Drag the sheet to snap between a compact peek and a near full-height view.
</Drawer.Description>
<div class="grid gap-3 mb-6" aria-hidden="true">
<div
v-for="index in 20"
:key="index"
class="h-12 bg-neutral-200 dark:bg-neutral-700"
/>
</div>
<div class="flex items-center justify-end gap-3">
<Drawer.Close
class="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-disabled:bg-neutral-100 active:not-disabled:bg-neutral-200 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-disabled:bg-neutral-800 dark:active:not-disabled:bg-neutral-700 dark:disabled:border-neutral-400 dark:disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
>Close</Drawer.Close
>
</div>
</div>
</Drawer.Content>
</Drawer.Popup>
</Transition>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
</template>By default, a fast swipe can skip snap points. Set snapToSequentialPoints to stop this. The distance of the drag then sets the snap point, and a drag can still go past more than one point.
Virtual keyboard aware
Put a bottom sheet with form controls in Drawer.VirtualKeyboardProvider. When a software keyboard opens, the provider scrolls the body of the drawer to keep the focused field visible.
- Keep the frame of the popup stable: put the header and the footer outside a plain scrollable body.
- Lift an input that is fixed in the footer: reserve a footer slot below the scroll area, and offset it by
var(--drawer-keyboard-inset, 0px). When the input in the footer has the focus, the demo gives the footerposition: fixedand adds the inset to its bottom padding. Thetransformof the popup makes the popup the container of the fixed footer. - Always include the
0pxfallback: the provider sets--drawer-keyboard-insetonly while the keyboard covers the layout viewport. A plainvar(--drawer-keyboard-inset)is thus not valid at other times. - Bind no
padding-bottomon the scroll body: the provider gives the scroll body room below its content withpadding-bottom. Vue writes a boundpadding-bottomagain at each render, and that removes the room.
<script setup lang="ts">
import { Drawer } from '@vase-ui/vue/drawer';
</script>
<template>
<Drawer.Root>
<Drawer.Trigger>Open</Drawer.Trigger>
<Drawer.VirtualKeyboardProvider>
<Drawer.Portal>
<Drawer.Viewport>
<Transition name="sheet" appear>
<Drawer.Popup>
<input aria-label="Name" />
</Drawer.Popup>
</Transition>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.VirtualKeyboardProvider>
</Drawer.Root>
</template><script setup lang="ts">
import { Drawer } from '@vase-ui/vue/drawer';
import styles from './index.module.css';
const fields = [
['Name', 'Ada Lovelace'],
['Phone', '+1 (555) 123-4567'],
['Street address', '12 Computing Way'],
['Apartment', 'Unit 4B'],
['City', 'San Francisco'],
['Postal code', '94107'],
['Delivery window', 'After 6 PM'],
['Backup contact', 'Grace Hopper'],
];
const backdropHiddenClass = styles.BackdropHidden;
const backdropLeavingClass = styles.BackdropLeaving;
const popupHiddenClass = styles.PopupHidden;
const popupLeavingClass = styles.PopupLeaving;
</script>
<template>
<Drawer.Root>
<Drawer.Trigger :class="styles.Button">Open keyboard-aware drawer</Drawer.Trigger>
<Drawer.VirtualKeyboardProvider>
<Drawer.Portal>
<Transition
:enter-from-class="backdropHiddenClass"
:leave-to-class="backdropHiddenClass"
:leave-active-class="backdropLeavingClass"
appear
>
<Drawer.Backdrop :class="styles.Backdrop" />
</Transition>
<Drawer.Viewport :class="styles.Viewport">
<Transition
:enter-from-class="popupHiddenClass"
:leave-to-class="popupHiddenClass"
:leave-active-class="popupLeavingClass"
appear
>
<Drawer.Popup :class="styles.Popup">
<div :class="styles.Header">
<div :class="styles.Handle" />
<div :class="styles.HeaderActions">
<Drawer.Close :class="[styles.Button, styles.HeaderButton]">Cancel</Drawer.Close>
<Drawer.Title :class="styles.Title">Delivery details</Drawer.Title>
<Drawer.Close :class="[styles.Button, styles.HeaderButton]">Save</Drawer.Close>
</div>
</div>
<Drawer.Content :class="styles.Scroll">
<div :class="styles.Form">
<label v-for="[label, placeholder] in fields" :key="label" :class="styles.Field">
<span :class="styles.FieldLabel">{{ label }}</span>
<input :class="styles.Input" :placeholder="placeholder" type="text" />
</label>
<label :class="styles.Field">
<span :class="styles.FieldLabel">Instructions</span>
<textarea
:class="styles.Textarea"
placeholder="Gate code, drop-off spot, or anything else the driver should know"
/>
</label>
</div>
</Drawer.Content>
<div :class="styles.FooterSlot">
<div :class="styles.StickyFooter">
<label :class="styles.Composer">
<span :class="styles.FieldLabel">Delivery note</span>
<input
:class="styles.ComposerInput"
placeholder="Add a note for the driver"
type="text"
/>
</label>
</div>
</div>
</Drawer.Popup>
</Transition>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.VirtualKeyboardProvider>
</Drawer.Root>
</template>.Button {
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
height: 2rem;
padding: 0 0.75rem;
margin: 0;
border: 1px solid oklch(14.5% 0 0deg);
background-color: white;
font-family: inherit;
font-size: 0.875rem;
font-weight: 400;
line-height: 1;
white-space: nowrap;
color: oklch(14.5% 0 0deg);
-webkit-user-select: none;
user-select: none;
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
@media (hover: hover) {
&:hover:not(:disabled) {
background-color: oklch(97% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
}
}
&:active:not(:disabled) {
background-color: oklch(92.2% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(37.1% 0 0deg);
}
}
&:disabled {
color: oklch(55.6% 0 0deg);
border-color: oklch(55.6% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
border-color: oklch(70.8% 0 0deg);
}
}
&:focus-visible {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Backdrop {
--backdrop-opacity: 0.2;
--bleed: 3rem;
position: fixed;
inset: 0;
background-color: black;
opacity: calc(var(--backdrop-opacity) * (1 - var(--drawer-swipe-progress)));
transition-duration: 450ms;
transition-property: opacity;
transition-timing-function: cubic-bezier(0.32, 0.72, 0, 1);
@supports (-webkit-touch-callout: none) {
position: absolute;
min-height: 100dvh;
}
@media (prefers-color-scheme: dark) {
--backdrop-opacity: 0.7;
}
&.BackdropHidden {
opacity: 0;
}
&[data-swiping] {
transition-duration: 0ms;
}
&.BackdropLeaving {
transition-duration: calc(var(--drawer-swipe-strength) * 400ms);
}
}
.Viewport {
--bleed: 3rem;
position: fixed;
inset: 0;
display: flex;
align-items: flex-end;
justify-content: center;
touch-action: none;
&::after {
content: '';
position: fixed;
inset-inline: 0;
bottom: 0;
height: var(--bleed);
background-color: white;
pointer-events: none;
}
@media (prefers-color-scheme: dark) {
&::after {
background-color: oklch(14.5% 0 0deg);
}
}
&:has(> .PopupLeaving)::after {
opacity: 0;
}
/* While swiping, the popup's own bleed covers the bottom edge, so hide the
fixed fill — otherwise it paints white over the backdrop once the popup is
dragged far enough down. */
&:has([data-swiping])::after {
opacity: 0;
}
}
.Popup {
--bleed: 3rem;
--footer-reserved-height: calc(5.25rem + var(--bleed));
box-sizing: border-box;
position: relative;
z-index: 1;
display: flex;
flex-direction: column;
width: 100%;
height: calc(100% - 1rem + var(--bleed));
max-height: calc(100% - 1rem + var(--bleed));
margin-bottom: calc(-1 * var(--bleed));
border-top: 1px solid oklch(14.5% 0 0deg);
background-color: white;
color: oklch(14.5% 0 0deg);
outline: 0;
overflow: visible;
touch-action: none;
box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 12%);
transition:
transform 450ms cubic-bezier(0.32, 0.72, 0, 1),
box-shadow 450ms cubic-bezier(0.32, 0.72, 0, 1);
transform: translateY(var(--drawer-swipe-movement-y));
will-change: transform;
@media (prefers-color-scheme: dark) {
border-top: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
box-shadow: none;
}
&[data-swiping] {
-webkit-user-select: none;
user-select: none;
}
&.PopupHidden {
transform: translateY(calc(100% - var(--bleed) + 2px));
box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 0%);
}
&.PopupLeaving {
transition-duration: calc(var(--drawer-swipe-strength) * 400ms);
}
}
.Header {
position: relative;
flex-shrink: 0;
padding: 1rem 1.5rem;
border-bottom: 1px solid oklch(87% 0 0deg);
touch-action: none;
-webkit-user-select: none;
user-select: none;
@media (prefers-color-scheme: dark) {
border-bottom: 1px solid oklch(37.1% 0 0deg);
}
}
.HeaderActions {
display: grid;
grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
align-items: center;
gap: 0.75rem;
}
.HeaderButton {
min-width: 0;
&:first-child {
justify-self: start;
}
&:last-child {
justify-self: end;
}
}
.Handle {
position: absolute;
top: 0.5rem;
left: 50%;
width: 3rem;
height: 0.25rem;
margin: 0;
flex-shrink: 0;
background-color: oklch(87% 0 0deg);
transform: translateX(-50%);
@media (prefers-color-scheme: dark) {
background-color: oklch(37.1% 0 0deg);
}
}
.Title {
margin: 0;
font-size: 1rem;
line-height: 1.5rem;
font-weight: 700;
text-align: center;
cursor: default;
}
.Scroll {
flex: 1 1 auto;
min-height: 0;
overflow-y: auto;
overscroll-behavior: contain;
touch-action: auto;
padding: 1rem 1.5rem 1.5rem;
}
.Form {
display: grid;
gap: 0.75rem;
width: 100%;
max-width: 22.5rem;
margin: 0 auto;
}
.Field {
display: flex;
flex-direction: column;
align-items: start;
gap: 0.25rem;
width: 100%;
}
.FieldLabel {
font-size: 0.875rem;
line-height: 1.25rem;
font-weight: 700;
color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
color: white;
}
}
.Input,
.Textarea {
box-sizing: border-box;
width: 100%;
margin: 0;
border-radius: 0;
border: 1px solid oklch(14.5% 0 0deg);
background-color: white;
font-family: inherit;
font-size: 0.875rem;
line-height: 1.25rem;
font-weight: 400;
color: oklch(14.5% 0 0deg);
@media (any-pointer: coarse) {
font-size: 1rem;
line-height: 1.5rem;
}
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
&::placeholder {
color: oklch(55.6% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
&:focus {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Input {
height: 2rem;
padding: 0 0.5rem;
}
.Textarea {
min-height: 5.5rem;
padding: 0.5rem;
resize: vertical;
}
.FooterSlot {
position: relative;
flex-shrink: 0;
min-height: var(--footer-reserved-height);
transition-duration: 260ms;
transition-property: min-height;
transition-timing-function: cubic-bezier(0.32, 0.72, 0, 1);
&:focus-within {
min-height: calc(var(--footer-reserved-height) + var(--drawer-keyboard-inset, 0px));
}
@media (prefers-reduced-motion: reduce) {
transition-duration: 0ms;
}
}
.StickyFooter {
position: absolute;
right: 0;
bottom: 0;
left: 0;
z-index: 1;
border-top: 1px solid oklch(14.5% 0 0deg);
background-color: white;
padding: 0.625rem 1.5rem calc(0.625rem + env(safe-area-inset-bottom, 0px) + var(--bleed));
transition-duration: 260ms;
transition-property: bottom, padding-bottom;
transition-timing-function: cubic-bezier(0.32, 0.72, 0, 1);
will-change: bottom, padding-bottom;
&:focus-within {
position: fixed;
z-index: 3;
bottom: 0;
padding-bottom: calc(
0.625rem + env(safe-area-inset-bottom, 0px) + var(--bleed) + var(--drawer-keyboard-inset, 0px)
);
transform: translate3d(0, 0, 0);
}
@media (prefers-color-scheme: dark) {
border-top-color: white;
background-color: oklch(14.5% 0 0deg);
}
@media (prefers-reduced-motion: reduce) {
transition-duration: 0ms;
}
}
.Composer {
display: flex;
flex-direction: column;
gap: 0.25rem;
width: 100%;
max-width: 22.5rem;
margin: 0 auto;
}
.ComposerInput {
box-sizing: border-box;
width: 100%;
height: 2.5rem;
margin: 0;
border-radius: 0;
border: 1px solid oklch(14.5% 0 0deg);
background-color: white;
padding: 0 0.625rem;
font-family: inherit;
font-size: 0.875rem;
line-height: 1.25rem;
font-weight: 400;
color: oklch(14.5% 0 0deg);
@media (any-pointer: coarse) {
font-size: 1rem;
line-height: 1.5rem;
}
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
&::placeholder {
color: oklch(55.6% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
&:focus {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}<script setup lang="ts">
import { Drawer } from '@vase-ui/vue/drawer';
const fields = [
['Name', 'Ada Lovelace'],
['Phone', '+1 (555) 123-4567'],
['Street address', '12 Computing Way'],
['Apartment', 'Unit 4B'],
['City', 'San Francisco'],
['Postal code', '94107'],
['Delivery window', 'After 6 PM'],
['Backup contact', 'Grace Hopper'],
];
const backdropHiddenClass = 'opacity-0!';
const backdropLeavingClass = 'duration-[calc(var(--drawer-swipe-strength)*400ms)]!';
const popupHiddenClass =
'[transform:translateY(calc(100%-var(--bleed)+2px))]! shadow-[0.25rem_0.25rem_0]! shadow-black/0!';
const popupLeavingClass = 'leaving duration-[calc(var(--drawer-swipe-strength)*400ms)]!';
</script>
<template>
<Drawer.Root>
<Drawer.Trigger
class="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-disabled:bg-neutral-100 active:not-disabled:bg-neutral-200 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-disabled:bg-neutral-800 dark:active:not-disabled:bg-neutral-700 dark:disabled:border-neutral-400 dark:disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
>Open keyboard-aware drawer</Drawer.Trigger
>
<Drawer.VirtualKeyboardProvider>
<Drawer.Portal>
<Transition
:enter-from-class="backdropHiddenClass"
:leave-to-class="backdropHiddenClass"
:leave-active-class="backdropLeavingClass"
appear
>
<Drawer.Backdrop
class="[--backdrop-opacity:0.2] [--bleed:3rem] dark:[--backdrop-opacity:0.7] fixed inset-0 bg-black opacity-[calc(var(--backdrop-opacity)*(1-var(--drawer-swipe-progress)))] transition-opacity duration-[450ms] ease-[cubic-bezier(0.32,0.72,0,1)] data-swiping:duration-0 supports-[-webkit-touch-callout:none]:absolute supports-[-webkit-touch-callout:none]:min-h-dvh"
/>
</Transition>
<Drawer.Viewport
class="fixed inset-0 flex items-end justify-center touch-none [--bleed:3rem] after:pointer-events-none after:fixed after:inset-x-0 after:bottom-0 after:h-[var(--bleed)] after:bg-white after:content-[''] has-[>.leaving]:after:opacity-0 has-[[data-swiping]]:after:opacity-0 dark:after:bg-neutral-950"
>
<Transition
:enter-from-class="popupHiddenClass"
:leave-to-class="popupHiddenClass"
:leave-active-class="popupLeavingClass"
appear
>
<Drawer.Popup
class="relative z-1 -mb-[var(--bleed)] flex h-[calc(100%-1rem+var(--bleed))] max-h-[calc(100%-1rem+var(--bleed))] w-full flex-col overflow-visible border-t border-neutral-950 bg-white text-neutral-950 outline-none touch-none shadow-[0.25rem_0.25rem_0] shadow-black/12 [--bleed:3rem] [--footer-reserved-height:calc(5.25rem+var(--bleed))] [transform:translateY(var(--drawer-swipe-movement-y))] transition-[transform,box-shadow] duration-[450ms] ease-[cubic-bezier(0.32,0.72,0,1)] will-change-transform data-swiping:select-none dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none"
>
<div
class="relative shrink-0 border-b border-neutral-300 px-6 py-4 touch-none select-none dark:border-neutral-700"
>
<div
class="absolute top-2 left-1/2 h-1 w-12 shrink-0 -translate-x-1/2 bg-neutral-300 dark:bg-neutral-700"
/>
<div class="grid grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)] items-center gap-3">
<Drawer.Close
class="flex h-8 min-w-0 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none justify-self-start hover:not-disabled:bg-neutral-100 active:not-disabled:bg-neutral-200 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-disabled:bg-neutral-800 dark:active:not-disabled:bg-neutral-700 dark:disabled:border-neutral-400 dark:disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
>Cancel</Drawer.Close
>
<Drawer.Title class="cursor-default text-center text-base font-bold"
>Delivery details</Drawer.Title
>
<Drawer.Close
class="flex h-8 min-w-0 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none justify-self-end hover:not-disabled:bg-neutral-100 active:not-disabled:bg-neutral-200 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-disabled:bg-neutral-800 dark:active:not-disabled:bg-neutral-700 dark:disabled:border-neutral-400 dark:disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
>Save</Drawer.Close
>
</div>
</div>
<Drawer.Content
class="min-h-0 flex-1 overflow-y-auto overscroll-contain touch-auto px-6 pt-4 pb-6"
>
<div class="mx-auto grid w-full max-w-90 gap-3">
<label
v-for="[label, placeholder] in fields"
:key="label"
class="flex w-full flex-col items-start gap-1"
>
<span class="text-sm font-bold text-neutral-950 dark:text-white">{{
label
}}</span>
<input
class="h-8 w-full border border-neutral-950 bg-white px-2 text-sm any-pointer-coarse:text-base font-normal text-neutral-950 placeholder:text-neutral-500 focus:outline-2 focus:-outline-offset-1 focus:outline-neutral-950 dark:focus:outline-white dark:border-white dark:bg-neutral-950 dark:text-white dark:placeholder:text-neutral-400"
:placeholder="placeholder"
type="text"
/>
</label>
<label class="flex w-full flex-col items-start gap-1">
<span class="text-sm font-bold text-neutral-950 dark:text-white"
>Instructions</span
>
<textarea
class="min-h-22 w-full resize-y border border-neutral-950 bg-white px-2 py-2 text-sm any-pointer-coarse:text-base font-normal text-neutral-950 placeholder:text-neutral-500 focus:outline-2 focus:-outline-offset-1 focus:outline-neutral-950 dark:focus:outline-white dark:border-white dark:bg-neutral-950 dark:text-white dark:placeholder:text-neutral-400"
placeholder="Gate code, drop-off spot, or anything else the driver should know"
/>
</label>
</div>
</Drawer.Content>
<div
class="relative min-h-[var(--footer-reserved-height)] shrink-0 transition-[min-height] duration-[260ms] ease-[cubic-bezier(0.32,0.72,0,1)] focus-within:min-h-[calc(var(--footer-reserved-height)+var(--drawer-keyboard-inset,0px))] motion-reduce:transition-none"
>
<div
class="absolute right-0 bottom-0 left-0 z-1 border-t border-neutral-950 bg-white px-6 pt-2.5 pb-[calc(0.625rem+env(safe-area-inset-bottom,0px)+var(--bleed))] transition-[bottom,padding-bottom] duration-[260ms] ease-[cubic-bezier(0.32,0.72,0,1)] will-change-[bottom,padding-bottom] focus-within:fixed focus-within:z-3 focus-within:bottom-0 focus-within:pb-[calc(0.625rem+env(safe-area-inset-bottom,0px)+var(--bleed)+var(--drawer-keyboard-inset,0px))] focus-within:[transform:translate3d(0,0,0)] motion-reduce:transition-none dark:border-white dark:bg-neutral-950"
>
<label class="mx-auto flex w-full max-w-90 flex-col gap-1">
<span class="text-sm font-bold text-neutral-950 dark:text-white"
>Delivery note</span
>
<input
class="h-10 w-full border border-neutral-950 bg-white px-2.5 text-sm font-normal text-neutral-950 placeholder:text-neutral-500 any-pointer-coarse:text-base focus:outline-2 focus:-outline-offset-1 focus:outline-neutral-950 dark:border-white dark:bg-neutral-950 dark:text-white dark:placeholder:text-neutral-400 dark:focus:outline-white"
placeholder="Add a note for the driver"
type="text"
/>
</label>
</div>
</div>
</Drawer.Popup>
</Transition>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.VirtualKeyboardProvider>
</Drawer.Root>
</template>Indent effect
To make the background smaller when a drawer opens, put your app in Drawer.Provider, and put Drawer.IndentBackground and Drawer.Indent at the top of your tree. Each Drawer.Root in the provider tells the provider when it opens and closes. While a drawer is open, the indent parts have the attribute data-active.
<script setup lang="ts">
import { useTemplateRef } from 'vue';
import { Drawer } from '@vase-ui/vue/drawer';
import styles from './index.module.css';
const portalContainer = useTemplateRef<HTMLDivElement>('portalContainer');
const backdropHiddenClass = styles.BackdropHidden;
const backdropLeavingClass = styles.BackdropLeaving;
const popupHiddenClass = styles.PopupHidden;
const popupLeavingClass = styles.PopupLeaving;
</script>
<template>
<Drawer.Provider>
<div ref="portalContainer" :class="styles.Root">
<Drawer.IndentBackground :class="styles.IndentBackground" />
<Drawer.Indent :class="styles.Indent">
<div :class="styles.Center">
<Drawer.Root :modal="false">
<Drawer.Trigger :class="styles.Button">Open drawer</Drawer.Trigger>
<Drawer.Portal :to="portalContainer">
<Transition
:enter-from-class="backdropHiddenClass"
:leave-to-class="backdropHiddenClass"
:leave-active-class="backdropLeavingClass"
appear
>
<Drawer.Backdrop :class="styles.Backdrop" />
</Transition>
<Drawer.Viewport :class="styles.Viewport">
<Transition
:enter-from-class="popupHiddenClass"
:leave-to-class="popupHiddenClass"
:leave-active-class="popupLeavingClass"
appear
>
<Drawer.Popup :class="styles.Popup">
<div :class="styles.Handle" />
<Drawer.Content :class="styles.Content">
<Drawer.Title :class="styles.Title">Notifications</Drawer.Title>
<Drawer.Description :class="styles.Description">
You are all caught up. Good job!
</Drawer.Description>
<div :class="styles.Actions">
<Drawer.Close :class="styles.Button">Close</Drawer.Close>
</div>
</Drawer.Content>
</Drawer.Popup>
</Transition>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
</div>
</Drawer.Indent>
</div>
</Drawer.Provider>
</template>.Root {
--bleed: 3rem;
position: relative;
width: 100%;
overflow: hidden;
}
.Indent {
--indent-radius: calc(1rem * (1 - var(--drawer-swipe-progress)));
--indent-transition: calc(1 - clamp(0, calc(var(--drawer-swipe-progress) * 100000), 1));
position: relative;
min-height: 20rem;
transition:
transform 0.4s cubic-bezier(0.32, 0.72, 0, 1),
border-radius 0.25s cubic-bezier(0.32, 0.72, 0, 1);
transform-origin: center top;
will-change: transform;
border: 1px solid oklch(14.5% 0 0deg);
contain: layout;
padding: 1rem;
color: oklch(14.5% 0 0deg);
background-color: white;
transition-duration:
calc(400ms * var(--indent-transition)), calc(250ms * var(--indent-transition));
@media (prefers-color-scheme: dark) {
border: 1px solid white;
color: white;
background-color: oklch(14.5% 0 0deg);
}
&[data-active] {
transform: scale(calc(0.98 + (0.02 * var(--drawer-swipe-progress))))
translateY(calc(0.5rem * (1 - var(--drawer-swipe-progress))));
border-top-left-radius: var(--indent-radius);
border-top-right-radius: var(--indent-radius);
}
}
.Center {
min-height: 20rem;
display: flex;
align-items: center;
justify-content: center;
}
.IndentBackground {
position: absolute;
inset: 0;
background-color: black;
@media (prefers-color-scheme: dark) {
background-color: oklch(87% 0 0deg);
}
}
.Button {
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
height: 2rem;
padding: 0 0.75rem;
margin: 0;
border: 1px solid oklch(14.5% 0 0deg);
background-color: white;
font-family: inherit;
font-size: 0.875rem;
font-weight: 400;
line-height: 1;
white-space: nowrap;
color: oklch(14.5% 0 0deg);
-webkit-user-select: none;
user-select: none;
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
@media (hover: hover) {
&:hover:not(:disabled) {
background-color: oklch(97% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
}
}
&:active:not(:disabled) {
background-color: oklch(92.2% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(37.1% 0 0deg);
}
}
&:disabled {
color: oklch(55.6% 0 0deg);
border-color: oklch(55.6% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
border-color: oklch(70.8% 0 0deg);
}
}
&:focus-visible {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Backdrop {
--backdrop-opacity: 0.2;
--bleed: 3rem;
position: absolute;
min-height: 100dvh;
inset: 0;
background-color: black;
opacity: calc(var(--backdrop-opacity) * (1 - var(--drawer-swipe-progress)));
transition-duration: 450ms;
transition-property: opacity;
transition-timing-function: cubic-bezier(0.32, 0.72, 0, 1);
@media (prefers-color-scheme: dark) {
--backdrop-opacity: 0.7;
}
&.BackdropHidden {
opacity: 0;
}
&[data-swiping] {
transition-duration: 0ms;
}
&.BackdropLeaving {
transition-duration: calc(var(--drawer-swipe-strength) * 400ms);
}
}
.Viewport {
position: absolute;
inset: 0;
display: flex;
align-items: flex-end;
justify-content: center;
}
.Popup {
box-sizing: border-box;
width: 100%;
max-height: calc(80vh + var(--bleed));
margin-bottom: calc(-1 * var(--bleed));
padding: 1rem 1.5rem 1.5rem;
padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px) + var(--bleed));
border-top: 1px solid oklch(14.5% 0 0deg);
background-color: white;
color: oklch(14.5% 0 0deg);
outline: 0;
box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 12%);
overflow-y: auto;
overscroll-behavior: contain;
transition: transform 450ms cubic-bezier(0.32, 0.72, 0, 1);
will-change: transform;
transform: translateY(var(--drawer-swipe-movement-y));
@media (prefers-color-scheme: dark) {
border-top: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
box-shadow: none;
}
&.PopupHidden {
transform: translateY(calc(100% - var(--bleed) + 2px));
}
&.PopupLeaving {
transition-duration: calc(var(--drawer-swipe-strength) * 400ms);
}
}
.Content {
width: 100%;
max-width: 32rem;
margin: 0 auto;
}
.Handle {
width: 3rem;
height: 0.25rem;
margin: 0 auto 1rem;
background-color: oklch(87% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(37.1% 0 0deg);
}
}
.Title {
margin-top: 0;
margin-bottom: 0.25rem;
font-size: 1rem;
line-height: 1.5rem;
font-weight: 700;
text-align: center;
}
.Description {
margin: 0 0 1.5rem;
font-size: 0.875rem;
line-height: 1.25rem;
color: oklch(43.9% 0 0deg);
text-align: center;
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
.Actions {
display: flex;
justify-content: center;
gap: 0.75rem;
}<script setup lang="ts">
import { useTemplateRef } from 'vue';
import { Drawer } from '@vase-ui/vue/drawer';
const portalContainer = useTemplateRef<HTMLDivElement>('portalContainer');
const backdropHiddenClass = 'opacity-0!';
const backdropLeavingClass = 'duration-[calc(var(--drawer-swipe-strength)*400ms)]!';
const popupHiddenClass = '[transform:translateY(calc(100%-var(--bleed)+2px))]!';
const popupLeavingClass = 'duration-[calc(var(--drawer-swipe-strength)*400ms)]!';
</script>
<template>
<Drawer.Provider>
<div ref="portalContainer" class="[--bleed:3rem] relative w-full overflow-hidden">
<Drawer.IndentBackground class="absolute inset-0 bg-black dark:bg-neutral-300" />
<Drawer.Indent
class="[--indent-radius:calc(1rem*(1-var(--drawer-swipe-progress)))] [--indent-transition:calc(1-clamp(0,calc(var(--drawer-swipe-progress)*100000),1))] relative min-h-80 border border-neutral-950 bg-white p-4 text-neutral-950 [transition:transform_0.4s_cubic-bezier(0.32,0.72,0,1),border-radius_0.25s_cubic-bezier(0.32,0.72,0,1)] origin-[center_top] will-change-transform [transform:scale(1)_translateY(0)] [transition-duration:calc(400ms*var(--indent-transition)),calc(250ms*var(--indent-transition))] data-active:transform-[scale(calc(0.98+(0.02*var(--drawer-swipe-progress))))_translateY(calc(0.5rem*(1-var(--drawer-swipe-progress))))] data-active:rounded-tl-(--indent-radius) data-active:rounded-tr-(--indent-radius) dark:border-white dark:bg-neutral-950 dark:text-white"
>
<div class="flex min-h-80 items-center justify-center">
<Drawer.Root :modal="false">
<Drawer.Trigger
class="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-disabled:bg-neutral-100 active:not-disabled:bg-neutral-200 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-disabled:bg-neutral-800 dark:active:not-disabled:bg-neutral-700 dark:disabled:border-neutral-400 dark:disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
>Open drawer</Drawer.Trigger
>
<Drawer.Portal :to="portalContainer">
<Transition
:enter-from-class="backdropHiddenClass"
:leave-to-class="backdropHiddenClass"
:leave-active-class="backdropLeavingClass"
appear
>
<Drawer.Backdrop
class="[--backdrop-opacity:0.2] [--bleed:3rem] dark:[--backdrop-opacity:0.7] absolute inset-0 min-h-dvh bg-black opacity-[calc(var(--backdrop-opacity)*(1-var(--drawer-swipe-progress)))] transition-opacity duration-[450ms] ease-[cubic-bezier(0.32,0.72,0,1)] data-swiping:duration-0 supports-[-webkit-touch-callout:none]:absolute"
/>
</Transition>
<Drawer.Viewport class="absolute inset-0 flex items-end justify-center">
<Transition
:enter-from-class="popupHiddenClass"
:leave-to-class="popupHiddenClass"
:leave-active-class="popupLeavingClass"
appear
>
<Drawer.Popup
class="w-full max-h-[calc(80vh+var(--bleed))] -mb-[var(--bleed)] border-t border-neutral-950 bg-white px-6 py-4 pb-[calc(1.5rem+env(safe-area-inset-bottom,0px)+var(--bleed))] text-neutral-950 outline-none shadow-[0.25rem_0.25rem_0] shadow-black/12 overflow-y-auto overscroll-contain transition-transform duration-[450ms] ease-[cubic-bezier(0.32,0.72,0,1)] [transform:translateY(var(--drawer-swipe-movement-y))] data-swiping:select-none dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none"
>
<div class="mx-auto mb-4 h-1 w-12 bg-neutral-300 dark:bg-neutral-700" />
<Drawer.Content class="mx-auto w-full max-w-[32rem]">
<Drawer.Title class="mt-0 mb-1 text-base font-bold text-center"
>Notifications</Drawer.Title
>
<Drawer.Description
class="mb-6 text-sm text-neutral-600 text-center dark:text-neutral-400"
>
You are all caught up. Good job!
</Drawer.Description>
<div class="flex justify-center gap-3">
<Drawer.Close
class="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-disabled:bg-neutral-100 active:not-disabled:bg-neutral-200 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-disabled:bg-neutral-800 dark:active:not-disabled:bg-neutral-700 dark:disabled:border-neutral-400 dark:disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
>Close</Drawer.Close
>
</div>
</Drawer.Content>
</Drawer.Popup>
</Transition>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
</div>
</Drawer.Indent>
</div>
</Drawer.Provider>
</template>Non-modal
Set :modal="false" to keep the focus free, and set disablePointerDismissal to keep the drawer open at a press outside it.
<script setup lang="ts">
import { Drawer } from '@vase-ui/vue/drawer';
import styles from './index.module.css';
const popupHiddenClass = styles.PopupHidden;
const popupLeavingClass = styles.PopupLeaving;
</script>
<template>
<Drawer.Root swipe-direction="right" :modal="false" disable-pointer-dismissal>
<Drawer.Trigger :class="styles.Button">Open non-modal drawer</Drawer.Trigger>
<Drawer.Portal>
<Drawer.Viewport :class="styles.Viewport">
<Transition
:enter-from-class="popupHiddenClass"
:leave-to-class="popupHiddenClass"
:leave-active-class="popupLeavingClass"
appear
>
<Drawer.Popup :class="styles.Popup">
<Drawer.Content :class="styles.Content">
<Drawer.Title :class="styles.Title">Non-modal drawer</Drawer.Title>
<Drawer.Description :class="styles.Description">
This drawer does not trap focus and ignores outside clicks. Use the close button or
swipe to dismiss it.
</Drawer.Description>
<div :class="styles.Actions">
<Drawer.Close :class="styles.Button">Close</Drawer.Close>
</div>
</Drawer.Content>
</Drawer.Popup>
</Transition>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
</template>.Button {
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
height: 2rem;
padding: 0 0.75rem;
margin: 0;
border: 1px solid oklch(14.5% 0 0deg);
background-color: white;
font-family: inherit;
font-size: 0.875rem;
font-weight: 400;
line-height: 1;
white-space: nowrap;
color: oklch(14.5% 0 0deg);
-webkit-user-select: none;
user-select: none;
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
@media (hover: hover) {
&:hover:not(:disabled) {
background-color: oklch(97% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
}
}
&:active:not(:disabled) {
background-color: oklch(92.2% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(37.1% 0 0deg);
}
}
&:disabled {
color: oklch(55.6% 0 0deg);
border-color: oklch(55.6% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
border-color: oklch(70.8% 0 0deg);
}
}
&:focus-visible {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Backdrop {
--backdrop-opacity: 0.2;
--bleed: 3rem;
position: fixed;
min-height: 100dvh;
inset: 0;
background-color: black;
opacity: calc(var(--backdrop-opacity) * (1 - var(--drawer-swipe-progress)));
transition-duration: 450ms;
transition-property: opacity;
transition-timing-function: cubic-bezier(0.32, 0.72, 0, 1);
/* iOS 26+: Ensure the backdrop covers the entire visible viewport. */
@supports (-webkit-touch-callout: none) {
position: absolute;
}
@media (prefers-color-scheme: dark) {
--backdrop-opacity: 0.7;
}
&.BackdropHidden {
opacity: 0;
}
&[data-swiping] {
transition-duration: 0ms;
}
&.BackdropLeaving {
transition-duration: calc(var(--drawer-swipe-strength) * 400ms);
}
}
.Viewport {
--viewport-padding: 0px;
position: fixed;
inset: 0;
display: flex;
justify-content: flex-end;
padding: var(--viewport-padding);
pointer-events: none;
@supports (-webkit-touch-callout: none) {
--viewport-padding: 0.625rem;
}
}
.Popup {
--bleed: 3rem;
box-sizing: border-box;
width: calc(20rem + var(--bleed));
max-width: calc(100vw - 3rem + var(--bleed));
height: 100%;
padding: 1.5rem;
padding-right: calc(1.5rem + var(--bleed));
margin-right: calc(-1 * var(--bleed));
border-left: 1px solid oklch(14.5% 0 0deg);
background-color: white;
color: oklch(14.5% 0 0deg);
outline: 0;
overflow-y: auto;
overscroll-behavior: contain;
touch-action: auto;
pointer-events: auto;
box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 12%);
transition:
transform 450ms cubic-bezier(0.32, 0.72, 0, 1),
box-shadow 450ms cubic-bezier(0.32, 0.72, 0, 1);
will-change: transform;
transform: translateX(var(--drawer-swipe-movement-x));
@media (prefers-color-scheme: dark) {
border-left: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
box-shadow: none;
}
&.PopupHidden {
transform: translateX(calc(100% - var(--bleed) + var(--viewport-padding) + 2px));
box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 0%);
}
&.PopupLeaving {
transition-duration: calc(var(--drawer-swipe-strength) * 400ms);
}
@supports (-webkit-touch-callout: none) {
--bleed: 0px;
margin-right: 0;
border: 1px solid oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
border: 1px solid white;
}
}
}
.Content {
width: 100%;
max-width: 32rem;
margin: 0 auto;
}
.Title {
margin-top: 0;
margin-bottom: 0.25rem;
font-size: 1rem;
line-height: 1.5rem;
font-weight: 700;
}
.Description {
margin: 0 0 1.5rem;
font-size: 0.875rem;
line-height: 1.25rem;
color: oklch(43.9% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
.Actions {
display: flex;
justify-content: flex-end;
gap: 0.75rem;
}<script setup lang="ts">
import { Drawer } from '@vase-ui/vue/drawer';
const popupHiddenClass =
'shadow-[0.25rem_0.25rem_0]! shadow-black/0! [transform:translateX(calc(100%-var(--bleed)+var(--viewport-padding)+2px))]!';
const popupLeavingClass = 'duration-[calc(var(--drawer-swipe-strength)*400ms)]!';
</script>
<template>
<Drawer.Root swipe-direction="right" :modal="false" disable-pointer-dismissal>
<Drawer.Trigger
class="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-disabled:bg-neutral-100 active:not-disabled:bg-neutral-200 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-disabled:bg-neutral-800 dark:active:not-disabled:bg-neutral-700 dark:disabled:border-neutral-400 dark:disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
>Open non-modal drawer</Drawer.Trigger
>
<Drawer.Portal>
<Drawer.Viewport
class="[--viewport-padding:0px] supports-[-webkit-touch-callout:none]:[--viewport-padding:0.625rem] fixed inset-0 flex items-stretch justify-end p-(--viewport-padding) pointer-events-none"
>
<Transition
:enter-from-class="popupHiddenClass"
:leave-to-class="popupHiddenClass"
:leave-active-class="popupLeavingClass"
appear
>
<Drawer.Popup
class="[--bleed:3rem] supports-[-webkit-touch-callout:none]:[--bleed:0px] pointer-events-auto h-full w-[calc(20rem+3rem)] max-w-[calc(100vw-3rem+3rem)] -mr-[3rem] border-l border-neutral-950 bg-white p-6 pr-[calc(1.5rem+3rem)] text-neutral-950 outline-none shadow-[0.25rem_0.25rem_0] shadow-black/12 overflow-y-auto overscroll-contain touch-auto [transform:translateX(var(--drawer-swipe-movement-x))] transition-[transform,box-shadow] duration-[450ms] ease-[cubic-bezier(0.32,0.72,0,1)] data-swiping:select-none supports-[-webkit-touch-callout:none]:mr-0 supports-[-webkit-touch-callout:none]:w-[20rem] supports-[-webkit-touch-callout:none]:max-w-[calc(100vw-3rem)] supports-[-webkit-touch-callout:none]:border supports-[-webkit-touch-callout:none]:pr-6 dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none"
>
<Drawer.Content class="mx-auto w-full max-w-[32rem]">
<Drawer.Title class="mb-1 text-base font-bold">Non-modal drawer</Drawer.Title>
<Drawer.Description class="mb-6 text-sm text-neutral-600 dark:text-neutral-400">
This drawer does not trap focus and ignores outside clicks. Use the close button or
swipe to dismiss it.
</Drawer.Description>
<div class="flex justify-end gap-3">
<Drawer.Close
class="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-disabled:bg-neutral-100 active:not-disabled:bg-neutral-200 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-disabled:bg-neutral-800 dark:active:not-disabled:bg-neutral-700 dark:disabled:border-neutral-400 dark:disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
>Close</Drawer.Close
>
</div>
</Drawer.Content>
</Drawer.Popup>
</Transition>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
</template>Swipe to open
Put Drawer.SwipeArea along the edge of the viewport. A swipe from that edge then opens the drawer.
Swipe from the right edge to open the drawer.
<script setup lang="ts">
import { useTemplateRef } from 'vue';
import { Drawer } from '@vase-ui/vue/drawer';
import styles from './index.module.css';
const portalContainer = useTemplateRef<HTMLDivElement>('portalContainer');
</script>
<template>
<div ref="portalContainer" :class="styles.Root">
<Drawer.Root swipe-direction="right" :modal="false">
<Drawer.SwipeArea :class="styles.SwipeArea">
<span :class="styles.SwipeLabel">Swipe here</span>
</Drawer.SwipeArea>
<div :class="styles.Center">
<div :class="styles.Instructions">
<p :class="styles.Hint">Swipe from the right edge to open the drawer.</p>
</div>
</div>
<Drawer.Portal :to="portalContainer">
<Transition
:enter-from-class="styles.BackdropHidden"
:leave-to-class="styles.BackdropHidden"
:leave-active-class="styles.BackdropLeaving"
appear
>
<Drawer.Backdrop :class="styles.Backdrop" />
</Transition>
<Drawer.Viewport :class="styles.Viewport">
<Transition
:enter-from-class="styles.PopupHidden"
:leave-to-class="styles.PopupHidden"
:leave-active-class="styles.PopupLeaving"
appear
>
<Drawer.Popup :class="styles.Popup">
<Drawer.Content :class="styles.Content">
<Drawer.Title :class="styles.Title">Library</Drawer.Title>
<Drawer.Description :class="styles.Description">
Swipe from the edge whenever you want to jump back into your playlists.
</Drawer.Description>
<div :class="styles.Actions">
<Drawer.Close :class="styles.Button">Close</Drawer.Close>
</div>
</Drawer.Content>
</Drawer.Popup>
</Transition>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
</div>
</template>.Root {
box-sizing: border-box;
position: relative;
width: 100%;
min-height: 20rem;
overflow: hidden;
border: 1px solid oklch(14.5% 0 0deg);
background-color: white;
color: oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
}
.Center {
box-sizing: border-box;
min-height: 20rem;
display: flex;
align-items: center;
justify-content: center;
padding: 1rem;
}
.Instructions {
display: flex;
flex-direction: column;
align-items: center;
gap: 0.75rem;
text-align: center;
}
.Hint {
box-sizing: border-box;
margin: 0;
font-size: 0.875rem;
line-height: 1.25rem;
color: oklch(43.9% 0 0deg);
text-align: center;
padding-right: 3rem;
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
.SwipeArea {
box-sizing: border-box;
position: absolute;
top: 0;
right: 0;
bottom: 0;
width: 2.5rem;
z-index: 1;
border-left: 2px dashed oklch(42.4% 0.199 265.638deg);
background-color: color-mix(in oklch, oklch(42.4% 0.199 265.638deg), transparent 90%);
@media (prefers-color-scheme: dark) {
border-left-color: oklch(62.3% 0.214 259.815deg);
background-color: color-mix(in oklch, oklch(62.3% 0.214 259.815deg), transparent 90%);
}
}
.SwipeLabel {
position: absolute;
right: 0;
top: 50%;
margin-right: 0.5rem;
transform: translateY(-50%) rotate(-90deg);
transform-origin: center;
z-index: 0;
font-size: 0.75rem;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
color: oklch(42.4% 0.199 265.638deg);
white-space: nowrap;
pointer-events: none;
@media (prefers-color-scheme: dark) {
color: oklch(62.3% 0.214 259.815deg);
}
}
.Button {
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
height: 2rem;
padding: 0 0.75rem;
margin: 0;
border: 1px solid oklch(14.5% 0 0deg);
background-color: white;
font-family: inherit;
font-size: 0.875rem;
font-weight: 400;
line-height: 1;
white-space: nowrap;
color: oklch(14.5% 0 0deg);
-webkit-user-select: none;
user-select: none;
@media (prefers-color-scheme: dark) {
border: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
}
@media (hover: hover) {
&:hover:not(:disabled) {
background-color: oklch(97% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(26.9% 0 0deg);
}
}
}
&:active:not(:disabled) {
background-color: oklch(92.2% 0 0deg);
@media (prefers-color-scheme: dark) {
background-color: oklch(37.1% 0 0deg);
}
}
&:disabled {
color: oklch(55.6% 0 0deg);
border-color: oklch(55.6% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
border-color: oklch(70.8% 0 0deg);
}
}
&:focus-visible {
outline: 2px solid oklch(14.5% 0 0deg);
outline-offset: -1px;
@media (prefers-color-scheme: dark) {
outline-color: white;
}
}
}
.Backdrop {
--backdrop-opacity: 0.2;
--bleed: 3rem;
position: absolute;
min-height: 100dvh;
inset: 0;
background-color: black;
opacity: calc(var(--backdrop-opacity) * (1 - var(--drawer-swipe-progress)));
transition-duration: 450ms;
transition-property: opacity;
transition-timing-function: cubic-bezier(0.32, 0.72, 0, 1);
@media (prefers-color-scheme: dark) {
--backdrop-opacity: 0.7;
}
&.BackdropHidden {
opacity: 0;
}
&[data-swiping] {
transition-duration: 0ms;
}
&.BackdropLeaving {
transition-duration: calc(var(--drawer-swipe-strength) * 400ms);
}
}
.Viewport {
--viewport-padding: 0px;
position: absolute;
inset: 0;
display: flex;
justify-content: flex-end;
padding: var(--viewport-padding);
z-index: 2;
@supports (-webkit-touch-callout: none) {
--viewport-padding: 0.625rem;
}
}
.Popup {
--bleed: 3rem;
box-sizing: border-box;
width: calc(20rem + var(--bleed));
max-width: calc(100vw - 3rem + var(--bleed));
height: 100%;
padding: 1.5rem;
padding-right: calc(1.5rem + var(--bleed));
margin-right: calc(-1 * var(--bleed));
border-left: 1px solid oklch(14.5% 0 0deg);
background-color: white;
color: oklch(14.5% 0 0deg);
outline: 0;
box-shadow: 0.25rem 0.25rem 0 rgb(0 0 0 / 12%);
overflow-y: auto;
touch-action: auto;
transition: transform 450ms cubic-bezier(0.32, 0.72, 0, 1);
will-change: transform;
transform: translateX(var(--drawer-swipe-movement-x));
@media (prefers-color-scheme: dark) {
border-left: 1px solid white;
background-color: oklch(14.5% 0 0deg);
color: white;
box-shadow: none;
}
&.PopupHidden {
transform: translateX(calc(100% - var(--bleed) + var(--viewport-padding) + 2px));
}
&.PopupLeaving {
transition-duration: calc(var(--drawer-swipe-strength) * 400ms);
}
@supports (-webkit-touch-callout: none) {
--bleed: 0px;
margin-right: 0;
border: 1px solid oklch(14.5% 0 0deg);
@media (prefers-color-scheme: dark) {
border: 1px solid white;
}
}
}
.Content {
width: 100%;
max-width: 32rem;
margin: 0 auto;
}
.Title {
margin-top: 0;
margin-bottom: 0.25rem;
font-size: 1rem;
line-height: 1.5rem;
font-weight: 700;
}
.Description {
margin: 0 0 1.5rem;
font-size: 0.875rem;
line-height: 1.25rem;
color: oklch(43.9% 0 0deg);
@media (prefers-color-scheme: dark) {
color: oklch(70.8% 0 0deg);
}
}
.Actions {
display: flex;
justify-content: flex-end;
gap: 0.75rem;
}<script setup lang="ts">
import { useTemplateRef } from 'vue';
import { Drawer } from '@vase-ui/vue/drawer';
const portalContainer = useTemplateRef<HTMLDivElement>('portalContainer');
</script>
<template>
<div
ref="portalContainer"
class="relative min-h-80 w-full overflow-hidden border border-neutral-950 bg-white text-neutral-950 dark:border-white dark:bg-neutral-950 dark:text-white"
>
<Drawer.Root swipe-direction="right" :modal="false">
<Drawer.SwipeArea
class="absolute inset-y-0 right-0 z-[1] w-10 border-l-2 border-dashed border-blue-800 bg-blue-800/10 dark:border-blue-500 dark:bg-blue-500/10"
>
<span
class="pointer-events-none absolute right-0 top-1/2 z-0 mr-2 -translate-y-1/2 -rotate-90 origin-center whitespace-nowrap text-xs font-bold tracking-[0.12em] text-blue-800 uppercase dark:text-blue-500"
>Swipe here</span
>
</Drawer.SwipeArea>
<div class="flex min-h-80 flex-col items-center justify-center gap-3 p-4 text-center">
<p class="text-sm text-neutral-600 text-center dark:text-neutral-400 pr-12">
Swipe from the right edge to open the drawer.
</p>
</div>
<Drawer.Portal :to="portalContainer">
<Transition
enter-from-class="opacity-0!"
leave-to-class="opacity-0!"
leave-active-class="duration-[calc(var(--drawer-swipe-strength)*400ms)]!"
appear
>
<Drawer.Backdrop
class="[--backdrop-opacity:0.2] [--bleed:3rem] dark:[--backdrop-opacity:0.7] absolute inset-0 min-h-dvh bg-black opacity-[calc(var(--backdrop-opacity)*(1-var(--drawer-swipe-progress)))] transition-opacity duration-[450ms] ease-[cubic-bezier(0.32,0.72,0,1)] data-swiping:duration-0 supports-[-webkit-touch-callout:none]:absolute"
/>
</Transition>
<Drawer.Viewport
class="[--viewport-padding:0px] supports-[-webkit-touch-callout:none]:[--viewport-padding:0.625rem] absolute inset-0 z-20 flex items-stretch justify-end p-(--viewport-padding)"
>
<Transition
enter-from-class="[transform:translateX(calc(100%-var(--bleed)+var(--viewport-padding)+2px))]!"
leave-to-class="[transform:translateX(calc(100%-var(--bleed)+var(--viewport-padding)+2px))]!"
leave-active-class="duration-[calc(var(--drawer-swipe-strength)*400ms)]!"
appear
>
<Drawer.Popup
class="[--bleed:3rem] supports-[-webkit-touch-callout:none]:[--bleed:0px] h-full w-[calc(20rem+3rem)] max-w-[calc(100vw-3rem+3rem)] -mr-[3rem] border-l border-neutral-950 bg-white p-6 pr-[calc(1.5rem+3rem)] text-neutral-950 outline-none shadow-[0.25rem_0.25rem_0] shadow-black/12 overflow-y-auto touch-auto [transform:translateX(var(--drawer-swipe-movement-x))] transition-transform duration-[450ms] ease-[cubic-bezier(0.32,0.72,0,1)] data-swiping:select-none supports-[-webkit-touch-callout:none]:mr-0 supports-[-webkit-touch-callout:none]:w-[20rem] supports-[-webkit-touch-callout:none]:max-w-[calc(100vw-3rem)] supports-[-webkit-touch-callout:none]:border supports-[-webkit-touch-callout:none]:pr-6 dark:border-white dark:bg-neutral-950 dark:text-white dark:shadow-none"
>
<Drawer.Content class="mx-auto w-full max-w-[32rem]">
<Drawer.Title class="mb-1 text-base font-bold">Library</Drawer.Title>
<Drawer.Description class="mb-6 text-sm text-neutral-600 dark:text-neutral-400">
Swipe from the edge whenever you want to jump back into your playlists.
</Drawer.Description>
<div class="flex justify-end gap-3">
<Drawer.Close
class="flex h-8 items-center justify-center gap-2 border border-neutral-950 bg-white px-3 text-sm leading-none whitespace-nowrap font-normal text-neutral-950 select-none hover:not-disabled:bg-neutral-100 active:not-disabled:bg-neutral-200 disabled:border-neutral-500 disabled:text-neutral-500 dark:border-white dark:bg-neutral-950 dark:text-white dark:hover:not-disabled:bg-neutral-800 dark:active:not-disabled:bg-neutral-700 dark:disabled:border-neutral-400 dark:disabled:text-neutral-400 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-neutral-950 dark:focus-visible:outline-white"
>Close</Drawer.Close
>
</div>
</Drawer.Content>
</Drawer.Popup>
</Transition>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
</div>
</template>Detached triggers
A trigger can be inside or outside Drawer.Root. For a simple interaction, put Drawer.Trigger inside Drawer.Root.
When the content of the drawer cannot be next to its trigger, use a detached trigger. Put Drawer.Trigger outside Drawer.Root, and connect the two with a handle from Drawer.createHandle().
The methods of the handle, such as open() and openWithPayload(), act only while a Drawer.Root with the same handle is mounted. The handle ignores a call before a root mounts or after it unmounts. Each root that mounts starts from a new state. It does not run an ignored call, and it does not keep the open state of an earlier root.
<script setup lang="ts">
import { Drawer } from '@vase-ui/vue/drawer';
const demoDrawer = Drawer.createHandle();
</script>
<template>
<Drawer.Trigger :handle="demoDrawer">Open</Drawer.Trigger>
<Drawer.Root :handle="demoDrawer">
<Drawer.Portal>
<Drawer.Viewport>
<Transition name="sheet" appear>
<Drawer.Popup>Drawer</Drawer.Popup>
</Transition>
</Drawer.Viewport>
</Drawer.Portal>
</Drawer.Root>
</template>The drawer can show different content for each trigger. Give a payload to each Drawer.Trigger. The default slot of Drawer.Root gets the payload of the active trigger.
<script setup lang="ts">
import { Drawer } from '@vase-ui/vue/drawer';
const demoDrawer = Drawer.createHandle<{ title: string }>();
</script>
<template>
<Drawer.Trigger :handle="demoDrawer" :payload="{ title: 'Profile' }">Profile</Drawer.Trigger>
<Drawer.Trigger :handle="demoDrawer" :payload="{ title: 'Settings' }">Settings</Drawer.Trigger>
<Drawer.Root :handle="demoDrawer">
<template #default="{ payload }">
<Drawer.Portal>
<Drawer.Viewport>
<Transition name="sheet" appear>
<Drawer.Popup>
<Drawer.Content>
<Drawer.Title>{{ payload?.title }}</Drawer.Title>
</Drawer.Content>
</Drawer.Popup>
</Transition>
</Drawer.Viewport>
</Drawer.Portal>
</template>
</Drawer.Root>
</template>Stacking and animations
Use CSS transitions or animations for the open, the close, the swipe and the stack. Put the backdrop and the popup each in a <Transition appear>, and animate the open and the close with its classes. A swipe that closes the drawer leaves the popup at the place of the drag, and the leave starts from there.
The --nested-drawers CSS variable gives the depth in the stack. The frontmost drawer has the index 0.
.DrawerPopup {
--stack-step: 0.05;
--stack-scale: calc(1 - (var(--nested-drawers) * var(--stack-step)));
transform: translateY(var(--drawer-swipe-movement-y)) scale(var(--stack-scale));
}When the drawers of a stack have different heights, use the --drawer-height and --drawer-frontmost-height variables to align the drawers behind the frontmost one with it.
.DrawerPopup {
--bleed: 3rem;
--stack-height: max(
0px,
calc(var(--drawer-frontmost-height, var(--drawer-height)) - var(--bleed))
);
height: var(--drawer-height, auto);
}
.DrawerPopup[data-nested-drawer-open] {
height: calc(var(--stack-height) + var(--bleed));
overflow: hidden;
}The attribute data-nested-drawer-open marks the drawers behind the frontmost drawer. Use it with data-nested-drawer-swiping to dim or hide the content of a parent drawer, and to show it again during a swipe of the nested drawer.
.DrawerContent {
transition: opacity 300ms;
}
.DrawerPopup[data-nested-drawer-open] .DrawerContent {
opacity: 0;
}
.DrawerPopup[data-nested-drawer-open][data-nested-drawer-swiping] .DrawerContent {
opacity: 1;
}Use the --drawer-swipe-movement-x, --drawer-swipe-movement-y and --drawer-snap-point-offset CSS variables for smooth drag and snap offsets:
.DrawerPopup[data-swipe-direction='right'] {
transform: translateX(var(--drawer-swipe-movement-x));
}
.DrawerPopup[data-swipe-direction='down'] {
transform: translateY(calc(var(--drawer-snap-point-offset) + var(--drawer-swipe-movement-y)));
}Use the data-swipe-direction attribute with the leave class of <Transition name="sheet"> to animate the dismissal in its direction. After a swipe, the popup and the backdrop also have data-swipe-dismiss in their leave.
.sheet-leave-to[data-swipe-direction='right'] {
transform: translateX(100%);
}
.sheet-leave-to[data-swipe-direction='down'] {
transform: translateY(100%);
}Use --drawer-swipe-progress to fade the backdrop during a swipe, and --drawer-swipe-strength to scale the duration of the leave by the speed of the swipe.
.DrawerBackdrop {
--backdrop-opacity: 0.2;
opacity: calc(var(--backdrop-opacity) * (1 - var(--drawer-swipe-progress)));
}
.sheet-leave-active,
.fade-leave-active {
transition-duration: calc(var(--drawer-swipe-strength) * 400ms);
}
.DrawerPopup[data-swiping],
.DrawerBackdrop[data-swiping] {
transition-duration: 0ms;
}API reference
Drawer.Provider
Gives the open state of its drawers to the indent parts. The indent parts are not active in the server HTML. They become active after the mount of an open root. Renders no element.
Slots
| Slot | Slot props | Description |
|---|---|---|
default | The content of the part. |
Drawer.IndentBackground
A layer under the indent.
Renders a <div> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: DrawerIndentBackgroundState | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: DrawerIndentBackgroundState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
[data-active] | A drawer of the provider is open. |
Drawer.Indent
A container of the page that moves back while a drawer is open.
Renders a <div> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: DrawerIndentState | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: DrawerIndentState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
[data-active] | A drawer of the provider is open. |
CSS variables
| Variable | Description |
|---|---|
--drawer-swipe-progress | The progress of the outer drawer toward its closed place: 0 at the open place, 1 at the closed place. |
--drawer-height | The height of the frontmost drawer, in pixels, while --drawer-swipe-progress is above 0 and that drawer has a height. |
Drawer.Root
Groups the parts of the drawer. Renders no element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
defaultOpen | boolean | undefined | false | The dialog is open at the mount of an uncontrolled root. |
defaultSnapPoint | DrawerSnapPoint | null | undefined | The active snap point at the mount of an uncontrolled root. By default the first snap point. | |
defaultTriggerId | string | null | undefined | null | The id of the active trigger at the mount, with defaultOpen. |
disablePointerDismissal | boolean | undefined | false | A press outside does not close the dialog. A dialog that is not modal also stays open when the focus leaves it. |
handle | DrawerHandle<Payload> | undefined | Connects the root to triggers outside it and to code. | |
modal | boolean | "trap-focus" | undefined | true | The modal state of the open dialog:
- true: the focus stays in the popup, and the rest of the page is inert. The page does not
scroll, and a fixed element covers it.
- 'trap-focus': the focus stays in the popup, and screen readers do not read the rest of the
page. The page stays in use for the pointer.
- false: the page stays in use. The dialog closes when the focus leaves it, unless
disablePointerDismissal is set.
Put a Close part in the popup: a touch screen reader needs it to leave a dialog that keeps
the focus. |
open | boolean | undefined | The dialog is open. v-model:open binds it. | |
snapPoint | DrawerSnapPoint | null | undefined | The active snap point. v-model:snap-point binds it. | |
snapPoints | DrawerSnapPoint[] | undefined | The places where the drawer stops. A number from 0 to 1 is a part of the height of the
viewport, a larger number is pixels, and a string has the unit px or rem. | |
snapToSequentialPoints | boolean | undefined | false | The speed of a swipe moves the drawer one snap point at most. |
swipeDirection | DrawerSwipeDirection | undefined | 'down' | The direction of the swipe that closes the drawer. |
triggerId | string | null | undefined | The id of the active trigger. v-model:trigger-id binds it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | payload: Payload | undefined | The content of the drawer. payload is the payload of the active trigger. |
Events
| Event | Arguments | Description |
|---|---|---|
openChange | [open: boolean, details: DrawerRootChangeEventDetails] | The drawer opens or closes. details.cancel() keeps it as it was. On Android, in a browser with
CloseWatcher, the back gesture closes the top open drawer with the reason 'close-watcher'.
Then cancel() keeps the drawer open only when the browser lets the page cancel the gesture. |
update:open | [open: boolean] | Comes after openChange, unless a listener cancels the change. v-model:open uses it. |
update:triggerId | [id: string | null] | The active trigger changes. v-model:trigger-id uses it. |
snapPointChange | [point: DrawerSnapPoint | null, details: DrawerRootSnapPointChangeEventDetails] | The snap point changes. details.cancel() keeps it as it was. |
update:snapPoint | [point: DrawerSnapPoint | null] | Comes after snapPointChange, unless a listener cancels the change. v-model:snap-point uses it. |
Exposed
| Member | Type | Description |
|---|---|---|
close | () => void | Closes the drawer with the reason 'imperative-action'. |
Drawer.Trigger
A button that opens the drawer.
Renders a <button> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
disabled | boolean | undefined | false | The user cannot press the trigger. |
handle | DrawerHandle<Payload> | undefined | Connects the trigger to a root outside it. | |
id | string | undefined | The root names the active trigger by this id in triggerId. | |
payload | Payload | undefined | The payload that the drawer gets when this trigger opens it. | |
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: DrawerTriggerState | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: DrawerTriggerState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
[aria-expanded="true"] | The drawer is open for this trigger. |
:disabled | The trigger is a native button, and it or a fieldset around it is disabled. |
[aria-disabled="true"] | The trigger is another element, and it is disabled. |
Drawer.SwipeArea
An area where a swipe opens the drawer.
Renders a <div> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
disabled | boolean | undefined | false | A swipe on the area opens nothing. |
id | string | undefined | The root names the area by this id in triggerId after a swipe on the area opens the drawer. | |
swipeDirection | DrawerSwipeDirection | undefined | The direction of the swipe that opens the drawer. By default the opposite of that of the root. | |
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: DrawerSwipeAreaState | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: DrawerSwipeAreaState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
[data-open] | The drawer is open. |
[data-swiping] | A swipe on the area moves the drawer. |
[data-swipe-direction] | The direction of the swipe that opens the drawer: up, down, left or right. |
[data-disabled] | A swipe on the area opens nothing. |
Drawer.VirtualKeyboardProvider
Keeps a focused text field of the drawer above the software keyboard. Renders no element.
Slots
| Slot | Slot props | Description |
|---|---|---|
default | The content of the part. |
Drawer.Portal
Moves its content to another place of the DOM, <body> by default.
Renders no element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
defer | boolean | undefined | false | Moves the content after the other content of the same update mounted. |
disabled | boolean | undefined | false | Renders the content in place, also on the server. |
keepMounted | boolean | undefined | false | The closed popup stays in the DOM, with hidden and inert. |
to | PortalTarget | undefined | The target of the content. With no value, the target of the nearest portal above, else
body. While it is null, the portal renders nothing. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | The content of the part. |
Drawer.Backdrop
An overlay under the popup.
Renders a <div> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
forceRender | boolean | undefined | false | The backdrop of a nested dialog renders its element. |
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: DrawerBackdropState | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: DrawerBackdropState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
[hidden] | The drawer is closed, and keepMounted of the portal keeps the backdrop in the DOM. |
[data-swiping] | A swipe moves the popup. |
[data-swipe-dismiss] | The backdrop leaves after a swipe on the popup closed the drawer. |
CSS variables
| Variable | Description |
|---|---|
--drawer-swipe-progress | The progress of the popup toward its closed place: 0 at the open place, 1 at the closed place. A swipe or the active snap point sets it. |
--drawer-swipe-strength | A number from 0.1 to 1 that scales the duration of the leave after a swipe. A faster swipe gives a smaller number. It is 1 at other times. |
--drawer-height | The height of the frontmost drawer, in pixels, while --drawer-swipe-progress is above 0 and that drawer has a height. |
Drawer.Viewport
The container of the popup, where a swipe moves it. At its first move of 6 px, a touch drag goes
to the swipe or stays with the browser. A move that is more across the axis of the drawer than
along it stays with the browser. In a scroller on that axis, the swipe takes the drag only at the
edge of the scroller, for a move toward the closed place. A touch can start a swipe on a control
or in Drawer.Content. It starts none on a range input, or while the popup has a text selection.
A touch that starts outside the popup moves it from the point where the finger comes into it. A
mouse or a pen starts a swipe only in the popup. It starts none on a control, in Drawer.Content
or in a scroller on the axis. An element with data-vase-ui-swipe-ignore starts no swipe. With
the value x or y, the element takes the touch drags on that axis, and a touch drag on the
other axis still swipes the drawer.
Renders a <div> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: DrawerViewportState | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: DrawerViewportState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
[hidden] | The drawer is closed, and keepMounted of the portal keeps the viewport in the DOM. |
[data-nested] | The root of the drawer is inside a Dialog.Root, an AlertDialog.Root or a Drawer.Root. |
:has(> .v-leave-active) | The popup leaves. Use the leave class of the <Transition> around the popup. |
CSS variables
| Variable | Description |
|---|---|
--drawer-keyboard-inset | The height of the software keyboard over the bottom of the layout viewport, in pixels. Drawer.VirtualKeyboardProvider sets it only while a field of the drawer has the focus and the keyboard covers the layout viewport. |
Drawer.Popup
The container of the content of the drawer.
Renders a <div> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
finalFocus | FocusTarget | undefined | The element that gets the focus at the close, or false to keep the focus where it is. A
function gets the type of the interaction and gives the element. By default: the trigger, else
the element that had the focus before the open. After an open by code, that element comes
before the trigger. For an element that is no tab stop, the focus goes to its first tab stop
outside the popup. An element in the popup is no target. | |
id | string | undefined | The trigger names the popup by this id in aria-controls. | |
initialFocus | FocusTarget | undefined | The element that gets the focus at the open, or false to move no focus. A function gets the
type of the interaction and gives the element. By default the popup. A modal drawer makes the
page inert, so an element outside the popup cannot keep or get the focus. | |
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: DrawerPopupState | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: DrawerPopupState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
[hidden] | The drawer is closed, and keepMounted of the portal keeps the popup in the DOM. |
[data-expanded] | The drawer is at the snap point 1. |
[data-nested-drawer-open] | A drawer in this drawer is open. |
[data-nested-drawer-swiping] | A swipe moves a drawer in this drawer by 10 px or more. |
[data-swipe-direction] | The direction of the swipe that closes the drawer: up, down, left or right. |
[data-swiping] | A swipe moves the popup. |
[data-swipe-dismiss] | The popup leaves after a swipe on it closed the drawer. |
CSS variables
| Variable | Description |
|---|---|
--nested-drawers | The number of open drawers in this drawer, at each depth. The frontmost drawer has 0. |
--drawer-height | The height of the popup, in pixels, while a drawer in this drawer is open or leaves and the popup has a height. |
--drawer-frontmost-height | The height of the frontmost open drawer, in pixels, while that drawer has a height. On the frontmost drawer, it is the height of its own popup. |
--drawer-snap-point-offset | The distance from the open place to the active snap point, in pixels. It is negative for a drawer that closes up, and 0 with no snap point. |
--drawer-swipe-movement-x | The movement of the popup on the x axis during a swipe, in pixels. |
--drawer-swipe-movement-y | The movement of the popup on the y axis during a swipe, in pixels. |
--drawer-swipe-strength | A number from 0.1 to 1 that scales the duration of the leave after a swipe. A faster swipe gives a smaller number. It is 1 at other times. |
--drawer-swipe-progress | The progress of the swipe of a drawer in this drawer: 0 at its open place, 1 at its closed place. |
Drawer.Content
The content of the popup, where a mouse selects text and starts no swipe.
Renders a <div> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: DrawerContentState | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: DrawerContentState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
Drawer.Title
A heading that names the drawer.
Renders an <h2> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
id | string | undefined | The popup names the title by this id in aria-labelledby. | |
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: DialogTitleState | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: DialogTitleState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
Drawer.Description
A paragraph that describes the drawer.
Renders a <p> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
id | string | undefined | The popup names the description by this id in aria-describedby. | |
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: DialogDescriptionState | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: DialogDescriptionState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
Drawer.Close
A button that closes the drawer.
Renders a <button> element.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
disabled | boolean | undefined | false | The user cannot press the button. |
as | keyof HTMLElementTagNameMap | Component | GenericComponent | undefined | A tag or a component that the part renders in place of its own element, with the same
attributes and content. The element slot wins over it. |
Slots
| Slot | Slot props | Description |
|---|---|---|
default | state: DialogCloseState | The content of the part. |
element | props: Record<string, unknown>elementRef: (target: unknown) => voidstate: DialogCloseState | Renders your element in place of the element of the part. Bind props with v-bind and elementRef with :ref. |
Exposed
| Member | Type | Description |
|---|---|---|
element | HTMLElement | null | The element of the part, or null while it is not mounted. |
Selectors
| Selector | Description |
|---|---|
:disabled | The button is a native button, and it or a fieldset around it is disabled. |
[aria-disabled="true"] | The button is another element, and it is disabled. |
createHandle
Makes a handle that connects a Drawer.Root to Drawer.Trigger parts outside it.
Return value
DrawerHandle<Payload>
Handle
The class of the handle, which opens and closes the drawer from code.
Properties
| Property | Type | Modifiers | Description |
|---|---|---|---|
isOpen | boolean | readonly | The popup is open. It is false while no root has the handle. |
Methods
| Method | Returns | Description |
|---|---|---|
open(triggerId: string | null) | void | Opens the popup for the trigger with this id. With null, or with an id that no trigger of
the root has, the popup opens with no trigger. A development build warns for such an id, and
for a call with no mounted root. |
openWithPayload(payload: Payload) | void | Opens the popup with no trigger. The default slot of the root gets the payload until a trigger opens the popup. A development build warns for a call with no mounted root. |
close() | void | Closes the popup. With no mounted root, it does nothing. |
Differences from Base UI
Vase UI ports Drawer from Base UI 1.9.0.
API
| Base UI | Vase UI |
|---|---|
Drawer.Root prop onOpenChangeComplete | Listen to @after-enter and @after-leave of the <Transition> around the popup. They run after its animations end. |
Drawer.Root prop actionsRef | A template ref of the root has close(). To keep the popup until a JavaScript animation ends, give :css="false" to the <Transition> around it, and call done in its leave hook. |
Drawer.Trigger prop nativeButton | The trigger reads its element to know if it is a native button, so it needs no nativeButton. |
Drawer.Portal prop render | The portal is a <Teleport> and renders no element, so it has no as and no element slot. Put an element in the portal when you need one. |
Drawer.Backdrop | A <Transition> around the backdrop animates it, in place of data-starting-style, data-ending-style and the transitionStatus of the state. A closed backdrop leaves the DOM, or has [hidden] with keepMounted, so it needs no data-open and data-closed. |
Drawer.Viewport | The viewport is new in the DOM at each open, so a CSS animation on it runs at the open. :has(> .v-leave-active) selects it while its popup leaves, and [hidden] while keepMounted keeps it closed. These take the place of data-starting-style, data-ending-style, data-open, data-closed and the transitionStatus of the state. |
Drawer.Popup | A <Transition> around the popup animates it, in place of data-starting-style, data-ending-style and the transitionStatus of the state. A closed popup leaves the DOM, or has [hidden] with keepMounted, so it needs no data-open and data-closed. [data-swipe-dismiss] and [data-swipe-direction] with the leave class select the leave after a swipe. |
Drawer.Close prop nativeButton | The button reads its element to know if it is a native button, so it needs no nativeButton. |
Added in Vase UI
| Part | Member | Why |
|---|---|---|
Drawer.Root | update:triggerId event | v-model:trigger-id binds the active trigger, as v-model:open binds the open state. |
Drawer.Portal | disabled prop | The portal is a <Teleport>. With disabled, it renders its content in place, also in the server HTML. |
Drawer.Portal | defer prop | The portal is a <Teleport>. With defer, it moves its content after the rest of the update mounts, so its target can come later in the same template. |
Return types
| Function | Vase UI returns | Why |
|---|---|---|
Drawer.createHandle | DrawerHandle<Payload> | The return type names the class DrawerHandle, which the namespace exports as Drawer.Handle. |
Behavior
| Vase UI | Evidence |
|---|---|
When Drawer.SwipeArea unmounts during a swipe that opens the drawer, the swipe ends. The popup goes to its open place with no data-swiping and no transition: none, and the backdrop and Drawer.Indent lose the progress of the swipe. In Base UI, the unmount of the swipe area only lets an outside press close the drawer again. The popup stays at the place of the gesture, and the indent keeps its progress. | |
At the release of a swipe that closes the drawer, the backdrop gets the --drawer-swipe-strength of the popup, so the two leave in the same time. Base UI gives the backdrop a fixed strength of 1. | |
A touch outside an open popup closes it only at a tap. A tap ends with pointerup in less than 1 s and moves 8 px or less. Chromium on Android sends click for a move of 8 px and not for 8.1 px, the smallest limit of the measured browsers. A touch that scrolls the page ends with pointercancel and closes nothing, as a native popover stays open in Chromium and WebKit. A drag of more than 8 px on an element that does not scroll also closes nothing. A tap on a backdrop, or on the element that a modal popup puts over the page, closes the popup and gives the page under it no click. In Base UI, a touch that scrolls the page closes a Popover, a Menu or a Select. | |
A pointerdown listener that calls preventDefault() does not stop the swipe of a drawer or a toast. The call keeps its native meaning only: the browser sends no compatibility mouse events. An element in the popup or the toast stops the swipe with data-vase-ui-swipe-ignore, and a listener that calls stopPropagation() keeps the press from the part. Base UI starts no swipe from a press that a listener prevented. |
|
While a modal dialog or a modal drawer is open, each element outside it is inert, the trigger too, as with showModal() of a native <dialog>. An inert element cannot keep or take the focus. So with initialFocus of false, or a function that returns nothing, the dialog moves no focus into the popup, the trigger does not keep the focus, and Tab goes to the first tab stop of the dialog. An element outside a modal popup that initialFocus names takes no focus for the same reason. A dialog with modal of 'trap-focus' or false keeps its trigger in use, and there the focus stays on the trigger. Base UI leaves the focus on the trigger of a modal dialog and gives it to an outside element that initialFocus names, while it hides those elements from assistive technology. |
|
close() of a handle with no mounted root does nothing and gives no warning: the popup is closed, which is what the call asks for. When two mounted roots have one handle, the root that mounted last has the handle, and the other root gets it back when that root unmounts; the library gives no warning. Base UI warns in a development build in both cases. |
|
A button part knows the element of a component in as or of the element slot only at the mount, and it needs no prop that says what the element is. Until the mount, the element has the attributes that suit a <button> and each other element: type="button", role="button", a tab stop, and the disabled state of both. So in the server HTML, Tab reaches a <div> before a lazy hydration, and a <button> does not submit its form. At the mount, the part keeps the attributes of its element. Base UI needs nativeButton set to false for an element that is not a <button>. |
|
The handbook gives the differences that all components share: Styling, Animation, Composition, Customization, Forms and TypeScript.