agentleFS
param087param087/saas-ui-skills/skills/modals-and-dialogs/SKILL.md

modals-and-dialogs

Skill3 starsChanged 6 months agoMITView on GitHub

Use when building modals, sheets, drawers, or confirmation flows — choosing Dialog vs Sheet vs Drawer vs AlertDialog, focus trapping, destructive-action confirms, and forms inside overlays without losing data.

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Always include DialogTitle (+ DialogDescription) — they back aria-labelledby/describedby.

    line 76
  2. Distinctive:

    Don't stack modals. Replace content or use a multi-step flow instead.

    line 78

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Modals & Dialogs

Overview

Overlays interrupt — use them sparingly and correctly. shadcn/ui (on Radix) gives you four primitives with built-in focus trap, Esc to close, scroll lock, and aria-modal. Your job is choosing the right one and handling the edge cases: destructive confirms, forms with unsaved input, and not stacking overlays.

When to use

  • A focused task or confirmation needs to block the page.
  • Building a side panel for details/filters/quick-edit.
  • A <div> overlay is being hand-rolled (you'll miss focus trap + keyboard).

Pick the right primitive

UsePrimitiveWhen
Centered modalDialogShort forms, focused tasks
Side panelSheetDetails, filters, edit alongside context
Bottom drawerDrawer (vaul)Mobile-friendly, touch dismiss
Confirm/destructAlertDialogYes/no decisions; no dismiss-on-outside-click

Destructive confirmation

AlertDialog (not Dialog) for irreversible actions — it requires an explicit choice and won't close on outside click or Esc accidentally losing the decision:

<AlertDialog>
  <AlertDialogTrigger asChild>
    <Button variant="destructive">Delete project</Button>
  </AlertDialogTrigger>
  <AlertDialogContent>
    <AlertDialogHeader>
      <AlertDialogTitle>Delete this project?</AlertDialogTitle>
      <AlertDialogDescription>
        This permanently deletes the project and all its data. This can’t be undone.
      </AlertDialogDescription>
    </AlertDialogHeader>
    <AlertDialogFooter>
      <AlertDialogCancel>Cancel</AlertDialogCancel>
      <AlertDialogAction
        className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
        onClick={deleteProject}
      >
        Delete
      </AlertDialogAction>
    </AlertDialogFooter>
  </AlertDialogContent>
</AlertDialog>

For high-risk deletes, require typing the resource name to enable the button.

Forms inside dialogs

Control open so you can keep the dialog open on validation error and close only on success:

const [open, setOpen] = React.useState(false);
async function onSubmit(values) {
  await save(values);     // throws → dialog stays open, error shows
  setOpen(false);         // success → close
  toast.success("Saved");
}
<Dialog open={open} onOpenChange={setOpen}>…</Dialog>

Warn before discarding unsaved changes: intercept onOpenChange and confirm if the form isDirty.

Accessibility (mostly handled, don't break it)

  • Always include DialogTitle (+ DialogDescription) — they back aria-labelledby/describedby. Visually hide the title with sr-only if needed, but keep it.
  • Focus moves into the dialog on open and returns to the trigger on close — don't disable this.
  • Don't stack modals. Replace content or use a multi-step flow instead.

Pitfalls

  • Dialog for destructive actions — outside-click dismiss can skip the decision; use AlertDialog.
  • Closing on submit before the request resolves — close on success only.
  • No unsaved-changes guard — users lose form input on accidental dismiss.
  • Missing DialogTitle — breaks the accessible name; Radix will warn.
  • Modal-on-modal stacking — confusing focus; redesign the flow.
  • Putting huge content in a modal — use a Sheet or a full page instead.

Hand-off

Overlays that host forms-and-validation, confirm data-tables row actions, and pair with notifications-and-toasts for post-action feedback.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.