v0.0.2
Demos (demo panel, opens in a new tab)

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

Basic usage: view
BLADE

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.

blade
<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>
PropValues
nameUnique name
titleHeader line (with the X button)
footerSlot: footer

Side and width

Side and width: view
BLADE

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.

blade
<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>
PropValues
sideright | left
sizesm | md
widthmax-w-* class (replaces size)

Form panel

Form panel: view
BLADE

With :closable-on-backdrop="false", a backdrop click does not close the panel, so a half-filled form is not lost.

blade
<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>
PropValues
closable-on-backdroptrue | false
autofocusField to focus on open

Binding with Livewire

Binding with Livewire: view
BLADE

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.

blade
<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>
PropValues
wire:model · wire:model.liveLivewire property (bool)
x-modelAlpine data (bool)

Composable parts

Composable parts: view
BLADE

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.

blade
<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>
PropValues
zb:drawer.triggername, toggle
zb:drawer.headertitle, description
zb:drawer.body · footerBody and footer
zb:drawer.closeThe element inside closes the panel

Props

The values the component takes. What are props and slots?

PropTypeDefaultDescription
name— — Required. The name used in the events and the ZubazarUI.drawer.open('…') call
title—nullHeader line (with X) and accessible name
side—rightright · left
size—mdmd (max-w-md) · sm (max-w-xs)
width—nullmax-w-* class; when given, size is not used
floatingbooleanfalsePanel inset from the edges, with rounded corners
backdropbooleantrueDims the background
lock-scrollbooleantrueKeeps the page from scrolling while open
closable-on-backdropbooleantrueCloses on a backdrop click
wire:model · x-model— — Binds the open/closed state to a Livewire property or Alpine data
compactbooleanfalseTight spacing in the footer
dockedbooleanfalseFilters panel behavior of list pages (in the Zubazar UI Pro panel layouts)
aria-label—nullAccessible name when there is no title; when empty, "Menu" (in the app language)
body-class—flex-1 p-5 overflow-y-autoClasses 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—nullHeader 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

7 examples

Floating panel

Floating panel: view
BLADE

floating shows the panel inset from the edges, like a card with rounded corners; it suits short content.

blade
<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>
PropValues
floatingtrue | false

Custom header

Custom header: view
BLADE

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.

blade
<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>
PropValues
headerSlot: replaces the header line
aria-labelAccessible name when there is no title

Without a backdrop

Without a backdrop: view
BLADE

: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.

blade
<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>
PropValues
backdroptrue | false
lock-scrolltrue | false

Livewire component

PHP

The component of the "Binding with Livewire" example. Setting the property to true is enough to open the panel.

php
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

Events: view
BLADE

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.

blade
<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>
PropValues
zb:drawer:open · zb:drawer:close · zb:drawer:toggleEvents listened for ({ name })
ZubazarUI.drawer.open · close · toggleThe same commands from JavaScript (name)
zb:drawer:opened · zb:drawer:closedEmitted events ({ name })

Filters panel (docked)

Filters panel (docked): view
BLADE

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.

blade
<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>
PropValues
dockedtrue | false
compacttrue | false (footer spacing)

Parts drawn by a Livewire component

BLADE

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.

blade
<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

Events, hooks and details
  • The panel also opens with the zb:drawer:open event 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:model sends the close with the next request, wire:model.live at once. When binding Alpine data with x-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 docked panel pushes the content to the right in the ready-made layouts, focus stays on the page and title is only the accessible name. The pinned look comes from Zubazar UI Pro's panel CSS; the example's zb:filter-button is in Zubazar UI Pro too.
  • zb:drawer.header must be inside an zb:drawer: outside one the page fails with an error, and in a Livewire component clicking X or zb:drawer.close logs 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

EventdetailDescription
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" and aria-modal="true". With zb:drawer.header, its title becomes aria-labelledby and its description aria-describedby. Without a header part the name is aria-label, then title, 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.trigger adds aria-haspopup="dialog" and an aria-expanded that 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-modal is false, 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, then title, then "Filters".
Zubazar UI · ZubazarDesigned for people.