Drawer
A modal panel that slides in from an edge of the screen.
Usage
Basic
With a confirmation dialog open on top, Tab stays inside it and Escape closes only the dialog.
Loading demo...
Direction
direction takes four edges; size is the width for left and right, and the height for top and bottom.
Loading demo...
Size and Fullscreen
size takes a number (px), a CSS length, a percentage, or 'full'; full equals size="full".
Loading demo...
Header, Footer, and Mask
The header and footer slots receive close; maskEffect sets the mask look, and panelTransparent lets the page show through the panel.
Loading demo...
Form
When close isn't needed, the footer slot can update outside state directly.
<template>
<TxDrawer v-model:visible="visible" title="Form">
<form>
<input type="text" placeholder="Name" />
</form>
<template #footer>
<TxButton @click="visible = false">Cancel</TxButton>
<TxButton type="primary" @click="handleSave">Save</TxButton>
</template>
</TxDrawer>
</template>
Close Behavior
<template>
<!-- Clicking the mask doesn't close it -->
<TxDrawer v-model:visible="visible" title="Persistent" :close-on-click-mask="false">
<p>Only the close button closes this drawer</p>
</TxDrawer>
<!-- Escape doesn't close it -->
<TxDrawer v-model:visible="visible2" title="No Escape" :close-on-press-escape="false">
<p>Escape does not close this drawer</p>
</TxDrawer>
</template>
Open and Close Events
<template>
<TxDrawer v-model:visible="visible" title="Events" @open="handleOpen" @close="handleClose">
<p>Content</p>
</TxDrawer>
</template>
Dashboard Navigation
Tabs hold the top-level sections, DropdownMenu the light actions, Popover the short notes, and Drawer the dense settings.
Loading demo...
Best Practices
- Put long forms, audit details, permission matrices, and flows that need a footer action bar in a drawer, not a popover.
- Give a meaningful
titleeven withshowHeader=false; it is the dialog's accessible name. - Size the drawer with
sizeorfull;widthexists only for older call sites. - Set
mobileAdapt=falseonly when a side entrance matters more on small screens than a bottom sheet. - Let the drawer manage focus instead of moving it from outside; form fields in the body still need explicit labels.
API Reference
Props
| Property | Type | Default | Description |
|---|---|---|---|
| visible | Whether the drawer is shown; bind with `v-model:visible`. | ||
| title | Title; becomes the `aria-label` when no header renders. | ||
| size | Size on the active axis: width for left/right, height for top/bottom; numbers are px, `full` is 100%. | ||
| full | Opens at 100% on the active axis; same as `size="full"`. | ||
| width | - | Legacy alias; use `size`. | |
| direction | Edge the drawer slides in from. | ||
| showHeader | Renders the header area. | ||
| showFooter | Renders the footer slot area. | ||
| showClose | Shows the close button in the default header. | ||
| closeOnClickMask | Closes when the mask is clicked. | ||
| closeOnPressEscape | Closes when Escape is pressed. | ||
| maskEffect | Mask look: blurred, dimmed only, or transparent. | ||
| panelTransparent | Makes the panel translucent so the page shows through. | ||
| mobileAdapt | Forces a bottom entrance when the viewport is 768px wide or less. | ||
| zIndex | - | Fixed layer; without it the z-index manager allocates from `10000`. | |
| lazy | Skips slot content until the first open, then keeps it; set `false` to mount eagerly. |
Events
| Property | Type | Default | Description |
|---|---|---|---|
| update:visible | - | Fires when visibility changes. | |
| open | - | Fires when `visible` turns `true`. | |
| close | - | Fires when the user closes the drawer; not when the parent sets `visible`. |
Slots
| Property | Type | Default | Description |
|---|---|---|---|
| default | - | - | Main content. |
| header | - | - | Replaces the default title and close button; slot props: `{ close, title, titleId }`. |
| footer | - | - | Footer action area; slot props: `{ close }`. |
Overview
- The root is
role="dialog"witharia-modal="true"; with a header it usesaria-labelledby, otherwisetitlebecomes thearia-label. - Opening focuses the drawer and Tab cycles inside it; closing or unmounting returns focus to the previously focused element.
- The close button, the mask, and Escape all emit
update:visible(false)andclose;closeOnClickMaskandcloseOnPressEscapeturn off the last two. - Only the topmost modal dialog handles Tab and Escape, and keys another control already handled are ignored, so a confirmation on top owns them.
- When closed, the root stays in the DOM with
inertandaria-hidden.
Technologies
- The header and footer dividers are
TxDivider; don't hard-code borders for them. - Source:
packages/tuffex/packages/components/src/drawer/.
查看源码
packages/tuffex/packages/components/src/drawer/index.ts