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

Modal

A window for short forms and details that opens on top of the page and dims what is behind it.

zb:modal zubazar/ui · free (MIT)

Basic usage

Basic usage: view
BLADE

Give the modal a unique name and open it with zb:modal.trigger; X, Esc and a backdrop click close it.

blade
<zb:modal.trigger name="catalog-customer"><zb:button>Open the customer summary</zb:button></zb:modal.trigger>

<zb:modal name="catalog-customer" title="Customer summary">
    <dl class="space-y-3 text-sm">
        <div class="flex justify-between"><dt class="text-muted">Customer</dt><dd>Ayşe Yılmaz</dd></div>
        <div class="flex justify-between"><dt class="text-muted">Membership</dt><dd>Premium</dd></div>
        <div class="flex justify-between"><dt class="text-muted">Last order</dt><dd>September 12, 2026</dd></div>
    </dl>
</zb:modal>
PropValues
nameUnique name; events carry this name
titleHeader line (with the X button)

Widths

Widths: view
BLADE

Pick the maximum width with max-width: sm for a short message, xl or 2xl for a two-column form or a table, 3xl–5xl or full for a long text (terms, a contract), where only the body scrolls and the header and the footer stay in place.

blade
<div class="flex flex-wrap gap-2" x-data>
    <zb:modal.trigger name="catalog-width-sm"><zb:button variant="white">sm</zb:button></zb:modal.trigger>
    <zb:modal.trigger name="catalog-width-lg"><zb:button variant="white">lg</zb:button></zb:modal.trigger>
    <zb:modal.trigger name="catalog-width-2xl"><zb:button variant="white">2xl</zb:button></zb:modal.trigger>
</div>

<zb:modal name="catalog-width-sm" title="Narrow window" max-width="sm"><p class="text-sm">For a short confirmation or message.</p></zb:modal>
<zb:modal name="catalog-width-lg" title="Wide window" max-width="lg"><p class="text-sm">For single-column forms.</p></zb:modal>
<zb:modal name="catalog-width-2xl" title="Widest window" max-width="2xl"><p class="text-sm">For two-column forms and small tables.</p></zb:modal>
PropValues
max-widthsm | md | lg | xl | 2xl | 3xl | 4xl | 5xl | full

With Livewire

PHP

Send the zb:modal:open and zb:modal:close events from the server; close-action calls a Livewire method when the user closes the window.

php
// <zb:modal name="product-form" title="Product" close-action="resetForm"> … </zb:modal>

public function edit(int $productId): void
{
    $this->product = Product::findOrFail($productId);
    $this->dispatch('zb:modal:open', name: 'product-form');
}

public function save(): void
{
    $this->product->save();
    $this->dispatch('zb:modal:close', name: 'product-form');
}

public function resetForm(): void
{
    $this->reset('product');
}
PropValues
close-actionLivewire method called when the user closes the window

Composable parts

Composable parts: view
BLADE

Build the window from the zb:modal.header, zb:modal.body and zb:modal.footer parts; a button inside zb:modal.close closes it.

blade
<zb:modal.trigger name="add-task">
    <zb:button>New task</zb:button>
</zb:modal.trigger>

<zb:modal name="add-task" max-width="lg">
    <zb:modal.header title="New task" description="Choose the branch and the assignee." />

    <zb:modal.body class="space-y-4">
        <zb:input name="task_name" label="Task name" placeholder="Kadıköy – stock count" />
        <zb:select name="branch" label="Branch" :options="['kadikoy' => 'Kadıköy', 'uskudar' => 'Üsküdar', 'atasehir' => 'Ataşehir']" placeholder="Choose a branch" />
        <zb:select name="assignee" label="Assignee" :options="['ahmet' => 'Ahmet Yılmaz', 'elif' => 'Elif Kaya']" placeholder="Choose a team member" />
    </zb:modal.body>

    <zb:modal.footer>
        <zb:modal.close>
            <zb:button variant="white">Cancel</zb:button>
        </zb:modal.close>
        <zb:modal.close>
            <zb:button x-on:click="$dispatch('toast', { type: 'success', message: 'Task saved.' })">Save</zb:button>
        </zb:modal.close>
    </zb:modal.footer>
