The row-action modal looks fine on the detail page. Drop the same component into a table row and the top half disappears behind the sticky header, or the whole thing gets cropped at the edge of a scrolling container. You bump the z-index to 9999. Nothing moves.
Livewire 4 ships @teleport for exactly this. It renders a chunk of your template somewhere else in the DOM — usually the end of body — while that markup stays part of the component that defined it.
Reproduce the clipped modal on purpose#
Before reaching for the directive, confirm which CSS rule is doing the damage. Build the smallest version of the bug: a table inside a container with overflow-hidden, and a fixed-position modal rendered inside one of the rows.
{{-- resources/views/livewire/invoices/table.blade.php --}}
<div class="overflow-hidden rounded-xl border"> {{-- the culprit --}}
<table class="w-full">
<tbody>
@foreach ($this->invoices as $invoice)
<tr>
<td>{{ $invoice->reference }}</td>
<td>
<button wire:click="edit({{ $invoice->id }})">Edit</button>
@if ($editing?->is($invoice))
{{-- fixed, inset-0, huge z-index, still clipped --}}
<div class="fixed inset-0 z-[9999] grid place-items-center bg-black/50">
<div class="rounded-xl bg-white p-6">Edit {{ $invoice->reference }}</div>
</div>
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
The backdrop is cropped to the rounded container. Delete overflow-hidden and it works. That one-line test tells you everything you need before you change any component code.
Identify the containing block, not the z-index#
Two separate CSS mechanisms produce the same symptom, and neither responds to z-index.
The first is clipping. overflow-hidden on an ancestor crops any descendant that paints outside its box — including absolutely positioned ones. Rounded cards, scroll containers and truncate wrappers all set it.
The second is the containing block. position: fixed normally resolves against the viewport, but a transform, filter, backdrop-filter, perspective, contain: paint or will-change on any ancestor makes that ancestor the containing block instead. A hover scale on a card is enough. Your "fixed" overlay is now fixed to a 300px card, and it also sits inside that card's stacking context, so a z-index of 9999 only ranks it against its siblings.
Walk up the tree in devtools and check computed styles for overflow and transform on every ancestor. Whichever one you find, the fix is the same: get the node out.
# quick sweep in the console for the real offenders
$$('*').filter(el => getComputedStyle(el).transform !== 'none').slice(0, 20)
Add a teleport target to your layout#
The selector you teleport to has to exist in the DOM when Alpine processes the directive, and it has to live outside the component. Add a dedicated root to the layout rather than teleporting straight to body — a named target is easier to style, easier to find in devtools, and gives toasts and modals separate homes.
{{-- resources/views/components/layouts/app.blade.php --}}
<body class="min-h-screen antialiased">
{{ $slot }}
<div id="modals"></div>
<div id="toasts" class="pointer-events-none fixed inset-x-0 bottom-0 z-50 flex flex-col items-center gap-2 p-4"></div>
@livewireScripts
</body>
Keep both divs above @livewireScripts and outside any wrapper that sets transform or overflow. A target nested inside a clipping ancestor recreates the original bug at a different address.
Wrap the modal in @teleport#
Now move the overlay. Wrap it in @teleport with the target selector, and leave the trigger where it is.
<td>
<button wire:click="edit({{ $invoice->id }})">Edit</button>
@if ($editing?->is($invoice))
@teleport('#modals')
<div class="fixed inset-0 z-50 grid place-items-center bg-black/50"
wire:key="invoice-modal-{{ $invoice->id }}">
<div class="w-full max-w-lg rounded-xl bg-white p-6" @click.outside="$wire.cancel()">
<h2 class="text-lg font-semibold">Edit {{ $invoice->reference }}</h2>
{{-- form goes here --}}
</div>
</div>
@endteleport
@endif
</td>
Two rules from the docs, both non-negotiable. The selector can be anything document.querySelector() accepts, but the target must be outside the component — teleporting to another element inside the same component does not work. And @teleport takes exactly one root element; two siblings at the top level will not render.
The z-index drops from 9999 to 50 because it finally means something. At body level the overlay competes with real page chrome, not with a table cell.
Keep the binding with wire:model and wire:click#
The node moves; the ownership does not. Teleported markup is still rendered by the component, so every Livewire directive behaves exactly as it did before — and this is the whole reason to use @teleport over Alpine's bare x-teleport, which gives you a node with no server binding at all.
@teleport('#modals')
<div class="fixed inset-0 z-50 grid place-items-center bg-black/50" wire:key="invoice-modal-{{ $invoice->id }}">
<form wire:submit="save" class="w-full max-w-lg rounded-xl bg-white p-6">
<input type="text" wire:model="form.reference" class="w-full rounded border p-2">
@error('form.reference') <p class="text-sm text-red-600">{{ $message }}</p> @enderror
<button type="submit" wire:loading.attr="disabled" wire:target="save">
<span wire:loading.remove wire:target="save">Save</span>
<span wire:loading wire:target="save">Saving…</span>
</button>
</form>
</div>
@endteleport
wire:loading with an explicit wire:target still resolves, because the loading machinery scopes to the component instance rather than to DOM position. If you are driving open and closed state from Alpine instead of a server property, the same rules apply as anywhere else — see sharing state between Livewire and Alpine with $wire and @entangle for when each side should own the flag.
Key teleported modals inside a loop#
One modal per table, teleported to one target, is unambiguous. The moment a @foreach can produce several teleported roots at the same address, Livewire's morph needs something stable to match them by.
@foreach ($this->invoices as $invoice)
<tr wire:key="invoice-row-{{ $invoice->id }}">
<td>
@teleport('#modals')
<div wire:key="invoice-modal-{{ $invoice->id }}" x-show="$wire.openInvoice === {{ $invoice->id }}">
{{-- ... --}}
</div>
@endteleport
</td>
</tr>
@endforeach
Prefix the keys so the modal key can never collide with the row key or with another component's keys on the same page. If you have ever watched a row keep the previous record's state after a delete, the cause is the same diffing behaviour described in wire:key and the row that kept the wrong data — teleporting does not exempt you from it.
The cleaner pattern for tables is one modal, not N: hold $editingId on the component and render a single teleported overlay outside the loop. Fewer nodes, one key, no collision surface.
Build a toast container on the same pattern#
Toasts have the same problem and a simpler shape — they are never bound to a trigger, so they teleport cleanly to their own target.
@teleport('#toasts')
<div class="pointer-events-auto flex flex-col gap-2">
@foreach ($this->toasts as $toast)
<div wire:key="toast-{{ $toast['id'] }}"
wire:transition.duration.200ms
class="rounded-lg bg-slate-900 px-4 py-2 text-white">
{{ $toast['message'] }}
</div>
@endforeach
</div>
@endteleport
Note the single root wrapping the loop — the loop itself cannot be the root. wire:transition works on teleported nodes like anywhere else, and the enter and leave animations are covered in animating Livewire updates with wire:transition and the View Transitions API.
Test the teleported markup with Pest#
Livewire's test helpers assert against the rendered component output, not against the browser DOM, so teleported content is still in scope. The directive moves nodes at runtime in the browser; it does not remove them from what the component rendered.
use App\Models\Invoice;
use App\Livewire\Invoices\Table;
use Livewire\Livewire;
it('renders the teleported modal for the selected invoice', function (): void {
$invoice = Invoice::factory()->create(['reference' => 'INV-2026-0042']);
Livewire::test(Table::class)
->call('edit', $invoice->id)
->assertSee('INV-2026-0042')
->assertSet('form.reference', 'INV-2026-0042');
});
it('saves from inside the teleported form', function (): void {
$invoice = Invoice::factory()->create();
Livewire::test(Table::class)
->call('edit', $invoice->id)
->set('form.reference', 'INV-2026-0099')
->call('save')
->assertHasNoErrors();
expect($invoice->fresh()->reference)->toBe('INV-2026-0099');
});
That covers the binding. Clipping is a visual bug, so it needs a browser assertion — a Pest browser test that opens the modal and checks the overlay's bounding box against the viewport. The component-level patterns are in testing Livewire 4 components with Pest.
Check these edge cases before you ship#
A few things bite in production that a local smoke test will not surface.
wire:navigate page swaps. Teleported nodes live outside the component's own subtree, so confirm they go away when you navigate rather than piling up in #modals. Open a modal, close it, navigate, and inspect the target element — it should be empty. If you are leaning on persisted layout chrome, the interaction with wire:navigate and prefetching is worth a deliberate test.
Multiple components, one target. Two components teleporting into #modals are fine, but give their roots distinct key prefixes. Two overlays with the same key in the same container is the one combination that reliably produces ghost markup.
Target missing on first paint. If the selector does not exist when the directive runs, nothing renders and nothing errors loudly. That happens when the target is defined in a partial that loads conditionally, or below @livewireScripts. Put it in the base layout and leave it there.
Dropdowns need a position, not just a parent. Teleporting a dropdown to body detaches it from the trigger it should sit under, and you are back to computing coordinates. For anchored UI, CSS anchor positioning is the better tool — see positioning popovers and tooltips with CSS anchor positioning.
The native <dialog> alternative. showModal() promotes the element to the browser's top layer, which sits above every stacking context by definition, and brings focus trapping and Escape handling for free. If what you need is a true modal rather than an arbitrarily placed overlay, <dialog> solves the layering problem without moving any nodes — teleporting is the answer for toasts, nested overlays and anything that is not modal.
Wrapping Up#
Check the ancestors for overflow-hidden and transform first, add one #modals div to the layout, wrap the overlay in @teleport with a single root and a prefixed wire:key. That is the whole fix, and it keeps the server binding you would lose by dropping to Alpine's x-teleport.
If you are restructuring modal state while you are in there, sharing state between Livewire and Alpine covers which side should own the open flag, and wire:key and the row that kept the wrong data covers the diffing rules that teleported nodes inherit.
FAQ#
Why is my Livewire modal clipped by its parent?
An ancestor is clipping it or capturing it. overflow-hidden crops any descendant that paints outside the box, and a transform, filter or will-change on an ancestor makes that element the containing block for position: fixed, so the overlay is positioned against the card rather than the viewport. Walk up the tree in devtools and check computed overflow and transform — the first ancestor that sets either is your culprit.
What does @teleport do in Livewire?
@teleport renders a portion of a component's template at a different location in the DOM, specified by any CSS selector document.querySelector() accepts. The markup is still owned and re-rendered by the component that declared it; only its position in the document changes. Under the hood it uses Alpine's x-teleport directive.
Does wire:model work inside a teleported element?
Yes. Teleporting moves the node, not the ownership, so wire:model, wire:click, wire:submit, wire:loading and $wire all behave exactly as they would in place. That is the practical difference between @teleport and using Alpine's x-teleport directly, which gives you a detached node with no Livewire binding.
Why doesn't z-index fix my modal?
Because z-index only orders elements within the same stacking context. If an ancestor created a stacking context — through a transform, filter, opacity below 1, or its own z-index — your element's value is compared against that ancestor's siblings, not against the page. A value of 9999 inside a card that sits below another card still paints below it. Moving the node out of that context is the fix.
Where should the teleport target go?
In your base layout, directly inside <body>, above @livewireScripts, and outside anything that sets overflow or transform. A dedicated <div id="modals"></div> is easier to debug than teleporting to body, and gives you a separate container for toasts. The target must exist when the directive runs and must live outside the component doing the teleporting.