Dialog
A modal built on native <dialog>. Open it with data-open="id".
How it helpsThe browser handles focus trapping, Escape and the top layer. Sidedish adds the styling, opening by attribute and closing on backdrop click.
Modal form
"use client";
import { toast } from "sidedish";
export default function Example() {
return (
<>
<button data-open="demo-dialog">Open dialog</button>
<dialog id="demo-dialog" aria-labelledby="dlg-title">
<header>
<h2 id="dlg-title">Edit account</h2>
<button data-variant="quiet" data-size="icon" data-close aria-label="Close">✕</button>
</header>
<form method="dialog" className="flex flex-col gap-3">
<label>Account name <input defaultValue="HDFC Savings" /></label>
<label>Nickname <input placeholder="Optional" /></label>
</form>
<footer>
<button data-variant="ghost" data-close>Cancel</button>
<button data-close onClick={() => toast('Account saved', {tone:'good'})}>Save</button>
</footer>
</dialog>
</>
);
}<button data-open="demo-dialog">Open dialog</button>
<dialog id="demo-dialog" aria-labelledby="dlg-title">
<header>
<h2 id="dlg-title">Edit account</h2>
<button data-variant="quiet" data-size="icon" data-close aria-label="Close">✕</button>
</header>
<form method="dialog" class="flex flex-col gap-3">
<label>Account name <input value="HDFC Savings"></label>
<label>Nickname <input placeholder="Optional"></label>
</form>
<footer>
<button data-variant="ghost" data-close>Cancel</button>
<button data-close onclick="Sidedish.toast('Account saved', {tone:'good'})">Save</button>
</footer>
</dialog>In Next.js
// data-open / data-close work in Server Components, with no "use client" needed.
// To open from code, use the native API with a ref:
"use client";
import { useRef } from "react";
export function EditAccount() {
const ref = useRef<HTMLDialogElement>(null);
return (
<>
<button onClick={() => ref.current?.showModal()}>Open</button>
<dialog ref={ref}>…</dialog>
</>
);
}API
| Name | Type | Description |
|---|---|---|
data-open="id" | attr | Put on any element to open that dialog. |
data-close | attr | Inside a dialog: closes it. |
data-side="right" | attr | Full-height side panel. |
> header, > footer | tag | Header row and tinted action bar. |
form method="dialog" | native | Submitting closes the dialog. |