# Waitlist field

> An email field that becomes its own answer: the button stretches across it, then settles as "You’re on the list · #1,248".

The first thing a launch page asks for, and usually a form that blinks and shows a green line. Here it is one surface. Submit and the button stretches across the whole field while a light sweeps through it. When the answer comes back it settles in place: a check draws itself, the label morphs to "You’re on the list", and the place number rolls up into view. A bad email gets a small shake and a hint underneath; a failed request folds the button back with "Try again".

## Install

```bash
npx shadcn@latest add https://hairlineui.com/r/waitlist-field.json
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: none
- Hairline UI components it needs (the CLI installs them too): `number-roll`, `text-morph`
- Docs and live preview: https://hairlineui.com/ui/waitlist-field
- Registry item (source): https://hairlineui.com/r/waitlist-field.json

## Usage

```tsx
import { WaitlistField } from "@/components/waitlist-field";

<WaitlistField onSubmit={(email) => joinWaitlist(email)} />
```

## With your API

Return a promise from onSubmit; resolve with the place in line to show it, throw to show Try again.

```tsx
"use client";
import { WaitlistField } from "@/components/waitlist-field";

export function Hero() {
  return (
    <WaitlistField
      onSubmit={async (email) => {
        const res = await fetch("/api/waitlist", { method: "POST", body: JSON.stringify({ email }) });
        if (!res.ok) throw new Error("Couldn't join");
        const { position } = await res.json();
        return { position };
      }}
    />
  );
}

// app/api/waitlist/route.ts
export async function POST(req: Request) {
  const { email } = await req.json();
  const position = await db.waitlist.add(email); // your storage; returns their place
  return Response.json({ position });
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `onSubmit` | `(email) => Promise<{ position? } \| void>` | – | Runs on a valid email. Resolve to show the joined state, throw to show Try again. |
| `joined` | `{ position? } \| null` | – | Show the joined state straight away, e.g. for someone already on the list. |
| `placeholder` | `string` | `"you@company.com"` | The field’s placeholder. |
| `labels` | `Partial<{ idle; pending; success; error; invalid }>` | – | Wording for each state and the invalid hint. |

## States

- **idle**: Email and "Join the waitlist" in one hairline pill; the button’s width is measured so the stretch starts exactly from it.
- **invalid**: A 380ms shake, the pill’s edge tints red and "Enter a full email address" slides in below. Typing clears it.
- **joining**: The button stretches across the field (560ms) and a light band sweeps through it; the label morphs to "Joining".
- **joined**: A check draws itself, the label morphs to "You’re on the list" and the place rolls up to #1,248.
- **failed**: The button folds back to its own width with a shake and "Try again".

## What it handles

The first thing a launch page asks for is an email address, and it is usually a form that blinks and shows a green line. This field becomes its own answer.

- **One surface**: The email and the button sit in one hairline pill, and the button’s width is measured so the stretch starts from it.
- **Validation with a hint**: A bad address shakes the pill, tints its edge red and shows “Enter a full email address” under it.
- **It shows it is working**: The button stretches across the field with a light sweeping through it while it joins.
- **The answer in place**: A check draws, the label becomes “You’re on the list” and the place in line rolls up to #1,248.
- **Failures fold back**: If the request fails, the button returns to its own width with a shake and “Try again”.
- **A real form**: Enter submits, the field has a label and autocomplete="email", and joining or failing is announced.

## Replaces

an email form, a submit button with states, an email validation hint, a success message, a place-in-line counter

## Where it fits

- **Launch pages**: The “Join the waitlist” field under a hero.
- **Coming-soon and beta pages**: Collect emails before a product is open.
- **Early-access forms**: Add people to a list for a feature that is not out yet.
- **In-app interest**: A “Notify me when it ships” field inside a product.

## Notes

- A real form: Enter submits, the field has a label, autocomplete="email" and the right mobile keyboard.
- The hint is linked to the field with aria-describedby, and joining or failing is announced from a status region.
- Installs Number roll and Text morph alongside it.
- With reduced motion there is no shake or sweep; states change in place.

License: MIT (https://hairlineui.com/license#components)
