Skip to content
Bladewell
Components
Accordion
Alert
Breadcrumbs
Button
Calendar
Chat
Clock
Command palette
Dropdown
Captcha
Checkbox
Colour picker
Date picker
Date range picker
File upload
Filter builder
Image cropper
Number
OTP
Password
Phone
Radio
Repeater
Search
Select
Show if
Slider
Sortable list
Switch
Tags input
Text input
Textarea
Time picker
Verification code
Field
Icon
Kanban
Auth layout
Sidebar layout
Modal
Pagination
Popover
Price roll
Progress
Stepper
Table
Tabs
Toast
Tooltip
Tooltip cursor
Tree
Docs
Installation
Why Bladewell
For AI agents
Guides
Build a Laravel form from your validation rules
Add a date range picker to a Laravel form
Laravel data table with sorting, filters, pagination
Editable table cells in Laravel with Livewire
A Livewire modal that stays open through re-renders
Using Blade components in Livewire 3 and 4
Two-factor authentication screens for Laravel Fortify
Passkey sign-in for Laravel with Fortify
Real-time notification bell with Laravel Reverb
AI agent actions with Approve and Deny in Laravel
Laravel AI chat with Livewire and streaming replies
Livewire multi-step form with validation per step
Toast notifications in Laravel and Livewire
Livewire file upload with progress and drag and drop
Laravel searchable select that loads from the database
Laravel Blade card, avatar and empty state patterns
Add charts and a rich text editor to a Laravel app
Compare
Bladewell vs Flux: a Free Alternative for Laravel
Bladewell vs Mary UI: daisyUI or Plain Blade
Bladewell vs WireUI: With or Without Alpine
Blade UI Kit Alternative for Laravel 12 and 13
Bladewell vs BladewindUI: Laravel Blade Components
Bladewell vs Sheaf UI: With or Without Alpine
Bladewell vs April UI: Package or Copied-in Code

Guides

A Livewire modal that stays open through re-renders

A Blade modal for Livewire 3 and 4: open and close it from the component, keep it open on validation errors, reset its form on close. No Alpine.

php artisan bladewell:add modal text-input button

Uses Modal, Text input and Button. New to Bladewell? Install it first.

Why modals close on their own

Livewire re-renders a component by comparing the new HTML with the page and patching the difference. A modal whose open state lives only in the browser, as a class or an attribute set by a script, can be patched back to closed. It happens on the very render that should show "The email has already been taken." The visitor sees the modal vanish and never sees the error.

Bladewell's modal is a native <dialog> that keeps its own state through every Livewire 3 and 4 render, checked in a real browser. It needs no Alpine, and nothing from Livewire, so the same tag works on a plain Blade page.

A form in a modal

Any element with data-modal-open opens it, and data-modal-close closes it, no wire:click or server round trip. The Save button sits in the footer, outside the form, so it names the form with form="profile-form".

resources/views/livewire/edit-profile.blade.php
<div>
    <x-widget.button data-modal-open="edit-profile">Edit profile</x-widget.button>

    <x-widget.modal id="edit-profile" title="Edit profile">
        <form id="profile-form" wire:submit="save" class="grid gap-4">
            <x-widget.text-input label="Name" wire:model="name" required />
            <x-widget.text-input label="Email" type="email" wire:model="email" required />
        </form>

        <x-slot:footer>
            <x-widget.button variant="neutral" data-modal-close>Cancel</x-widget.button>
            <x-widget.button type="submit" form="profile-form">Save</x-widget.button>
        </x-slot:footer>
    </x-widget.modal>
</div>

The component validates as usual. A failed save re-renders with the errors under their fields and the modal still open. A good one closes it from the server.

app/Livewire/EditProfile.php
namespace App\Livewire;

use Illuminate\Validation\Rule;
use Livewire\Component;

class EditProfile extends Component
{
    public string $name = '';

    public string $email = '';

    public function mount(): void
    {
        $this->fill(auth()->user()->only('name', 'email'));
    }

