The native dialog scrolled too once its content outgrew the browser's default max-height. It now clips to the viewport and only the body scrolls. Co-Authored-By: Claude Opus 5.5 <[email protected]>
57 lines
2.6 KiB
PHP
57 lines
2.6 KiB
PHP
{{--
|
|
A large modal work area on the native <dialog> element (see
|
|
<x-confirm-dialog> for why not <x-modal />): focus moves in, Escape
|
|
closes it and closing returns focus to the opening button.
|
|
|
|
Slots: `header` (replaces the plain title bar, must contain an element
|
|
with id "<id>-title"), the default slot (scrolling body) and `footer`.
|
|
Open it with document.getElementById('<id>').showModal(), from Livewire
|
|
with $this->js(...). `locked` (an Alpine expression) keeps it open while
|
|
true, e.g. while a timer runs: Escape and the close button do nothing.
|
|
--}}
|
|
@props([
|
|
'id',
|
|
'title' => null,
|
|
'width' => 'max-w-5xl',
|
|
'locked' => 'false',
|
|
])
|
|
|
|
<dialog
|
|
id="{{ $id }}"
|
|
aria-labelledby="{{ $id }}-title"
|
|
wire:ignore.self
|
|
x-data="{ get isLocked() { return {{ $locked }}; } }"
|
|
x-on:cancel="if (isLocked) { $event.preventDefault(); }"
|
|
{{ $attributes->class(['m-auto max-h-[calc(100dvh-2rem)] w-[calc(100%-1rem)] overflow-hidden rounded-2xl border border-neutral-300 bg-white p-0 text-neutral-900 shadow-2xl backdrop:bg-black/70 dark:border-[#3e4249] dark:bg-[#222427] dark:text-neutral-100', $width]) }}
|
|
>
|
|
{{-- Only the body scrolls: the dialog itself never does (one scrollbar), and its border takes 2px. --}}
|
|
<div class="flex max-h-[calc(100dvh-2rem-2px)] flex-col">
|
|
@isset($header)
|
|
{{ $header }}
|
|
@else
|
|
<div class="flex shrink-0 items-center justify-between gap-3 border-b border-neutral-200 px-5 py-3 dark:border-[#36393f]">
|
|
<h2 id="{{ $id }}-title" class="text-base font-bold">{{ $title }}</h2>
|
|
<button
|
|
type="button"
|
|
x-on:click="if (! isLocked) { $el.closest('dialog').close(); }"
|
|
x-bind:disabled="isLocked"
|
|
aria-label="{{ __('layout.close') }}"
|
|
class="inline-flex size-8 items-center justify-center rounded-lg text-neutral-600 hover:bg-neutral-100 focus-visible:outline-2 focus-visible:outline-primary-600 disabled:opacity-40 dark:text-neutral-200 dark:hover:bg-white/10 dark:focus-visible:outline-primary-300"
|
|
>
|
|
<x-icon name="x-mark" class="size-5" aria-hidden="true" />
|
|
</button>
|
|
</div>
|
|
@endisset
|
|
|
|
<div class="min-h-0 flex-1 overflow-y-auto">
|
|
{{ $slot }}
|
|
</div>
|
|
|
|
@isset($footer)
|
|
<div class="flex shrink-0 flex-wrap items-center justify-between gap-2 border-t border-neutral-200 bg-neutral-100 px-5 py-3 dark:border-[#36393f] dark:bg-[#18191b]">
|
|
{{ $footer }}
|
|
</div>
|
|
@endisset
|
|
</div>
|
|
</dialog>
|