FormsFormStatus
Searchastronomic.dev# FormStatus For the line that says whether a form sent, read out by screen readers. Form uses it for you. Static: no JavaScript. ## Usage ```astro import FormStatus from "@astronomic-dev/ui/components/FormStatus.astro"; ``` ## Examples ### Inside a Form Form renders one FormStatus beside its button for you, with the texts from its own props. It is empty on load and takes no room; with enhance="fetch", Form's script writes the text and sets data-state (sending, success, error), which the colors read. This form posts to #, so the status stays empty. ```astro --- import Field from "@astronomic-dev/ui/components/Field.astro"; import Form from "@astronomic-dev/ui/components/Form.astro"; import Input from "@astronomic-dev/ui/components/Input.astro"; --- <Form class="max-w-md" action="#" submitLabel="Subscribe"> <Field label="Email" for="formstatus-email" required> <Input id="formstatus-email" name="email" type="email" autocomplete="email" spellcheck="false" required /> </Field> <p slot="note" class="m-0"> The FormStatus sits beside the button. It is empty, and takes no room, until Form's script writes to it, so this plain form shows none. </p> </Form> ``` ## Props ### FormStatus | Prop | Type | Default | Description | | --- | --- | --- | --- | | `sendingText` | `string` | `"Sending…"` | Said while the form sends. | | `successText` | `string` | `"Thanks. It has been sent."` | Said on a 2xx JSON answer, or 204 No Content. Focus moves here. | | `errorText` | `string` | `"It did not send. Check your connection and try again."` | Said on any other answer, or with no network. The user's text stays in the form. | | `tone` | `"page" \| "band"` | `"page"` | The surface: page (muted while sending, the danger color on an error) or band (the band's text colors and focus ring). | | `class` | `string` | None | More classes, merged with cn(), so yours win on conflicts. | Any other attribute goes on the <p>, except role. ## Accessibility - One role="status" region, so a screen reader reads each change politely, without cutting in. Use one per form. - It is in the page and empty from the start, so a screen reader is listening before the first change. - On success the script moves focus to it (tabindex=-1), so a keyboard user hears it and stays in place. Tab never stops on it. - The script looks it up inside its own form, so keep it inside the <form>, as Form does.
FormStatus
FreeFor the line that says whether a form sent, read out by screen readers. Form uses it for you.
- File
- FormStatus.astro
- Group
- Forms
- Kind
- Static: no JavaScript
- Examples
- 1
Examples
Drag the orange handle to set the width. Frames get real breakpoints.
- Static
- Interactive
- Framed
Inside a Form
Form renders one FormStatus beside its button for you, with the texts from its own props. It is empty on load and takes no room; with enhance="fetch", Form's script writes the text and sets data-state (sending, success, error), which the colors read. This form posts to #, so the status stays empty.
Force statemain.astro
examples/formstatus/main.astro
---
import Field from "@astronomic-dev/ui/components/Field.astro";
import Form from "@astronomic-dev/ui/components/Form.astro";
import Input from "@astronomic-dev/ui/components/Input.astro";
---
<Form class="max-w-md" action="#" submitLabel="Subscribe">
<Field label="Email" for="formstatus-email" required>
<Input id="formstatus-email" name="email" type="email" autocomplete="email" spellcheck="false" required />
</Field>
<p slot="note" class="m-0">
The FormStatus sits beside the button. It is empty, and takes no room, until Form's script writes to it, so this
plain form shows none.
</p>
</Form>Minimal · Light