Skip to content
🌏 Translated with the assistance of DeepSeek and ChatGPT

Drawer

A dialog that pops out from the edge of the window.

When you need to display a large amount of content in a popup, this component may provide a better visual effect than Dialog. The Drawer component uses an API design similar to Dialog.

Basic Usage

visible controls whether the Drawer is shown or hidden. Passing visible puts it in controlled mode. If you don't pass it or pass undefined, it will be in uncontrolled mode; you can then use the defaultVisible prop as the default value.

Hide source code

show-footer controls whether the bottom area is displayed, defaulting to false. When show-footer is enabled, you can use the footer slot to provide footer content.

Hide source code

Placement

The placement prop sets where the drawer appears from.

Hide source code

Styling

As shown in the example, you can directly pass attrs like class and style which will be forwarded to the drawer container element.

Hide source code

Functional

If you have fully registered the component library, you can use the Drawer functionally in the following ways:

  • window.$drawer;
  • Inside a Vue component: getCurrentInstance().appContext.config.globalProperties.PixeliumVue.drawer;
  • Import from @pixelium/web-vue.

When importing on demand, you can also import Drawer from @pixelium/web-vue/es.

Hide source code

API

Drawer Function

ts
export type DrawerReturn = {
	close: () => void
}

// ...
// Drawer
{
	open: (
		options: (DrawerOptions & Omit<EmitEvent<DrawerEvents>, 'update:visible'>) | string
	) => DrawerReturn
}

Attrs

As shown in the example above, when using it as a component, you can directly pass attrs like class and style that will be forwarded to the drawer container element.

DrawerOptions

AttributeTypeOptionalDefaultDescriptionVersion
contentValidContentFalseThe main content of the Drawer.0.2.0
titleValidContentTrueThe title of the Drawer.0.2.0
footerValidContentTrueThe footer area of the Drawer.0.2.0
placement'right' | 'left' | 'top' | 'down'True'right'The placement where the Drawer appears.0.2.0
closablebooleanTruetrueWhether to show the close button in the upper right corner.0.2.0
maskbooleanTruetrueWhether to show the mask layer.0.2.0
maskClosablebooleanTruetrueWhether clicking the mask layer closes the Drawer.0.2.0
escToClosebooleanTruetrueWhether pressing the ESC key closes the Drawer.0.2.0
showFooterbooleanTruefalseWhether to show the footer area of the Drawer.0.2.0
zIndexnumberTrueThe z-index property of the Drawer.0.2.0
rootstring | HTMLElementTrue'body'The root element where the Drawer is mounted.0.2.0
maskPropsOmit<MaskProps, 'zIndex'>TrueProps for the mask layer.0.2.0
containerPropsRestAttrsTrueProps for the Drawer container element.0.2.0
headerPropsRestAttrsTrueProps for the Drawer header area element.0.2.0
bodyPropsRestAttrsTrueProps for the Drawer content area element.0.2.0
footerPropsRestAttrsTrueProps for the Drawer footer area element.0.2.0

DrawerProps

AttributeTypeOptionalDefaultDescriptionVersion
visibleboolean | nullTrueControls the visibility of the Drawer, controlled mode, supports v-model.0.2.0
defaultVisibleboolean | nullTrueThe default visibility value of the Drawer, uncontrolled mode.0.2.0
titlestringTrue''The title of the Drawer.0.2.0
placement'right' | 'left' | 'top' | 'down'True'right'0.2.0
closablebooleanTruetrueWhether to show the close button in the upper right corner.0.2.0
maskbooleanTruetrueWhether to show the mask layer.0.2.0
maskClosablebooleanTruetrueWhether clicking the mask layer closes the Drawer.0.2.0
escToClosebooleanTruetrueWhether pressing the ESC key closes the Drawer.0.2.0
showFooterbooleanTruefalseWhether to show the footer area of the Drawer.0.2.0
rootstring | HTMLElementTrue'body'The root element where the Drawer is mounted.0.2.0
zIndexnumberTrueThe z-index property of the Drawer.0.2.0
destroyOnHidebooleanTruefalseWhether the Drawer content is destroyed after hiding.0.2.0
maskPropsOmit<MaskProps, 'zIndex'>TrueProps for the mask layer.0.2.0
containerPropsRestAttrsTrueProps for the Drawer container element.0.2.0
headerPropsRestAttrsTrueProps for the Drawer header area element.0.2.0
bodyPropsRestAttrsTrueProps for the Drawer content area element.0.2.0
footerPropsRestAttrsTrueProps for the Drawer footer area element.0.2.0

DrawerSlots

SlotParameterDescriptionVersion
defaultThe main content of the Drawer.0.2.0
titleThe title of the Drawer.0.2.0
footerThe footer area of the Drawer.0.2.0

DrawerEvents

EventParameterDescriptionVersion
update:visibleUsed to update the visible value in controlled mode.0.2.0
exitevent: MouseEvent | KeyboardEvent0.2.0
openCallback when the Drawer opens.0.2.0
afterOpenCallback after the Drawer opening animation ends.0.2.0
closeCallback when the Drawer closes.0.2.0
afterCloseCallback after the Drawer closing animation ends.0.2.0

DrawerExpose

AttributeTypeOptionalDefaultDescriptionVersion
close() => voidFalseCloses the Drawer.0.2.0
open() => voidFalseOpens the Drawer.0.2.0

ValidContent, ValidVNodeContent

ts
export type ValidContent = string | ((...args: any[]) => VNode | string | JSX.Element | null | void)
export type ValidVNodeContent = (...args: any[]) => VNode | JSX.Element

RestAttrs

ts
import type { StyleValue } from 'vue'

export type VueClassValue = string | Record<string, any> | VueClassValue[]
export type VueStyleValue = StyleValue

export type RestAttrs = {
	style?: VueStyleValue | null
	class?: VueClassValue | null
	[x: string]: any
}

EmitEvent

ts
export type EmitEvent<T extends Record<string, any>> = {
	[K in keyof T as `on${Capitalize<K & string>}`]?: (...args: T[K]) => void
}