    public function save(): void
    {
        $validated = $this->validate([
            'name' => ['required', 'string', 'max:120'],
            'email' => ['required', 'string', 'email', 'max:255', Rule::unique('users')->ignore(auth()->id())],
        ]);

        $user = auth()->user();
        $user->fill($validated);
        // A new address isn't verified yet: with MustVerifyEmail, it has to be confirmed again.
        if ($user->isDirty('email')) {
            $user->email_verified_at = null;
        }
        $user->save();

        // Closes it from the server, once the save went through.
        $this->dispatch('modal-close', id: 'edit-profile');
    }

    public function render()
    {
        return view('livewire.edit-profile');
    }
}

Open and close it from PHP

Dispatch modal-open or modal-close with the modal's id, from any action. Use it to open a modal once a record has loaded, or to close one after a save.

In a Livewire action
// Anywhere in the component: open it, or close it.
$this->dispatch('modal-open', id: 'edit-profile');
$this->dispatch('modal-close', id: 'edit-profile');

Start empty every time

A "New project" modal shouldn't reopen with the last project's name in it. reset-on-close puts its forms back to how the page last drew them when it closes, and tells wire:model, so the properties follow. Before anything is saved, that's empty. After a render, such as a Create that failed validation, it's what that render drew, so also reset the property in PHP once a save has gone through: $this->reset('projectName').

resources/views/livewire/projects.blade.php
<x-widget.modal id="new-project" title="New project" reset-on-close>
    <form id="project-form" wire:submit="create" class="grid gap-4">
        <x-widget.text-input label="Name" wire:model="projectName" required />
    </form>

    <x-slot:footer>
        <x-widget.button variant="neutral" data-modal-close>Cancel</x-widget.button>
        <x-widget.button type="submit" form="project-form">Create</x-widget.button>
    </x-slot:footer>
</x-widget.modal>

A modal only your code can close

While something runs that mustn't be interrupted, disable-close removes the X, Esc and the backdrop click. Dispatching modal-close from the component still closes it, because the app asked.

resources/views/livewire/import.blade.php
<x-widget.modal id="importing" title="Importing your contacts" disable-close>
    <p>This takes a minute. Keep the page open.</p>
</x-widget.modal>

"Are you sure?"

Give the button a confirm question. It asks in a dialog styled like your modals, starting on Cancel so Enter can't confirm by accident, and runs wire:click, or submits the form, only once confirmed. No script needed.

resources/views/livewire/project.blade.php
<x-widget.button variant="danger" wire:click="delete" confirm="Delete this project?" confirm-message="Its files go too.">Delete</x-widget.button>

Livewire's own wire:confirm still works, with the browser's plain dialog. To ask from a script instead, call modal.confirm(): it resolves true or false. See the confirm example.

Without Livewire

On a plain Blade page the form posts as normal. Validate it into a named error bag with $request->validateWithBag('updateProfile', …), then pass :open="$errors->updateProfile->any()" and bag="updateProfile" on its fields. The modal opens again after a failed submit with the errors and old input in place, and only for its own form: a failed search or newsletter form elsewhere on the page leaves it closed. Old input isn't kept per form, though: if that other form also has an email field, what was typed there fills this one too, so give the fields different names.

resources/views/profile/edit.blade.php
{{-- Opens again after a failed submit, with the errors in place. The controller validates into its own bag,
     $request->validateWithBag('updateProfile', [...]), so a failed form elsewhere on the page doesn't open it. --}}
<x-widget.modal id="edit-profile" title="Edit profile" :open="$errors->updateProfile->any()">
    <form id="profile-form" method="POST" action="{{ route('profile.update') }}" class="grid gap-4">
        @csrf
        @method('PATCH')
        <x-widget.text-input name="name" label="Name" :value="$user->name" bag="updateProfile" required />
        <x-widget.text-input name="email" type="email" label="Email" :value="$user->email" bag="updateProfile" required />
    </form>

    <x-slot:footer>
        <x-widget.button variant="neutral" data-modal-close>Cancel</x-widget.button>
        <x-widget.button type="submit" form="profile-form">Save</x-widget.button>
    </x-slot:footer>
</x-widget.modal>

Drawers, full-screen dialogs and bottom sheets on phones are the same component. See the modal's page.