FormsQuoteSteps
Searchastronomic.dev# QuoteSteps
For a longer quote form: the same form in steps, with Next and Back, that checks each step and still works as one long form with no script.
Interactive: inline script.
## Usage
```astro
import QuoteSteps from "@astronomic/ui-pro/components/QuoteSteps.astro";
```
## Examples
### A quote in three steps
Tilth & Stone's quote form, a plain post: services as option chips, the yard, then the reader's details. Next checks the step before it moves on, Back keeps every value, and the Form's own button shows on the last step. With no script it is one long form.
```astro
---
import Field from "@astronomic-dev/ui/components/Field.astro";
import Form from "@astronomic-dev/ui/components/Form.astro";
import Icon from "@astronomic-dev/ui/components/Icon.astro";
import Input from "@astronomic-dev/ui/components/Input.astro";
import Select from "@astronomic-dev/ui/components/Select.astro";
import Textarea from "@astronomic-dev/ui/components/Textarea.astro";
import { optionChip, optionChipBox, optionChipInput } from "@astronomic-dev/ui/lib/chip.ts";
import { cn } from "@astronomic-dev/ui/lib/cn.ts";
import QuoteStep from "@astronomic/ui-pro/components/QuoteStep.astro";
import QuoteSteps from "@astronomic/ui-pro/components/QuoteSteps.astro";
import { landscaping } from "../_data/groundcrew.ts";
const chip = optionChip({ size: "lg", box: true });
---
<!-- A plain post: with no script it is one long form. Next checks each step; try it with the ZIP code empty. -->
<Form class="mx-auto w-full max-w-lg" action="#" submitLabel="Send my quote request">
<QuoteSteps>
<QuoteStep title="Services" text="Pick one or more. We will price each one.">
<div class="flex flex-wrap gap-2">
{
landscaping.services.slice(0, 5).map((s) => (
<label class={cn(chip, "max-w-full")}>
<input type="checkbox" name="service" value={s.slug} class={optionChipInput} />
<span class={optionChipBox}>
<Icon size="sm">
<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M3.5 8.5l3 3 6-7" /></svg>
</Icon>
</span>
<span class="min-w-0 [overflow-wrap:anywhere]">{s.title}</span>
</label>
))
}
</div>
</QuoteStep>
<QuoteStep title="Your yard" text="Where the work is, and how we get to it.">
<Field label="Street address" for="qs-main-address" required>
<Input id="qs-main-address" name="address" autocomplete="street-address" required />
</Field>
<Field label="ZIP code" for="qs-main-zip" required>
<Input id="qs-main-zip" name="zip" inputmode="numeric" autocomplete="postal-code" pattern="[0-9]{5}" maxlength="5" required class="max-w-40 tabular-nums" />
</Field>
<Field label="Yard size" for="qs-main-size">
<Select id="qs-main-size" name="size">
<option value="">Not sure</option>
<option value="small">Under 2,500 sq ft</option>
<option value="medium">2,500 to 6,000 sq ft</option>
<option value="large">Over 6,000 sq ft</option>
</Select>
</Field>
<Field label="Access" for="qs-main-access" hint="A side gate, a dog, a slope: anything that helps us plan.">
<Textarea id="qs-main-access" name="access" rows="3" />
</Field>
</QuoteStep>
<QuoteStep title="Your details" text="We answer within one business day.">
<Field label="Name" for="qs-main-name" required>
<Input id="qs-main-name" name="name" autocomplete="name" required />
</Field>
<Field label="Email" for="qs-main-email" required>
<Input id="qs-main-email" name="email" type="email" autocomplete="email" spellcheck="false" required />
</Field>
<Field label="Phone" for="qs-main-phone">
<Input id="qs-main-phone" name="phone" type="tel" autocomplete="tel" />
</Field>
</QuoteStep>
</QuoteSteps>
<p slot="note" class="m-0">{landscaping.name}: we never share your details.</p>
</Form>
```
### Sent in the page
On a Form with enhance="fetch": each step's errors show under its fields as the Form's do, and are cleared as soon as a field is fixed. On the last step, a bad field in an earlier step opens that step first. After a good send the form resets to step 1 and the status says it. progressText sets the progress line's words.
```astro
---
import Field from "@astronomic-dev/ui/components/Field.astro";
import Form from "@astronomic-dev/ui/components/Form.astro";
import Icon from "@astronomic-dev/ui/components/Icon.astro";
import Input from "@astronomic-dev/ui/components/Input.astro";
import Select from "@astronomic-dev/ui/components/Select.astro";
import { optionChip, optionChipBox, optionChipInput } from "@astronomic-dev/ui/lib/chip.ts";
import { cn } from "@astronomic-dev/ui/lib/cn.ts";
import QuoteStep from "@astronomic/ui-pro/components/QuoteStep.astro";
import QuoteSteps from "@astronomic/ui-pro/components/QuoteSteps.astro";
import { cleaning } from "../_data/groundcrew.ts";
const chip = optionChip({ size: "lg", box: true });
---
<!-- Sent in the page (enhance="fetch"): each step's errors show under its fields, and the answer shows under the button. -->
<Form class="mx-auto w-full max-w-lg" action="/__astronomic/form-echo?delay=600" enhance="fetch" submitLabel="Get my price" successText="Thanks. We will send your price by email today.">
<QuoteSteps progressText="{title}, step {n} of {total}">
<QuoteStep title="The cleaning" text="Pick what you need.">
<div class="flex flex-wrap gap-2">
{
cleaning.services.slice(0, 4).map((s) => (
<label class={cn(chip, "max-w-full")}>
<input type="checkbox" name="service" value={s.slug} class={optionChipInput} />
<span class={optionChipBox}>
<Icon size="sm">
<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M3.5 8.5l3 3 6-7" /></svg>
</Icon>
</span>
<span class="min-w-0 [overflow-wrap:anywhere]">{s.title}</span>
</label>
))
}
</div>
</QuoteStep>
<QuoteStep title="Your home">
<Field label="Bedrooms" for="qs-fetch-bedrooms" required errorSlot>
<Select id="qs-fetch-bedrooms" name="bedrooms" required data-error="Pick the number of bedrooms.">
<option value="">Pick one</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4 or more</option>
</Select>
</Field>
<Field label="ZIP code" for="qs-fetch-zip" required errorSlot>
<Input id="qs-fetch-zip" name="zip" inputmode="numeric" autocomplete="postal-code" pattern="[0-9]{5}" maxlength="5" required data-error="Enter a 5-digit ZIP code, like 85233." class="max-w-40 tabular-nums" />
</Field>
</QuoteStep>
<QuoteStep title="Your email">
<Field label="Email" for="qs-fetch-email" required errorSlot>
<Input id="qs-fetch-email" name="email" type="email" autocomplete="email" spellcheck="false" required data-error="Enter an email address, like name@example.com." />
</Field>
</QuoteStep>
</QuoteSteps>
</Form>
```
### Step pills
progress="pills": a numbered pill per step (its number and title) in place of the bar. The current pill is inverted and each done one keeps its number in the accent; the progress line stays for a screen reader only.
```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";
import Select from "@astronomic-dev/ui/components/Select.astro";
import Textarea from "@astronomic-dev/ui/components/Textarea.astro";
import QuoteStep from "@astronomic/ui-pro/components/QuoteStep.astro";
import QuoteSteps from "@astronomic/ui-pro/components/QuoteSteps.astro";
import { plumbing } from "../_data/groundcrew.ts";
---
<!-- progress="pills": a numbered pill per step in place of the bar; the current pill inverted, each done one's number in the accent. -->
<Form class="mx-auto w-full max-w-lg" action="#" submitLabel="Send my quote request">
<QuoteSteps progress="pills">
<QuoteStep title="What do you need?" text="Pick the closest. You can tell us more in step 3.">
<Field label="Service" for="qs-pills-service" required>
<Select id="qs-pills-service" name="service" required>
<option value="">Pick a service</option>
{plumbing.services.slice(0, 5).map((s) => <option value={s.slug}>{s.title}</option>)}
</Select>
</Field>
</QuoteStep>
<QuoteStep title="Property and access" text="Where the work is.">
<Field label="ZIP code" for="qs-pills-zip" required>
<Input id="qs-pills-zip" name="zip" inputmode="numeric" autocomplete="postal-code" pattern="[0-9]{5}" maxlength="5" required class="max-w-40 tabular-nums" />
</Field>
<Field label="Access" for="qs-pills-access" hint="A gate code, a dog, where to park.">
<Textarea id="qs-pills-access" name="access" rows="3" />
</Field>
</QuoteStep>
<QuoteStep title="Your details" text="We answer within one business day.">
<Field label="Name" for="qs-pills-name" required>
<Input id="qs-pills-name" name="name" autocomplete="name" required />
</Field>
<Field label="Phone" for="qs-pills-phone" required>
<Input id="qs-pills-phone" name="phone" type="tel" autocomplete="tel" required />
</Field>
</QuoteStep>
</QuoteSteps>
<p slot="note" class="m-0">{plumbing.name}: we never share your details.</p>
</Form>
```
### One step
With one QuoteStep there is no progress line and no Back or Next: a plain form with a fieldset named by its heading.
```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";
import Textarea from "@astronomic-dev/ui/components/Textarea.astro";
import QuoteStep from "@astronomic/ui-pro/components/QuoteStep.astro";
import QuoteSteps from "@astronomic/ui-pro/components/QuoteSteps.astro";
---
<!-- One step: no progress line and no Back or Next. A plain form with a fieldset and the Form's own button. -->
<Form class="mx-auto w-full max-w-lg" action="#" submitLabel="Request a visit">
<QuoteSteps>
<QuoteStep title="Book an estimate" text="We come out, measure and give you a fixed price.">
<Field label="Name" for="qs-one-name" required>
<Input id="qs-one-name" name="name" autocomplete="name" required />
</Field>
<Field label="Phone" for="qs-one-phone" required>
<Input id="qs-one-phone" name="phone" type="tel" autocomplete="tel" required />
</Field>
<Field label="What is the project?" for="qs-one-project">
<Textarea id="qs-one-project" name="project" rows="3" />
</Field>
</QuoteStep>
</QuoteSteps>
</Form>
```
## Props
### QuoteSteps
| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `progressText` | `string` | `"Step {n} of {total}: {title}"` | The progress line over the steps, with {n}, {total} and the step's {title} filled. A status line: a screen reader says it on each move. |
| `nextText` | `string` | `"Next"` | The Next button's words. |
| `backText` | `string` | `"Back"` | The Back button's words. |
| `prefill` | `string[]` | `["service"]` | Field names read from the page's query string to tick or fill when the page opens, so the services picked in a QuotePicker (?service=…) start ticked. A field the reader already changed is left alone; an unknown value is ignored. |
| `progress` | `"bar" \| "pills"` | `"bar"` | How the place in the steps shows: a bar of marks over the progress line, or a numbered pill per step (number and title; the current one aria-current="step" and inverted, each done one with its number in the accent and "done" for a screen reader). With pills the progress line is for a screen reader only. |
| `pillsLabel` | `string` | `"Steps"` | pills: the step list's accessible name. |
| `doneLabel` | `string` | `"done"` | pills: what a screen reader hears after a done step's title (", done"). |
| `barClass` | `string` | None | For recipes: more classes on the row that holds Back and Next. |
| `pillClass` | `string` | None | For recipes: more classes on each step pill, such as your own card fill. The current pill's inverted look still wins. |
| `class` | `string` | None | More classes on the root, merged with cn(), so yours win on conflicts. |
| Slot | Description |
| --- | --- |
| `default` | The QuoteStep parts, in order. Put QuoteSteps in a Form's default slot. |
Any other attribute goes on the root <div>.
## Accessibility
| Key | Action |
| --- | --- |
| Enter | In a field or on Next: checks the step and moves on; on the last step, sends the form |
| Enter or Space | On Back: shows the step before, values kept |
| Tab | Moves through the shown step's fields, then Back, Next or the Form's button |
- One plain form: with no script every step is a visible fieldset with its legend, the progress line and Back and Next stay hidden, and the Form's own button posts it all. Nothing is ever disabled, so a hidden step's fields still submit.
- Each step is a fieldset named by its legend, which holds the step's heading. Next and Back move focus to the shown step's heading, so a screen reader says where the reader is, and focus never stays on a button that hides.
- The progress line is a status line, said on each move and not when the page opens (step 1's line is in the server HTML). The marks above it are drawn for the eye only (aria-hidden).
- With progress="pills" the steps are an ordered list named by pillsLabel: each pill reads the progress line's words around its title ("Step 2 of 3: Property and access"), the shown one is aria-current="step", and a done one adds ", done". The numbers are decoration. The current pill is marked by its fill, not by color alone.
- Next checks the step first: a bad field shows its error and takes focus, as the Form's own submit does. On the last step a bad field in an earlier step opens that step before it is reported.
- Enter in a field moves to the next step (Next is the form's default button), and on the last step it sends with the Form's own button. The Form's status stays shown on every step, so its messages are always said.
- Back and Next are at least 44px tall at every pointer.
QuoteSteps
ProFor a longer quote form: the same form in steps, with Next and Back, that checks each step and still works as one long form with no script.
- File
- QuoteSteps.astro
- Group
- Forms
- Kind
- Interactive: inline script
- Examples
- 4
Examples
Drag the orange handle to set the width. Frames get real breakpoints.
- Static
- Interactive
- Framed
A quote in three steps
Tilth & Stone's quote form, a plain post: services as option chips, the yard, then the reader's details. Next checks the step before it moves on, Back keeps every value, and the Form's own button shows on the last step. With no script it is one long form.
This preview did not load.
examples/quotesteps/main.astro
---
import Field from "@astronomic-dev/ui/components/Field.astro";
import Form from "@astronomic-dev/ui/components/Form.astro";
import Icon from "@astronomic-dev/ui/components/Icon.astro";
import Input from "@astronomic-dev/ui/components/Input.astro";
import Select from "@astronomic-dev/ui/components/Select.astro";
import Textarea from "@astronomic-dev/ui/components/Textarea.astro";
import { optionChip, optionChipBox, optionChipInput } from "@astronomic-dev/ui/lib/chip.ts";
import { cn } from "@astronomic-dev/ui/lib/cn.ts";
import QuoteStep from "@astronomic/ui-pro/components/QuoteStep.astro";
import QuoteSteps from "@astronomic/ui-pro/components/QuoteSteps.astro";
import { landscaping } from "../_data/groundcrew.ts";
const chip = optionChip({ size: "lg", box: true });
---
<!-- A plain post: with no script it is one long form. Next checks each step; try it with the ZIP code empty. -->
<Form class="mx-auto w-full max-w-lg" action="#" submitLabel="Send my quote request">
<QuoteSteps>
<QuoteStep title="Services" text="Pick one or more. We will price each one.">
<div class="flex flex-wrap gap-2">
{
landscaping.services.slice(0, 5).map((s) => (
<label class={cn(chip, "max-w-full")}>
<input type="checkbox" name="service" value={s.slug} class={optionChipInput} />
<span class={optionChipBox}>
<Icon size="sm">
<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M3.5 8.5l3 3 6-7" /></svg>
</Icon>
</span>
<span class="min-w-0 [overflow-wrap:anywhere]">{s.title}</span>
</label>
))
}
</div>
</QuoteStep>
<QuoteStep title="Your yard" text="Where the work is, and how we get to it.">
<Field label="Street address" for="qs-main-address" required>
<Input id="qs-main-address" name="address" autocomplete="street-address" required />
</Field>
<Field label="ZIP code" for="qs-main-zip" required>
<Input id="qs-main-zip" name="zip" inputmode="numeric" autocomplete="postal-code" pattern="[0-9]{5}" maxlength="5" required class="max-w-40 tabular-nums" />
</Field>
<Field label="Yard size" for="qs-main-size">
<Select id="qs-main-size" name="size">
<option value="">Not sure</option>
<option value="small">Under 2,500 sq ft</option>
<option value="medium">2,500 to 6,000 sq ft</option>
<option value="large">Over 6,000 sq ft</option>
</Select>
</Field>
<Field label="Access" for="qs-main-access" hint="A side gate, a dog, a slope: anything that helps us plan.">
<Textarea id="qs-main-access" name="access" rows="3" />
</Field>
</QuoteStep>
<QuoteStep title="Your details" text="We answer within one business day.">
<Field label="Name" for="qs-main-name" required>
<Input id="qs-main-name" name="name" autocomplete="name" required />
</Field>
<Field label="Email" for="qs-main-email" required>
<Input id="qs-main-email" name="email" type="email" autocomplete="email" spellcheck="false" required />
</Field>
<Field label="Phone" for="qs-main-phone">
<Input id="qs-main-phone" name="phone" type="tel" autocomplete="tel" />
</Field>
</QuoteStep>
</QuoteSteps>
<p slot="note" class="m-0">{landscaping.name}: we never share your details.</p>
</Form>Sent in the page
On a Form with enhance="fetch": each step's errors show under its fields as the Form's do, and are cleared as soon as a field is fixed. On the last step, a bad field in an earlier step opens that step first. After a good send the form resets to step 1 and the status says it. progressText sets the progress line's words.
This preview did not load.
examples/quotesteps/fetch.astro
---
import Field from "@astronomic-dev/ui/components/Field.astro";
import Form from "@astronomic-dev/ui/components/Form.astro";
import Icon from "@astronomic-dev/ui/components/Icon.astro";
import Input from "@astronomic-dev/ui/components/Input.astro";
import Select from "@astronomic-dev/ui/components/Select.astro";
import { optionChip, optionChipBox, optionChipInput } from "@astronomic-dev/ui/lib/chip.ts";
import { cn } from "@astronomic-dev/ui/lib/cn.ts";
import QuoteStep from "@astronomic/ui-pro/components/QuoteStep.astro";
import QuoteSteps from "@astronomic/ui-pro/components/QuoteSteps.astro";
import { cleaning } from "../_data/groundcrew.ts";
const chip = optionChip({ size: "lg", box: true });
---
<!-- Sent in the page (enhance="fetch"): each step's errors show under its fields, and the answer shows under the button. -->
<Form class="mx-auto w-full max-w-lg" action="/__astronomic/form-echo?delay=600" enhance="fetch" submitLabel="Get my price" successText="Thanks. We will send your price by email today.">
<QuoteSteps progressText="{title}, step {n} of {total}">
<QuoteStep title="The cleaning" text="Pick what you need.">
<div class="flex flex-wrap gap-2">
{
cleaning.services.slice(0, 4).map((s) => (
<label class={cn(chip, "max-w-full")}>
<input type="checkbox" name="service" value={s.slug} class={optionChipInput} />
<span class={optionChipBox}>
<Icon size="sm">
<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M3.5 8.5l3 3 6-7" /></svg>
</Icon>
</span>
<span class="min-w-0 [overflow-wrap:anywhere]">{s.title}</span>
</label>
))
}
</div>
</QuoteStep>
<QuoteStep title="Your home">
<Field label="Bedrooms" for="qs-fetch-bedrooms" required errorSlot>
<Select id="qs-fetch-bedrooms" name="bedrooms" required data-error="Pick the number of bedrooms.">
<option value="">Pick one</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4 or more</option>
</Select>
</Field>
<Field label="ZIP code" for="qs-fetch-zip" required errorSlot>
<Input id="qs-fetch-zip" name="zip" inputmode="numeric" autocomplete="postal-code" pattern="[0-9]{5}" maxlength="5" required data-error="Enter a 5-digit ZIP code, like 85233." class="max-w-40 tabular-nums" />
</Field>
</QuoteStep>
<QuoteStep title="Your email">
<Field label="Email" for="qs-fetch-email" required errorSlot>
<Input id="qs-fetch-email" name="email" type="email" autocomplete="email" spellcheck="false" required data-error="Enter an email address, like name@example.com." />
</Field>
</QuoteStep>
</QuoteSteps>
</Form>Step pills
progress="pills": a numbered pill per step (its number and title) in place of the bar. The current pill is inverted and each done one keeps its number in the accent; the progress line stays for a screen reader only.
This preview did not load.
examples/quotesteps/pills.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";
import Select from "@astronomic-dev/ui/components/Select.astro";
import Textarea from "@astronomic-dev/ui/components/Textarea.astro";
import QuoteStep from "@astronomic/ui-pro/components/QuoteStep.astro";
import QuoteSteps from "@astronomic/ui-pro/components/QuoteSteps.astro";
import { plumbing } from "../_data/groundcrew.ts";
---
<!-- progress="pills": a numbered pill per step in place of the bar; the current pill inverted, each done one's number in the accent. -->
<Form class="mx-auto w-full max-w-lg" action="#" submitLabel="Send my quote request">
<QuoteSteps progress="pills">
<QuoteStep title="What do you need?" text="Pick the closest. You can tell us more in step 3.">
<Field label="Service" for="qs-pills-service" required>
<Select id="qs-pills-service" name="service" required>
<option value="">Pick a service</option>
{plumbing.services.slice(0, 5).map((s) => <option value={s.slug}>{s.title}</option>)}
</Select>
</Field>
</QuoteStep>
<QuoteStep title="Property and access" text="Where the work is.">
<Field label="ZIP code" for="qs-pills-zip" required>
<Input id="qs-pills-zip" name="zip" inputmode="numeric" autocomplete="postal-code" pattern="[0-9]{5}" maxlength="5" required class="max-w-40 tabular-nums" />
</Field>
<Field label="Access" for="qs-pills-access" hint="A gate code, a dog, where to park.">
<Textarea id="qs-pills-access" name="access" rows="3" />
</Field>
</QuoteStep>
<QuoteStep title="Your details" text="We answer within one business day.">
<Field label="Name" for="qs-pills-name" required>
<Input id="qs-pills-name" name="name" autocomplete="name" required />
</Field>
<Field label="Phone" for="qs-pills-phone" required>
<Input id="qs-pills-phone" name="phone" type="tel" autocomplete="tel" required />
</Field>
</QuoteStep>
</QuoteSteps>
<p slot="note" class="m-0">{plumbing.name}: we never share your details.</p>
</Form>One step
With one QuoteStep there is no progress line and no Back or Next: a plain form with a fieldset named by its heading.
This preview did not load.
examples/quotesteps/one-step.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";
import Textarea from "@astronomic-dev/ui/components/Textarea.astro";
import QuoteStep from "@astronomic/ui-pro/components/QuoteStep.astro";
import QuoteSteps from "@astronomic/ui-pro/components/QuoteSteps.astro";
---
<!-- One step: no progress line and no Back or Next. A plain form with a fieldset and the Form's own button. -->
<Form class="mx-auto w-full max-w-lg" action="#" submitLabel="Request a visit">
<QuoteSteps>
<QuoteStep title="Book an estimate" text="We come out, measure and give you a fixed price.">
<Field label="Name" for="qs-one-name" required>
<Input id="qs-one-name" name="name" autocomplete="name" required />
</Field>
<Field label="Phone" for="qs-one-phone" required>
<Input id="qs-one-phone" name="phone" type="tel" autocomplete="tel" required />
</Field>
<Field label="What is the project?" for="qs-one-project">
<Textarea id="qs-one-project" name="project" rows="3" />
</Field>
</QuoteStep>
</QuoteSteps>
</Form>