</zb:modal>
PropValues
zb:modal.triggername (the modal to open)
zb:modal.headertitle, description; slot: header content
zb:modal.body · footerBody and footer
zb:modal.closeThe element inside closes the modal

Props

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

PropTypeDefaultDescription
name— — Required. The name used in the events and the ZubazarUI.modal.open('…') / close('…') calls; closing without a name closes all modals
title—nullHeader line and X button; not rendered when empty
max-width—mdsm · md · lg · xl · 2xl · 3xl · 4xl · 5xl · full; another value is an error
aria-label—nullAccessible name when there is no title; when empty, "Dialog" (in the app language)
closable-on-backdropbooleantrueCloses on a backdrop click
close-action—nullLivewire method called when the user closes the window
request-close-event—nullX / Esc / backdrop emit this event instead of closing
alertbooleanfalseA question that needs an answer: role="alertdialog" (confirmation-dialog uses it)
wire:model / x-model— — Binds the open state both ways: it opens when the property is true and sets it to false when the user closes it (confirmation-dialog takes it too)
modal.trigger: name— — Required; opens the modal with this name on click (confirmation-dialog included)
modal.header: title · description—nullTitle, description and X; when title is not given, the slot is the title itself
modal.body · modal.footer— — Scrolling body and right-aligned footer
modal.close— — Clicking the element inside closes the modal

Slots: default: the window body (scrolls), the parts (zb:modal.header, zb:modal.body, zb:modal.footer) or a Livewire component that draws the parts · footer: right-aligned footer · zb:modal.trigger and zb:modal.close open and close it.

Advanced

5 examples

Window without a title

Window without a title: view
BLADE

Without title, no header line or X is drawn and the content uses the whole window. Give an aria-label to name the window (when empty, "Dialog" is read, in the app language).

blade
<zb:modal.trigger name="catalog-done"><zb:button variant="white">Finish the import</zb:button></zb:modal.trigger>

<zb:modal name="catalog-done" max-width="sm" aria-label="Import complete">
    <div class="flex flex-col items-center gap-3 py-4 text-center">
        <zb:icon name="check-circle" size="12" stroke="1.4" class="text-success-line" />
        <p class="text-base font-semibold text-ink">Import complete</p>
        <p class="text-sm text-muted">148 products were added to the Electronics category.</p>
        <zb:modal.close><zb:button class="mt-2">Done</zb:button></zb:modal.close>
    </div>
</zb:modal>
PropValues
aria-labelAccessible name of the window when there is no title

Do not close on outside click

Do not close on outside click: view
BLADE

So a long form is not lost, turn off backdrop clicks with :closable-on-backdrop="false"; X and Esc still work. Pass the value with a colon, otherwise "false" arrives as text and the feature stays on.

blade
<zb:modal.trigger name="catalog-sticky"><zb:button variant="white">Open the ticket form</zb:button></zb:modal.trigger>

<zb:modal name="catalog-sticky" title="Support ticket" :closable-on-backdrop="false">
    <zb:textarea name="ticket_note" label="Ticket note" rows="4" />
    <zb:slot:footer>
        <zb:modal.close><zb:button variant="white">Close</zb:button></zb:modal.close>
    </zb:slot:footer>
</zb:modal>
PropValues
closable-on-backdroptrue | false

Asking before closing

Asking before closing: view
BLADE

With request-close-event, X, Esc and the backdrop do not close the window but emit an event with this name; the listening code decides and closes it with close() or ZubazarUI.modal.close('catalog-note'). close() in the footer skips this check.

blade
<zb:modal.trigger name="catalog-note"><zb:button variant="white">Add a note</zb:button></zb:modal.trigger>

