Drawer
Introduction
The Drawer component is a panel that slides out from the edge of the page, commonly used to display more content or operations. mengyue-components has encapsulated this component and conducted vitest testing. You can use <MYDrawer></MYDrawer> or <MYDrawer /> to implement drawer functionality.
Basic Usage
Basic Drawer
A basic drawer component that slides out from the right by default.
Code Demo
展开代码
Different Directions
Use the direction prop to set the drawer's slide-out direction.
Code Demo
展开代码
Custom Size
Use the size prop to set the drawer's size.
Code Demo
展开代码
Custom Background Color
Use the backgroundColor prop to customize the drawer's background color.
Code Demo
展开代码
Hide Header and Close Button
Use the with-header and show-close props to control the display of the header and close button.
Code Demo
展开代码
With Footer Action Bar
Use the footer slot to add a footer action bar.
Code Demo
展开代码
API Reference
Props
| Parameter | Description | Type | Options | Default |
|---|---|---|---|---|
| modelValue | Whether to show the drawer | boolean | — | false |
| title | Drawer title | string | — | '' |
| direction | Drawer opening direction | string | ltr/rtl/ttb/btt | rtl |
| size | Drawer size | string | number | — | 30% |
| with-header | Whether to show the header | boolean | — | true |
| show-close | Whether to show the close button | boolean | — | true |
| background-color | Drawer background color | string | — | '' |
| close-on-click-modal | Whether to close the drawer by clicking on the mask layer | boolean | — | true |
| close-on-press-escape | Whether to close the drawer by pressing ESC | boolean | — | true |
| lock-scroll | Whether to lock body scroll when drawer is shown | boolean | — | true |
| before-close | Callback function before closing | function | — | undefined |
Events
| Event Name | Description | Parameters |
|---|---|---|
| update:modelValue | Triggered when drawer display state changes | value: boolean |
| open | Triggered when drawer opens | — |
| close | Triggered when drawer closes | — |
Slots
| Slot Name | Description |
|---|---|
| default | Drawer main content |
| title | Drawer title content |
| footer | Drawer footer content |
Type Definitions
typescript
interface DrawerProps {
modelValue?: boolean;
title?: string;
direction?: 'ltr' | 'rtl' | 'ttb' | 'btt';
size?: string | number;
withHeader?: boolean;
showClose?: boolean;
backgroundColor?: string;
closeOnClickModal?: boolean;
closeOnPressEscape?: boolean;
lockScroll?: boolean;
beforeClose?: (done: () => void) => void;
}