Skip to content

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
展开代码

Use the footer slot to add a footer action bar.

Code Demo
展开代码

API Reference ​

Props ​

ParameterDescriptionTypeOptionsDefault
modelValueWhether to show the drawerboolean—false
titleDrawer titlestring—''
directionDrawer opening directionstringltr/rtl/ttb/bttrtl
sizeDrawer sizestring | number—30%
with-headerWhether to show the headerboolean—true
show-closeWhether to show the close buttonboolean—true
background-colorDrawer background colorstring—''
close-on-click-modalWhether to close the drawer by clicking on the mask layerboolean—true
close-on-press-escapeWhether to close the drawer by pressing ESCboolean—true
lock-scrollWhether to lock body scroll when drawer is shownboolean—true
before-closeCallback function before closingfunction—undefined

Events ​

Event NameDescriptionParameters
update:modelValueTriggered when drawer display state changesvalue: boolean
openTriggered when drawer opens—
closeTriggered when drawer closes—

Slots ​

Slot NameDescription
defaultDrawer main content
titleDrawer title content
footerDrawer 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;
}

Released under the MIT License.