Skip to content

Form dialog

A create or edit form in a dialog: a centred card on desktop, a bottom sheet on phones, with keyboard submit.

It has no trigger part: open it from your own button with open and onOpenChange. On phones it is a sheet from the bottom, and the default footer folds into the header: Cancel on the left, the submit button on the right. The Create more switch is in the desktop footer only.

Create form

No project created yet

Sizes

Create more

No tasks added yet

Destructive submit

With tabs

Nothing saved yet

Installation

npx shadcn@latest add @khaeli/form-dialog

Install @khaeli/foundation first: this item's styling lives in its tokens and [data-slot] rules.

Installs with

npm packages
  • @base-ui/react ^1.7.0
  • @keyline-icons/react ^2.2.0

Keyboard

EnterSpace
On your button, opens the dialog. Focus starts on the close button in the header (Cancel on phones), not on the first field: the first and third examples move it to the field in onOpenChangeComplete.
⌘ EnterCtrl Enter
Submit from anywhere in the dialog: they call onSubmit, or submit the form named by formId. Nothing happens while pending or submitDisabled is set. submitKbd shows the keys on the button.
Enter
In a single-line field of the form named by formId, submits it, as in any form.
TabShift Tab
Move through the header, the fields and the footer, and wrap at either end. Focus cannot leave the dialog while it is open.
Escape
Closes the dialog and returns focus to the button that opened it. It also closes while pending: only Cancel is disabled then, so keep the dialog open in onOpenChange when the request cannot be cancelled, as the first example does.

Accessible name

  • The dialog is named by title. description is always its description for assistive technology and is only shown with showDescription, so write one either way.
  • FormField ties its label to the control through htmlFor: give the control the same id. optional adds the word to the label.
  • There is no error part. Mark the field with aria-invalid, point aria-describedby at the message and give the message role="alert", as the first example does in hint.
  • While pending the submit button stays focusable, is marked aria-disabled and shows a loader. submitDisabled disables it outright: pass submitDescribedBy the id of the text that says why.
  • On phones a submit button labelled Save, Create, Done or Add becomes a check icon and keeps the label as its aria-label. Any other label stays as text.
  • With a custom footer, phones still show the submit button in the header. Give it submitLabel and onSubmit (or formId), or it does nothing.

Registry JSON

The item as the shadcn CLI reads it, with every file it ships: https://ui.khaeli.com/r/form-dialog.json