Experimental.Drawer builds on an alpha primitive, so the API may still change in a future release.
Usage
Drawer shows a panel above the page without leaving the current view, for details of a record, a filter panel or a short form. It covers the page with a backdrop and keeps the rest of the page out of reach until it closes.
import {
MtDrawerRoot,
MtDrawerTrigger,
MtDrawerContent,
MtDrawerClose,
} from "@shopware-ag/meteor-component-library";
Examples
Floating
variant="floating" keeps an 8px distance to the viewport edges and gives the panel a border with rounded corners.
Sides
side picks the edge the drawer slides in from. size sets the width of a start or end drawer and the height of a top or bottom drawer.
Confirm before closing
Set dismissible to false while a form has unsaved changes. A click on the backdrop, Escape or a swipe then emits dismiss-prevented instead of closing, so you can ask before the changes are lost.
Anatomy
mt-drawer-rootholds the open state (v-model:open) and decides whether the drawer may be dismissed.mt-drawer-triggeropens the drawer. Passasto render another component, such as Button.mt-drawer-contentrenders the backdrop and the panel with a header (title, subtitle, close button), the content and an optionalfooterslot.mt-drawer-closecloses the drawer from anywhere inside it, also when it is not dismissible.
API reference
Root
Props
| Prop | Type | Default |
|---|---|---|
openWhether the drawer is open. Bind it with `v-model:open` or leave it out to let the drawer manage it. | false | true | undefined |
default-openWhether the drawer starts open when `open` is not bound. | false | true | false |
dismissibleWhether a click on the backdrop, Escape or a swipe closes the drawer. When `false`,
these emit `dismiss-prevented` instead, for example to confirm discarding unsaved changes.
Close buttons always close the drawer. | false | true | true |
Events
| Event | Payload |
|---|---|
update:open | [open: boolean] |
dismiss-prevented | [details: { reason: MtDrawerDismissReason; }] |
Slots
| Slot | Bindings |
|---|---|
default | { open: boolean; close: () => void; } |
Content
Props
| Prop | Type | Default |
|---|---|---|
title *The title of the drawer. It is also the accessible name of the dialog. | string | |
subtitleA short description below the title. | string | undefined |
sideThe edge of the viewport the drawer slides in from. | "end" | "start" | "top" | "bottom" | "end" |
variant`floating` keeps an 8px distance to the viewport edges and gets a border with rounded corners. | "default" | "floating" | "default" |
sizeThe width of a `start` or `end` drawer, or the height of a `top` or `bottom` drawer,
as a CSS length such as `"30rem"`. Without it, the drawer takes the size of its content. | string | undefined |
insetRemoves the padding around the content. | false | true | false |
hide-headerHides the header with the title and the close button. The title stays available to assistive technology. | false | true | false |
keep-mountedKeeps the content mounted while the drawer is closed, so its state survives. | false | true | false |
Slots
| Slot | Bindings |
|---|---|
default | any |
footer | any |
Trigger and close
Props
| Prop | Type | Default |
|---|---|---|
asThe element or component to render, for example `MtButton`. | string | Component | "button" |
Slots
| Slot | Bindings |
|---|---|
default | {} |
Best practices
Do
- Use a drawer for tasks that relate to the current view and can be finished without leaving it.
- Always give the drawer a
title; it is the accessible name of the dialog, also withhide-header. - Guard forms with
dismissibleanddismiss-preventedinstead of blocking close buttons.
Behavior
- Dismissing. A click on the backdrop, Escape and a swipe towards the edge close the drawer. With
dismissibleset tofalsethey emitdismiss-preventedwith the reason (outside-click,escape-keyorswipe) and the drawer stays open.mt-drawer-closeand the close button in the header always close it. - Mounting. The content is mounted while the drawer is open and removed after it closed. With
keep-mountedit stays mounted, so its state survives closing and opening. - Layering. Drawers share the modal layer with Modal. While a drawer is open, the page behind it is inert. Overlays opened from inside it, such as select result lists, date pickers, popovers and a confirmation modal, render above it and stay usable, and Escape closes the innermost of them first.
- Size. Without
size, the drawer takes the size of its content, up to the viewport size minus 48px.
Accessibility
- The panel is a modal dialog named by its
title;subtitlebecomes its description. - The panel receives the focus when it opens. Tab and Shift+Tab stay inside it, and the focus returns to the element that opened it when it closes.
- Escape closes the drawer while the focus is inside it.
- The slide animation is skipped when the user prefers reduced motion.