Directory
- Welcome
Drawer Component
The Drawer component creates a mobile-optimized bottom sheet that slides up from the screen’s bottom edge. It provides a native-feeling experience with smooth animations, gesture controls, and accessibility features built-in.
Key Features
-
Intuitive: Natural touch gestures and smooth animations
-
Responsive: Optimized for mobile and desktop interactions
-
Accessible: Keyboard navigation and screen reader support
-
Flexible: Customizable content and styling options
Basic Implementation
<Button id="drawer-trigger">Open Settings</Button>
<Drawer triggerQuery="#drawer-trigger"> <h2 class="text-xl font-bold">Settings</h2> <p>Configure your preferences here.</p></Drawer>
Live Demo
Try the interactive example:
Features
Interaction Methods
-
Touch Gestures
- Drag to dismiss
- Velocity-based animations
- Natural-feeling physics
-
Click Actions
- Trigger button to open
- Close button to dismiss
- Backdrop tap to close
-
Keyboard Support
- Escape key dismissal
- Focus trap navigation
- ARIA attribute integration
Drawer Component API
Prop | Type | Default | Description |
---|---|---|---|
triggerQuery | string | CSS selector for trigger element | |
closeText | string | Close | Custom close button text |
closeButtonProps | ButtonProps | {} | Props for close button |
Drawer Functions API
The drawer component provides a set of functions to interact with the drawer:
Function | Type | Description |
---|---|---|
toggle | (force?: boolean) => void | Toggles the drawer, optionally force open or closed |
Event Handling
The component emits custom events for changes:
document.querySelector('drawer-wrapper').addEventListener(DrawerEventNames.Open, (event) => { // Handle open});
document.querySelector('drawer-wrapper').addEventListener(DrawerEventNames.Close, (event) => { // Handle close});
Common Use Cases
Limited Time Launch Sale
Create engaging mobile experiences with our pre-built Drawer component. Get started with our AstroJS template today.
GET 60% OFF!