Skip to main content
239

Search Lumen

Find components, APIs, guides, and recipes.

GitHub
Themes
Web docs
Overlays

DialogForm

Runs a form inside a dialog: it blocks closing while a request is pending, shows errors, and closes on success.

Frameworks
Astro · React · Elements · Dioxus
Registry
lumen add DialogForm
Interaction
Enhanced runtime
01

See it and copy it

Framework example

Choose Astro, React, Elements, or Dioxus to compare native usage against the shared visual output. Each example assumes the framework-level setup is already complete.

AstroCode target · live preview uses Astro

Rename project

The new name shows everywhere the project is listed.

Type “taken” to see a server error.

View DialogForm code

Framework usage

Switch targets to compare the adapter code. This live preview runs the Astro example. Before copying an example, complete the matching framework setup; React, Elements, and Dioxus use their own behavior APIs.Width controls resize the preview container. Resize your browser to test viewport breakpoints.
astro
---
import {
  Button,
  Dialog,
  DialogBody,
  DialogClose,
  DialogFooter,
  DialogForm,
  DialogHeader,
  DialogTitle,
  ErrorSummary,
  Field,
  FieldError,
  Input,
  Label
} from '@santi020k/lumen-astro'
---

<Button data-ui-dialog-trigger="ex-dialog-form">Rename project</Button>
<Dialog id="ex-dialog-form" aria-labelledby="ex-dialog-form-title">
  <DialogForm id="ex-dialog-form-rename" failureMessage="The project was not renamed. Try again.">
    <DialogHeader>
      <DialogTitle id="ex-dialog-form-title">Rename project</DialogTitle>
      <p>The new name shows everywhere the project is listed.</p>
    </DialogHeader>
    <DialogBody>
      <ErrorSummary heading="Check these fields" id="ex-dialog-form-errors" />
      <Field>
        <Label for="ex-dialog-form-name">Project name</Label>
        <Input data-error-required="Enter a project name." id="ex-dialog-form-name" name="name" required />
        <p data-ui-field-hint id="ex-dialog-form-name-hint">Type “taken” to see a server error.</p>
        <FieldError id="ex-dialog-form-name-error" />
      </Field>
    </DialogBody>
    <DialogFooter>
      <DialogClose variant="outline">Cancel</DialogClose>
      <Button type="submit">Rename</Button>
    </DialogFooter>
  </DialogForm>
</Dialog>

<script>
  import {
    type LumenFormErrorInput,
    lumenDialogFormSubmitEventName,
    readLumenDialogFormSubmitDetail
  } from '@santi020k/lumen-core'

  // Illustrative only: a real app sends the values to its server.
  const renameProject = (name: string) => new Promise<LumenFormErrorInput>(resolve => {
    setTimeout(() => {
      resolve(name.trim().toLowerCase() === 'taken' ?
        [{ controlId: 'ex-dialog-form-name', message: 'That name is taken.', name: 'name' }] :
        undefined)
    }, 800)
  })

  document.addEventListener(lumenDialogFormSubmitEventName, event => {
    const detail = readLumenDialogFormSubmitDetail(event)

    if (detail?.form.id !== 'ex-dialog-form-rename') return

    const name = detail.values.get('name')

    // Call waitUntil before the listener returns, so the dialog stays open while the request runs.
    detail.waitUntil(renameProject(typeof name === 'string' ? name : ''))
  })
</script>
Edit DialogForm in browser

Framework differences

React: Pass submit instead of listening for ui:dialog-form-submit. The pending state locks the Dialog without dismissOn props. Render ErrorSummary with errors and pass loading={pending} to the submit Button.

Elements: Put a native <form data-ui-form> inside lumen-dialog-form, inside the native dialog. Close controls and submit buttons update on their own while a submission is pending.

02

Choose your target

Add this component

Choose the package for your runtime. All adapters share the Lumen stylesheet. Use the matching registry command when you want a local wrapper for that framework.

bash@santi020k/lumen-astro
pnpm add @santi020k/lumen-astro
bashAstro wrapper
lumen add DialogForm

API reference

Lumen-specific props and runtime attributes for the Astro primitive. Use the framework differences above and the copyable examples for React composition and Elements attributes; the public adapter types define their supported contracts.

AttributeValuesDefaultDescription
childrenDialogHeader, DialogBody, DialogFooter, or task contentrequiredRenders the native form of the enclosing Dialog or AlertDialog. With a DialogBody inside, the header and footer stay visible while the body scrolls.
method"dialog" | "post" | "get""dialog"Used when the form submits natively, such as before JavaScript loads: "dialog" closes the dialog and "post" sends the form.
failureMessagestring"Something went wrong. Try again."Shown in the ErrorSummary when a submission fails. Every value stays. Elements uses failure-message.
submit(values: FormData) => PromiseLike<LumenFormErrorInput>-Runs after client validation passes. Resolve with field or form errors to keep the dialog open, or undefined to close it. Without submit, a valid form submits natively.
onSuccess() => void-Called when a submission resolves without errors.
children({ errors, pending })(state: { errors: LumenFormErrors; pending: boolean }) => ReactNode-Pass errors to ErrorSummary and pending to the submit Button loading prop. DialogClose disables itself while pending.
ui:dialog-form-submitCustomEvent<LumenDialogFormSubmitDetail>-Fires after client validation passes. Call event.detail.waitUntil(promise) synchronously to run the pending flow.
form[data-ui-form]native childrequiredlumen-dialog-form adds the form classes, data-slot, and data-ui-dialog-form to this form and runs its behavior.
UIPrimitivesAstro runtimerequiredAdds validation, the pending lock, and error focus. Without it, the form submits natively.
class, classNamestring""Merges custom classes with the generated ui-* root classes.
...native attributesHTML attributes-Forwards standard attributes to the root element unless the component consumes them.

Customize DialogForm

Start with semantic theme tokens and a class on the public component. Keep its accessible name, focus treatment, and interaction state intact.

cssScoped theme overrides
.product-dialog-form {
  --surface: 0 0% 100%;
  --ink: 220 20% 15%;
  --line: 220 15% 82%;
}

Apply product-dialog-form through Astro's class, React's className, or the custom element's class. Verify foreground and background contrast in both schemes.

HookValuesDefaultContract
form[data-ui-form]native childrequiredlumen-dialog-form adds the form classes, data-slot, and data-ui-dialog-form to this form and runs its behavior.
class, classNamestring""Merges custom classes with the generated ui-* root classes.

Use the documented hooks above and adapter types when targeting component states. Theme guide · Accessibility verification scope

Keyboard interactions

Keyboard behavior provided by the Astro UIPrimitives runtime for this component.

KeyAction
Enter in a text fieldSubmit the form. If a field is invalid, the dialog stays open and focus moves to the first error.
EscapeClose the dialog as usual and clear the errors. While a submission is pending, Escape does nothing.

Runtime events

CustomEvents dispatched by the Astro UIPrimitives runtime for this component.

EventTargetDetailWhen
ui:dialog-form-submitDialogForm form ([data-ui-dialog-form])LumenDialogFormSubmitDetail: { form: HTMLFormElement, submitter: HTMLElement | null, values: FormData, waitUntil(promise: PromiseLike<LumenFormErrorInput>): void }Cancelable. Bubbles after a valid submit. Call waitUntil synchronously: the promise resolves to field or form errors, or undefined to close the dialog, and a rejection shows failureMessage. Without waitUntil the form submits natively; preventDefault cancels that. React uses submit instead.

Web docsFull catalog