A panel that slides in from the edge of the screen and can be swiped away.
Installation
Add the following to your global styles. On iOS Safari, the drawer overlay is absolutely positioned and requires a positioned body to cover the viewport after the page is scrolled.
body {
position: relative;
}Usage
<Drawer>
<DrawerTrigger>
<Render>
<Button @attributes="context.Attributes" Variant="ButtonVariant.Outline">Open</Button>
</Render>
</DrawerTrigger>
<DrawerContent>
<DrawerHeader>
<DrawerTitle>Are you absolutely sure?</DrawerTitle>
<DrawerDescription>This action cannot be undone.</DrawerDescription>
</DrawerHeader>
<div class="p-4">...</div>
<DrawerFooter>
<Button>Submit</Button>
<DrawerClose>
<Render>
<Button @attributes="context.Attributes" Variant="ButtonVariant.Outline">Cancel</Button>
</Render>
</DrawerClose>
</DrawerFooter>
</DrawerContent>
</Drawer>Composition
Use the following composition to build a Drawer:
Drawer
├── DrawerTrigger
└── DrawerContent
├── DrawerHeader
│ ├── DrawerTitle
│ └── DrawerDescription
└── DrawerFooterDrawerContent composes the portal, overlay, viewport, and popup from Blazix.Primitives. For lower-level control, DrawerPortal, DrawerOverlay, and DrawerSwipeHandle are also exported.
Custom Sizes
A vertical drawer sizes itself to its content and is capped at calc(100dvh - 6rem) by default. A side drawer spans 75% of the viewport width, or 24rem on larger screens.
To customize the height of a vertical drawer, use the h-* and max-h-* utilities on DrawerContent.
<DrawerContent Class="h-[50vh]">...</DrawerContent>To customize the width of a side drawer, use the w-* and max-w-* utilities on DrawerContent.
<DrawerContent Class="w-96">...</DrawerContent>When the same component renders in multiple directions, scope an override to one axis using the data-[swipe-axis=*] variants.
<DrawerContent Class="data-[swipe-axis=y]:max-h-[50vh] data-[swipe-axis=x]:w-96">...</DrawerContent>To make a region of the drawer scrollable, make the scroll container a flex item. Avoid h-full, which does not resolve inside a content-sized drawer.
<DrawerContent>
<DrawerHeader>...</DrawerHeader>
<div class="flex-1 overflow-y-auto p-4">...</div>
<DrawerFooter>...</DrawerFooter>
</DrawerContent>Styling
The drawer exposes CSS variables for style-level customization. Set the sizing variables on DrawerContent. Set the overlay variable on [data-slot=drawer-overlay] in your CSS.
The drawer also sets data attributes you can target with variants such as data-[swipe-direction=down]: on DrawerContent, or group-data-[swipe-axis=y]/drawer-popup: on its descendants.
Position
Use the SwipeDirection parameter to set the side of the drawer.
Available options are DrawerSwipeDirection.Up, Right, Down (the default), and Left.
Swipe Handle
Use ShowSwipeHandle on Drawer to render a swipe handle.
Nested
Open drawers from inside another drawer. Parent drawers stay mounted and stack behind the frontmost drawer.
Non Modal
Set Modal="false" to allow interaction with the rest of the page while the drawer is open. Combine with DisablePointerDismissal to prevent the drawer from closing on outside presses.
Snap Points
Use SnapPoints to snap a drawer to preset heights. Numbers between 0 and 1 represent fractions of the viewport. Numbers greater than 1 are treated as pixel values. String values support px and rem units. Snap points apply to vertical drawers.
Track the active snap point with @bind-SnapPoint. At the full snap point, the drawer gets a data-expanded attribute you can style with the data-expanded: variant.
Responsive
You can combine the Dialog and Drawer components to create a responsive dialog. This renders a Dialog component on desktop and a Drawer on mobile.
RTL
To enable RTL support in Blazix, see the RTL configuration guide.
Translated with AI for the demo, so it may have mistakes.
API Reference
Drawer
DrawerClose
Other attributes are passed to the element it renders.
DrawerContent
Other attributes are passed to the element it renders.
DrawerDescription
Other attributes are passed to the element it renders.
DrawerFooter
Other attributes are passed to the element it renders.
DrawerHeader
Other attributes are passed to the element it renders.
DrawerOverlay
Other attributes are passed to the element it renders.
DrawerPortal
DrawerSwipeHandle
Other attributes are passed to the element it renders.
DrawerTitle
Other attributes are passed to the element it renders.
DrawerTrigger
Other attributes are passed to the element it renders.