Drawer
A panel that slides in from the side of the screen to show details, a short form or filters without leaving the page.
zb:drawer zubazar/ui · free (MIT)
Basic usage
Give the panel a unique name and open it with zb:drawer.trigger; X, Esc, the backdrop and a link in the panel close it.
<zb:drawer.trigger name="catalog-details"><zb:button variant="white">Open the customer summary</zb:button></zb:drawer.trigger>
<zb:drawer name="catalog-details" title="Customer summary">
<dl class="space-y-3 text-sm">
<div class="flex justify-between"><dt class="text-muted">Membership</dt><dd>Premium</dd></div>
<div class="flex justify-between"><dt class="text-muted">Orders</dt><dd>5</dd></div>
</dl>
<zb:slot:footer>
<zb:drawer.close><zb:button variant="white">Close</zb:button></zb:drawer.close>
</zb:slot:footer>
</zb:drawer>
| Prop | Values |
|---|---|
name | Unique name |
title | Header line (with the X button) |
footer | Slot: footer |
Side and width
side picks the edge it opens from; set the width with size (md ≈ 448px, sm ≈ 320px) or with width, which takes a max-w-* class.
<div class="flex flex-wrap gap-2" x-data>
<zb:drawer.trigger name="catalog-left"><zb:button variant="white">From the left, sm</zb:button></zb:drawer.trigger>
<zb:drawer.trigger name="catalog-wide"><zb:button variant="white">From the right, max-w-2xl</zb:button></zb:drawer.trigger>
</div>
<zb:drawer name="catalog-left" side="left" size="sm" title="Shortcuts">
<p class="text-sm">A narrow panel that opens from the left.</p>
</zb:drawer>
<zb:drawer name="catalog-wide" width="max-w-2xl" title="Order history">
<p class="text-sm">A wider panel for wide content such as tables.</p>
</zb:drawer>
| Prop | Values |
|---|---|
side | right | left |
size | sm | md |
width | max-w-* class (replaces size) |
Form panel
With :closable-on-backdrop="false", a backdrop click does not close the panel, so a half-filled form is not lost.
<zb:drawer.trigger name="catalog-form"><zb:button variant="white">Add a note</zb:button></zb:drawer.trigger>
<zb:drawer name="catalog-form" :closable-on-backdrop="false">
<zb:drawer.header title="Order note" description="#10482 · Ayşe Yılmaz" />
<zb:drawer.body class="space-y-4">
<zb:input name="subject" label="Subject" />
<zb:textarea name="note" label="Note" rows="4" autofocus />
</zb:drawer.body>
<zb:drawer.footer>
<zb:drawer.close><zb:button variant="white">Cancel</zb:button></zb:drawer.close>
<zb:drawer.close><zb:button>Save</zb:button></zb:drawer.close>
</zb:drawer.footer>
</zb:drawer>
| Prop | Values |
|---|---|
closable-on-backdrop | true | false |
autofocus | Field to focus on open |
Binding with Livewire
wire:model binds the panel to a Livewire property: it opens when the property is true, and the property becomes false when the user closes it.
<zb:button wire:click="showDetails(4821)">Order details</zb:button>
<zb:drawer name="order-details" wire:model="detailsOpen">
<zb:drawer.header :title="'Order #'.$orderNo" description="Kadıköy warehouse · 3 items" />
<zb:drawer.body>
<p class="text-sm">Recipient: Ayşe Yılmaz · Status: Processing</p>
</zb:drawer.body>
<zb:drawer.footer>
<zb:drawer.close><zb:button variant="white">Close</zb:button></zb:drawer.close>
<zb:button wire:click="markShipped">Ship order</zb:button>
</zb:drawer.footer>
</zb:drawer>
| Prop | Values |
|---|---|
wire:model · wire:model.live | Livewire property (bool) |
x-model | Alpine data (bool) |
Composable parts
Build the panel from the zb:drawer.header, zb:drawer.body and zb:drawer.footer parts; with toggle, zb:drawer.trigger opens and closes it.
<zb:drawer.trigger name="order-4821">
<zb:button variant="white">Order details</zb:button>
</zb:drawer.trigger>
<zb:drawer name="order-4821">
<zb:drawer.header title="Order #4821" description="Kadıköy warehouse · 3 items · Agent: Ayşe Yılmaz" />
<zb:drawer.body class="space-y-4">
<zb:input name="recipient" label="Recipient" value="Mehmet Kaya" />
<zb:select name="status" label="Order status" :options="['processing' => 'Processing', 'shipped' => 'Shipped', 'delivered' => 'Delivered']" />
<zb:textarea name="note" label="Agent note" rows="3" />
</zb:drawer.body>
<zb:drawer.footer>
<zb:drawer.close>
<zb:button variant="white">Cancel</zb:button>
</zb:drawer.close>
<zb:drawer.close>
<zb:button x-on:click="$dispatch('toast', { type: 'success', message: 'Order updated.' })">Save</zb:button>
</zb:drawer.close>
</zb:drawer.footer>
</zb:drawer>
| Prop | Values |
|---|---|
zb:drawer.trigger | name, toggle |
zb:drawer.header | title, description |
zb:drawer.body · footer | Body and footer |
zb:drawer.close | The element inside closes the panel |
Props
The values the component takes. What are props and slots?
| Prop | Type | Default | Description |
|---|---|---|---|
name | — | — | Required. The name used in the events and the ZubazarUI.drawer.open('…') call |
title | — | null | Header line (with X) and accessible name |
side | — | right | right · left |
size | — | md | md (max-w-md) · sm (max-w-xs) |
width | — | null | max-w-* class; when given, size is not used |
floating | boolean | false | Panel inset from the edges, with rounded corners |
backdrop | boolean | true | Dims the background |
lock-scroll | boolean | true | Keeps the page from scrolling while open |
closable-on-backdrop | boolean | true | Closes on a backdrop click |
wire:model · x-model | — | — | Binds the open/closed state to a Livewire property or Alpine data |
compact | boolean | false | Tight spacing in the footer |
docked | boolean | false | Filters panel behavior of list pages (in the Zubazar UI Pro panel layouts) |
aria-label | — | null | Accessible name when there is no title; when empty, "Menu" (in the app language) |
body-class | — | flex-1 p-5 overflow-y-auto | Classes of the body wrapper |
drawer.trigger: name · toggle | — | — | Opens the panel; with toggle, closes it if open. aria-expanded is added to the button |
drawer.header: title · description | — | null | Header line and X |
drawer.body · drawer.footer | — | — | Scrolling body and footer (follow the compact and docked settings) |
drawer.close | — | — | Clicking the element inside closes the panel |
Slots: default: panel content · header: replaces the header line (no X is added) · footer: footer. Inside the slots, close() closes the panel.
Advanced
Floating panel
floating shows the panel inset from the edges, like a card with rounded corners; it suits short content.
<zb:drawer.trigger name="catalog-floating"><zb:button variant="white">Open the floating panel</zb:button></zb:drawer.trigger>
<zb:drawer name="catalog-floating" floating title="Notifications">
<ul class="space-y-3 text-sm">
<li>12 orders were shipped from the Kadıköy warehouse.</li>
<li>Ayşe Yılmaz added a new customer.</li>
</ul>
</zb:drawer>
| Prop | Values |
|---|---|
floating | true | false |
Custom header
The header slot replaces the header line, and no X is added. Add a close button yourself with zb:drawer.close and give the panel an aria-label.
<zb:drawer.trigger name="catalog-person"><zb:button variant="white">Show the support agent</zb:button></zb:drawer.trigger>
<zb:drawer name="catalog-person" aria-label="Support agent">
<zb:slot:header>
<div class="flex items-center gap-3 pb-4">
<zb:avatar name="Ayşe Yılmaz" />
<div class="min-w-0 flex-1">
<p class="text-sm font-semibold text-ink">Ayşe Yılmaz</p>
<p class="text-xs text-muted">Support agent · Business accounts</p>
</div>
<zb:drawer.close><zb:button variant="ghost" size="icon" aria-label="Close"><zb:icon name="x-mark" /></zb:button></zb:drawer.close>
</div>
</zb:slot:header>
<p class="text-sm">Answered 112 support tickets this month.</p>
</zb:drawer>
| Prop | Values |
|---|---|
header | Slot: replaces the header line |
aria-label | Accessible name when there is no title |
Without a backdrop
:backdrop="false" removes the dimming and :lock-scroll="false" lets the page behind scroll. Clicking outside still closes the panel; closable-on-backdrop controls that.
<zb:drawer.trigger name="catalog-plain"><zb:button variant="white">Open without a backdrop</zb:button></zb:drawer.trigger>
<zb:drawer name="catalog-plain" title="Help" :backdrop="false" :lock-scroll="false">
<p class="text-sm">Help text at the side while the page stays visible.</p>
</zb:drawer>
| Prop | Values |
|---|---|
backdrop | true | false |
lock-scroll | true | false |
Livewire component
The component of the "Binding with Livewire" example. Setting the property to true is enough to open the panel.
use Livewire\Component;
class OrderDetails extends Component
{
public bool $detailsOpen = false;
public ?int $orderNo = null;
public function showDetails(int $no): void
{
$this->orderNo = $no;
$this->detailsOpen = true;
}
public function markShipped(): void
{
// … update the record
$this->detailsOpen = false;
}
}
Events
The panel listens for zb:drawer:open, zb:drawer:close and zb:drawer:toggle and dispatches zb:drawer:opened and zb:drawer:closed, all with { name }. In JavaScript, ZubazarUI.drawer.open('…'), close('…') and toggle('…') do the same.
<div class="flex items-center gap-3" x-data="{ isOpen: false }"
x-on:zb:drawer:opened.window="if ($event.detail.name === 'catalog-notes') isOpen = true"
x-on:zb:drawer:closed.window="if ($event.detail.name === 'catalog-notes') isOpen = false">
<zb:drawer.trigger name="catalog-notes" toggle><zb:button variant="white">Notes</zb:button></zb:drawer.trigger>
<span class="text-sm" x-text="isOpen ? 'Panel open' : 'Panel closed'"></span>
</div>
<zb:drawer name="catalog-notes" title="Notes">
<p class="text-sm">Notes taken during the customer call.</p>
</zb:drawer>
| Prop | Values |
|---|---|
zb:drawer:open · zb:drawer:close · zb:drawer:toggle | Events listened for ({ name }) |
ZubazarUI.drawer.open · close · toggle | The same commands from JavaScript (name) |
zb:drawer:opened · zb:drawer:closed | Emitted events ({ name }) |
Filters panel (docked)
docked is for the Filters panel of list pages: pinned to the left edge on desktop, a drawer on narrow screens. In this mode no header line is drawn and side, size, width, floating, backdrop and header are not used; compact tightens the footer.
<zb:filter-button drawer="catalog-filters" :count="1" />
<zb:drawer name="catalog-filters" docked title="Filters" compact>
<div class="space-y-4">
<zb:input name="f_code" placeholder="Custom Code" />
<zb:select name="f_status" :options="['' => 'All Statuses', '1' => 'Active', '0' => 'Inactive']" />
</div>
<zb:slot:footer>
<zb:button variant="outline" size="sm" class="flex-1">Clear</zb:button>
<zb:drawer.close><zb:button variant="outline-danger" size="sm" class="flex-1">Close</zb:button></zb:drawer.close>
</zb:slot:footer>
</zb:drawer>
| Prop | Values |
|---|---|
docked | true | false |
compact | true | false (footer spacing) |
Parts drawn by a Livewire component
Start the component's root element with zb:drawer.header or zb:drawer.body; the parts fill the panel, the header names it, and this works in a docked panel too. If the component draws its own header, don't give the panel a title, or two headers show.
<zb:drawer name="order-details">
<livewire:order-details />
</zb:drawer>
{{-- resources/views/livewire/order-details.blade.php --}}
<div>
<zb:drawer.header title="Order #4821" />
<zb:drawer.body>…</zb:drawer.body>
<zb:drawer.footer>…</zb:drawer.footer>
</div>
Developer notes
- The panel also opens with the
zb:drawer:openevent or, in JavaScript,ZubazarUI.drawer.open('name'). While it is open, the page behind it does not scroll. - On narrow screens the panel covers 85% of the screen.
wire:modelsends the close with the next request,wire:model.liveat once. When binding Alpine data withx-model, name the variable differently from the panel's state names (rendered,entered,opened,model).- An open menu or dropdown inside the panel uses the Esc key first; the panel closes with the next Esc.
- On desktop (1024px and up) a
dockedpanel pushes the content to the right in the ready-made layouts, focus stays on the page andtitleis only the accessible name. The pinned look comes from Zubazar UI Pro's panel CSS; the example'szb:filter-buttonis in Zubazar UI Pro too. zb:drawer.headermust be inside anzb:drawer: outside one the page fails with an error, and in a Livewire component clicking X orzb:drawer.closelogs an error to the console.- If a Livewire component draws only the body and the footer, write the header in the panel with
zb:drawer.header, before the component.
Events
| Event | detail | Description |
|---|---|---|
zb:drawer:opened | { name } | Sent from the drawer root when it opens; bubbles to window. |
zb:drawer:closed | { name } | Sent as soon as the drawer starts closing, before the slide-out ends. |
drawer-state-changed | { name, open } | Legacy name, sent at the same moments with open: true or open: false. |
zb:drawer:open · close · toggle (listens) | { name } | Dispatched on window, they open, close or toggle the drawer. close without a name closes every open drawer. The legacy names open-drawer, close-drawer and toggle-drawer also work. |
Accessibility
- ARIA and roles
- The drawer has
role="dialog"andaria-modal="true". Withzb:drawer.header, its title becomesaria-labelledbyand its descriptionaria-describedby. Without a header part the name isaria-label, thentitle, then "Menu". - Keyboard and focus
- Escape closes the drawer; Tab and Shift+Tab stay inside the panel. On open, focus moves to an element with
autofocus, else to the first focusable element in the panel; on close it returns to the opener. The page does not scroll while it is open (turn this off with:lock-scroll="false"). - Trigger
zb:drawer.triggeraddsaria-haspopup="dialog"and anaria-expandedthat follows the drawer to the button or link it wraps. The X button is named "Close".- Docked panel
- From lg up the panel sits beside the content:
aria-modalisfalse, Tab is not trapped, focus stays on the trigger, and Escape closes it wherever the focus is. On narrow screens it behaves like a normal drawer. - What you provide
- Give a drawer without a title an
aria-label, otherwise it is named "Menu". A docked panel is named the same way:aria-label, thentitle, then "Filters".