Skip to content

Modal

Terminal window
pnpm add @agencecinq/modal
import "@agencecinq/modal";
<cinq-modal-button class="block">
<button aria-controls="demo-modal" aria-pressed="false">Open modal</button>
</cinq-modal-button>
<cinq-modal id="demo-modal">
<dialog
class="fixed left-1/2 top-1/2 w-[min(92vw,32rem)] -translate-x-1/2 -translate-y-1/2 rounded-xl bg-white p-6 shadow-2xl backdrop:bg-black/50 text-gray-900"
>
<h2 class="text-xl font-semibold mb-2">Monster entry</h2>
<p class="text-gray-800 mb-4">
This is a native <code>&lt;dialog&gt;</code> modal.
</p>
<p class="text-gray-800 mb-4">
The dracolich is an undead dragon created by forbidden rites; opening this
modal feels like leafing through the AD&amp;D Monster Manual.
</p>
<cinq-modal-button class="block">
<button aria-controls="demo-modal" aria-pressed="false">Close</button>
</cinq-modal-button>
</dialog>
</cinq-modal>
  • <cinq-modal> must contain a <dialog> (or an element marked with [data-dialog]).
  • id is required for event-driven open/close (it must match the aria-controls of your buttons).

Copy‑paste starter markup:

<cinq-modal-button class="block">
<button
type="button"
aria-controls="example-modal"
aria-pressed="false"
>
Open modal
</button>
</cinq-modal-button>
<cinq-modal id="example-modal">
<dialog
class="fixed left-1/2 top-1/2 w-[min(92vw,32rem)] -translate-x-1/2 -translate-y-1/2 rounded-xl bg-white p-6 shadow-2xl backdrop:bg-black/50 text-gray-900"
>
<h2 class="text-xl font-semibold mb-2">Dracolich lore</h2>
<p class="text-gray-800 mb-4">
The dracolich is an undead dragon created by forbidden rites; opening this
modal feels like leafing through the AD&amp;D Monster Manual.
</p>
<cinq-modal-button class="block">
<button
type="button"
aria-controls="example-modal"
aria-pressed="false"
class="px-4 py-2 rounded-lg bg-black text-white hover:bg-gray-800"
>
Close
</button>
</cinq-modal-button>
</dialog>
</cinq-modal>
MethodDescription
show()Opens the native dialog (calls showModal()).
close()Closes the dialog.
EventDispatched byDetail payloadDescription
modal-togglecinq-modal-button{ modal, trigger, trap }Emitted on document.documentElement to request a toggle.
modal-opencinq-modal{ modal }Fired after the modal has been opened.
modal-closecinq-modalFired after the modal has been closed.

Dracolich lore

The dracolich retains the spellcasting and breath weapon of its original form, but its eyes burn with cold, undead hatred.

Confirm dialog

A simple confirm/cancel flow using multiple <cinq-modal-button> tied to the same modal.

Waiting for your choice…

Spend a spell slot?

Casting fireball will consume a 3rd-level spell slot for your wizard this encounter.

Inline form

A small form inside the modal — the dialog closes on submit and shows the result outside.

No character saved yet.

Character sheet

Enter a name and class for your adventurer.