Basic Setup
1
Import Components
Import the essential drawer components into your Svelte file:
2
Create State
Use Svelte 5’s
$state rune to manage the drawer’s open/closed state:Svelte Drawer is built for Svelte 5 and uses the new runes syntax. The
$state rune creates reactive state.3
Add Trigger Button
Create a button to open the drawer:
4
Build the Drawer
Add the drawer structure with overlay, content, and handle:
Complete Example
Here’s the complete code for a working drawer:Understanding the Components
Drawer
Drawer
The main wrapper component that manages state, animations, and gesture handling. Use
bind:open to control visibility.DrawerOverlay
DrawerOverlay
The semi-transparent backdrop that appears behind the drawer. Clicking it dismisses the drawer.
DrawerContent
DrawerContent
The container for your drawer content. Includes drag detection and focus management.
DrawerHandle
DrawerHandle
The visual drag indicator at the top of the drawer. Provides a clear affordance for gesture interactions.
Try Different Directions
The drawer can slide from any edge of the screen:What’s Next?
Now that you have a basic drawer working, explore more advanced features:Variants
Use prebuilt variants like sheet, dialog, and sidebar
Snap Points
Create iOS-like drawers with multiple snap positions
Styling & Blur
Customize appearance and add blur effects to overlays
Portal Rendering
Escape z-index conflicts with portal rendering