<zb:modal
    name="catalog-note"
    title="Add a note"
    request-close-event="catalog-note-close-requested"
    x-on:catalog-note-close-requested.window="if (confirm('The note you wrote will not be saved. Close anyway?')) close()"
>
    <zb:textarea name="customer_note" label="Note" rows="3" />
</zb:modal>
PropValues
request-close-eventName of the event emitted on a close request

Parts drawn by a Livewire component

BLADE

Start the component's root element with zb:modal.header or zb:modal.body; the parts fill the window and the header names it. If the component draws its own header, don't give the modal a title, or two headers show.

blade
<zb:modal name="customer-form">
    <livewire:customer-form />
</zb:modal>

{{-- resources/views/livewire/customer-form.blade.php --}}
<div>
    <zb:modal.header title="New customer" />
    <zb:modal.body>…</zb:modal.body>
    <zb:modal.footer>…</zb:modal.footer>
</div>

Close button in a classic modal

Close button in a classic modal: view
BLADE

zb:modal.close also works in the classic usage with title and the footer slot.

blade
<zb:modal.trigger name="delivery-note">
    <zb:button variant="white">Delivery note</zb:button>
</zb:modal.trigger>

<zb:modal name="delivery-note" title="Delivery note">
    <p class="text-sm text-dim">If the customer is not at the address, leave the package with the building attendant and take a photo.</p>
    <zb:slot:footer>
        <zb:modal.close><zb:button variant="white">Close</zb:button></zb:modal.close>
    </zb:slot:footer>
</zb:modal>

Developer notes

Events, hooks and details
  • Only one modal stays open at a time.
  • A modal also opens with the zb:modal:open event or, in JavaScript, ZubazarUI.modal.open('name'); inside the slots, close() closes it.
  • On narrow screens the window is always full width.
  • An zb:modal:close sent from the server does not call the close-action method again. The old event names open-modal, close-modal and modal-closed still work.
  • With the parts, the content must start with a part; to wrap the body and footer in a form, put the form after the header.
  • zb:modal.header must be inside an zb:modal: outside one the page fails with an error, and in a Livewire component clicking X or zb:modal.close logs an error to the console.
  • If a Livewire component draws only the body and the footer, write the header in the modal with zb:modal.header, before the component.

Events

EventdetailDescription
zb:modal:opened{ name }Sent from the modal root when it opens; bubbles to window.
zb:modal:closed{ name }Sent from the modal root on every close (X, Escape, backdrop, close(), a server zb:modal:close). The legacy name modal-closed is sent at the same time.
zb:modal:open (listens){ name }Dispatched on window, it opens the modal with that name. The legacy name open-modal also works.
zb:modal:close (listens){ name }Closes the modal with that name, or every open modal when no name is given. The legacy name close-modal also works.

Accessibility

ARIA and roles
The panel has role="dialog" and aria-modal="true"; a confirmation (zb:confirmation-dialog) uses role="alertdialog". The title (title or zb:modal.header) names the dialog through aria-labelledby, and the header description describes it through aria-describedby. Without a title the name comes from aria-label, or falls back to "Dialog".
Keyboard
Escape closes the modal, or sends the request-close-event instead when one is set. Tab and Shift+Tab cycle inside the modal. An open menu or list inside takes the first Escape; the modal closes on the next one.
Focus
On open, focus moves to an element with autofocus, else to the first focusable element (usually the X in the title row), else to the panel itself. On close it returns to the element that opened the modal. The page does not scroll while the modal is open.
Buttons
The X button is named "Close". zb:modal.trigger adds aria-haspopup="dialog" to the button or link it wraps. The backdrop has aria-hidden.
What you provide
Give a modal without a title an aria-label, or screen readers only hear "Dialog". In a classic body with title, text with the id {name}-description also describes the dialog. The rest of the page does not get inert; aria-modal and the Tab loop keep it apart.
Zubazar UI · ZubazarDesigned for people.