Overview
TheDrawer component is the main wrapper that manages the drawer’s state, animations, and lifecycle. It provides context to all child components and handles keyboard interactions, focus management, and optional state persistence.
Props
Controls the open/closed state of the drawer. Use
bind:open for two-way binding.Callback function fired when the drawer’s open state changes. Useful for side effects or tracking.
Direction from which the drawer slides in.
Whether pressing the Escape key closes the drawer.
Array of snap positions between 0 and 1 (e.g.,
[0.25, 0.5, 0.9] for 25%, 50%, and 90% of screen height). Creates an iOS-like sheet experience.Current active snap point value. Use
bind:activeSnapPoint to programmatically control the drawer position.Callback fired when the active snap point changes.
Render the drawer in a portal at the end of the document body to avoid z-index conflicts.
Custom portal container element or CSS selector. Only used when
portal={true}.Automatically save and restore drawer state (open/closed) across page reloads using localStorage.
Unique identifier for this drawer when using
persistState. Required when using multiple persistent drawers.Whether to persist the snap point position along with the drawer state. Only used when
persistState={true} and snapPoints are defined.Usage Example
Features
- State Management: Controls drawer visibility and animations
- Keyboard Support: Escape key to close (configurable)
- Focus Management: Auto-focus and focus restoration
- Snap Points: iOS-like multi-height drawers
- Portal Rendering: Escape z-index conflicts
- State Persistence: Save drawer state across reloads
- Flexible Directions: Bottom, top, left, or right drawers
Related Components
- DrawerContent - Content container with drag handling
- DrawerOverlay - Background overlay
- DrawerHandle - Visual drag indicator
- DrawerVariants - Pre-styled drawer variants
- DrawerPortal - Portal rendering component