InstallComponentsExample

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

Edit account

"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

NameTypeDescription
data-open="id"attrPut on any element to open that dialog.
data-closeattrInside a dialog: closes it.
data-side="right"attrFull-height side panel.
> header, > footertagHeader row and tinted action bar.
form method="dialog"nativeSubmitting closes the dialog.