Skip to content
TallCraftUI

Drawer

You can trigger the drawer to close from any PHP class by dispatching a close event $this->dispatch('close');.

Basic usage

Blade
@php
/*
public string $name;
public string $email;
public string $password;
 
public function createUser()
{
$this->validate([
'name' => ['required', 'string'],
'email' => ['required', 'email', 'unique:users,email'],
'password' => ['required', 'string', 'min:8'],
]);
 
User::create([
'name' => $this->pull('name'),
'email' => $this->pull('email'),
'password' => $this->pull('password'),
]);
 
// Close the drawer
$this->dispatch('close');
} */
@endphp
 
<x-button x-on:click="$wire.showDrawer = true" label="Form" />
 
<x-drawer wire:model="showDrawer" title="Create new user" blur>
<form wire:submit="createUser" class="space-y-4">
<x-input wire:model="name" label="Name *" />
<x-input wire:model="email" label="Email *" />
<x-input type="password" wire:model="password" label="Password *" />
 
<div class="flex justify-end w-full gap-5">
<x-button label="Submit" spinner="createUser" class="w-full py-2.5"/>
</div>
</form>
</x-drawer>

Open with Livewire

It will send network request.
Blade
<x-button wire:click="$set('openWithLivewire', true)" label="Livewire" />
 
<x-drawer wire:model="openWithLivewire" title="Open with Livewire">
Drawer content..
</x-drawer>

Open with Alpine Js

It will not send any network request.
Blade
<x-button x-on:click="$wire.openWithAlpine = true" label="Alpine" />
 
<x-drawer wire:model="openWithAlpine" title="Open with Alpine Js">
Drawer content..
</x-drawer>

Position

Blade
<x-button x-on:click="$wire.openLeft = true" label="Left" />
<x-button x-on:click="$wire.openRight = true" label="Right" /> {{-- default --}}
<x-button x-on:click="$wire.openTop = true" label="Top" />
<x-button x-on:click="$wire.openBottom = true" label="Bottom" />
 
<x-drawer wire:model="openTop" title="Position top" top>
Drawer content..
</x-drawer>
 
<x-drawer wire:model="openBottom" title="Position bottom" bottom>
Drawer content..
</x-drawer>
 
<x-drawer wire:model="openLeft" title="Position left" left>
Drawer content..
</x-drawer>
 
{{-- default --}}
<x-drawer wire:model="openRight" title="Position right" right>
Drawer content..
</x-drawer>

Persistent

Blade
<x-button x-on:click="$wire.openPersistent = true" label="Persistent" />
 
<x-drawer wire:model="openPersistent" title="Persistent" persistent>
Drawer content..
</x-drawer>

Background blur

Blade
<x-button x-on:click="$wire.openBlur = true" label="Blur" />
 
<x-drawer wire:model="openBlur" title="Background blur-sm" blur>
Drawer content..
</x-drawer>

Size variants

Blade
<x-drawer sm>
<x-drawer md>
<x-drawer lg>
<x-drawer xl>
<x-drawer 2xl>
<x-drawer 3xl>
<x-drawer 4xl>
<x-drawer 5xl>
<x-drawer 6xl>
<x-drawer 7xl>
<x-drawer full>

Disable focus trap

The focus trap is enabled by default, but you can disable it by including the without-trap-focus attribute.
Blade
<x-drawer without-trap-focus />

Default settings

Change drawer default settings according your needs config/tallcraftui.php

PHP
return [
'drawer' => [
'width' => 'lg', // Allowed: sm, md, lg, xl, 2xl, 3xl, 4xl, 5xl, 6xl, 7xl, full
'blur' => false,
'trap-focus' => true,
],
];

API reference

Props are read from the component classes in TallCraftUI 3.0.0-beta.1. Write them in kebab-case and pass booleans as bare attributes, for example <x-button outline />. Other attributes, such as class or wire:model, are passed to the component's element.

<x-drawer>

View source
Prop Type Default
title string null
id string null
left bool false
right bool false
top bool false
bottom bool false
no-separator bool false
persistent bool false
without-dismissible bool false
without-trap-focus bool false
Config
drawer.width = lg drawer.blur = false drawer.trap-focus = true Change defaults