Teleport renders content outside the component DOM.
Modal Component
<button wire:click="$set('show', true)">Open</button>
@teleport('body')
@if($show)
<div class="modal-backdrop fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center">
<div class="modal bg-white p-6 rounded-lg shadow-xl">
<h2 class="text-xl font-bold mb-4">Modal Title</h2>
<p>Modal content goes here...</p>
<button wire:click="$set('show', false)" class="mt-4 px-4 py-2 bg-gray-200 rounded">Close</button>
</div>
</div>
@endif
@endteleportComponent Class
class ModalDialog extends Component
{
public bool $show = false;
public function openModal(): void
{
$this->show = true;
}
public function closeModal(): void
{
$this->show = false;
}
}