# Address form

A controlled native shipping and optional billing address form with consumer-supplied countries, regions, linked errors and reset handling.

Access: pro. Category: Forms. Kind: composite.

## When to use

- Use it when a page needs a controlled native shipping and optional billing address form with consumer-supplied countries, regions, linked errors and reset handling.
- Choose it when the host application can supply the required state and keep business logic outside the presentation component.

## Alternatives

- Choose form-field instead when a labeled email field with validation and help text is the actual interface need, rather than address form.

## Setup for agents

Use React 19 and TypeScript. Initialize shadcn for your framework, then merge this exact entry into components.json:

```json
{
  "registries": {
    "@tidal-pro": {
      "url": "https://tidalui.com/r/pro/{name}.json",
      "headers": {
        "Authorization": "Bearer ${TIDALUI_TOKEN}"
      }
    }
  }
}
```

The namespace must be named **@tidal-pro** because transitive Pro dependencies use that namespace. Obtain an agent key from your active Pro account at https://tidalui.com/account. Keep TIDALUI_TOKEN in your local environment, never in components.json, client code, Git or logs.

```sh
export TIDALUI_TOKEN='your-private-agent-key'
npx shadcn@latest add @tidal-pro/waitlist-form
npx shadcn@latest add https://tidalui.com/r/tidal-button.json
```

Free command: `npx shadcn@latest add https://tidalui.com/r/<name>.json`.
Pro command: `npx shadcn@latest add @tidal-pro/<name>`.

Import the base stylesheet and every stylesheet listed on the installed item's metadata. For example:

```tsx
import "./components/ui/tidal.css";
import "./components/ui/hero-section.css";
// Place installed components inside this wrapper:
<div className="tidal-scope" data-theme="dark">...</div>
```

Omit data-theme for the default light theme. Put the attribute on the same tidal-scope element for dark mode. Every component installs the shared free tidal-base dependency. After upgrading, run `npx shadcn@latest add https://tidalui.com/r/tidal-base.json --overwrite` to receive current tokens. Review local modifications before overwriting.

Vite: Use React + TypeScript. Map @/* to ./src/* in paths and Vite resolve.alias. Import tidal.css and each component stylesheet in your application entry.

Next.js 15 App Router: Next.js App Router: import tidal.css and component CSS in app/layout.tsx. Interactive examples belong in a client component with "use client". Map @/* to ./* or ./src/* to match your project.

TypeScript 6: use paths without baseUrl:

```json
{
  "compilerOptions": {
    "paths": {
      "@/*": [
        "./src/*"
      ]
    }
  }
}
```

Pro registry requests are server/CLI-only. Use the same-origin account interface in a browser; cross-origin Authorization preflights are intentionally unsupported.


## Install Address form

```sh
npx shadcn@latest add @tidal-pro/address-form
```

Stylesheets: `components/ui/tidal.css`, `components/ui/address-form.css`.

## Minimal example

```tsx
import"./components/ui/tidal.css";
import"./components/ui/address-form.css";
import{TidalAddressForm}from"./components/ui/address-form";
export default(p:Parameters<typeof TidalAddressForm>[0])=><div className="tidal-scope"><TidalAddressForm {...p}/></div>;
```

## Structured props

- `TidalAddressForm.shipping: TidalAddressSectionConfig`: Required shipping value accepted by this exported component.
- `TidalAddressForm.title: ReactNode`: Required title value accepted by this exported component.
- `TidalAddressForm.billing?: TidalBillingAddressConfig | undefined`: Optional billing value accepted by this exported component.
- `TidalAddressForm.busy?: boolean | undefined` (default false): Optional busy value accepted by this exported component.
- `TidalAddressForm.description?: ReactNode`: Optional description value accepted by this exported component.
- `TidalAddressForm.disabled?: boolean | undefined` (default false): Optional disabled value accepted by this exported component.
- `TidalAddressForm.error?: ReactNode`: Optional error value accepted by this exported component.
- `TidalAddressForm.errorRef?: Ref<HTMLDivElement> | undefined`: Optional error ref value accepted by this exported component.
- `TidalAddressForm.eyebrow?: ReactNode`: Optional eyebrow value accepted by this exported component.
- `TidalAddressForm.footer?: ReactNode`: Optional footer value accepted by this exported component.
- `TidalAddressForm.headingLevel?: "h2" | "h3" | "h4" | undefined` (default "h2"): Optional heading level value accepted by this exported component.
- `TidalAddressForm.labels?: Partial<TidalAddressFormLabels> | undefined`: Optional labels value accepted by this exported component.
- `TidalAddressForm.onReset?: ((event: FormEvent<HTMLFormElement>) => void) | undefined`: Callback invoked when the reset interaction is proposed.
- `TidalAddressForm.onResetRequest?: ((event: FormEvent<HTMLFormElement>) => void) | undefined`: Callback invoked when the reset request interaction is proposed.
- `TidalAddressForm.onSubmit?: ((event: FormEvent<HTMLFormElement>) => void) | undefined`: Callback invoked when the submit interaction is proposed.
- `TidalAddressForm.resetButtonProps?: Omit<ButtonHTMLAttributes<HTMLButtonElement>, "children"> | undefined`: Optional reset button props value accepted by this exported component.
- `TidalAddressForm.resetButtonRef?: Ref<HTMLButtonElement> | undefined`: Optional reset button ref value accepted by this exported component.
- `TidalAddressForm.status?: ReactNode`: Optional status value accepted by this exported component.
- `TidalAddressForm.submitButtonProps?: Omit<ButtonHTMLAttributes<HTMLButtonElement>, "children"> | undefined`: Optional submit button props value accepted by this exported component.
- `TidalAddressForm.submitButtonRef?: Ref<HTMLButtonElement> | undefined`: Optional submit button ref value accepted by this exported component.

## Complete usage example

[Source](https://tidalui.com/examples/address-form.tsx) | [Manifest](https://tidalui.com/examples/address-form.json). Install the listed additional dependencies. Consumer fixture: TypeScript pass; Vite pass. This fixture check is distinct from the actual shadcn install receipt.

```tsx
"use client";

import "./components/ui/tidal.css";

import { useEffect, useRef, useState, type Dispatch, type SetStateAction } from "react";

import { TidalAddressForm, type TidalAddressField, type TidalAddressOption, type TidalAddressValue } from "./components/ui/address-form";

import "./components/ui/address-form.css";



const tidalExampleStyles = ".tidal-scope .address-form-demo,\n.tidal-scope .address-form-demo * {\n  box-sizing: border-box;\n}\n\n.tidal-scope .address-form-demo {\n  display: grid;\n  width: min(100%, 1040px);\n  min-width: 0;\n  gap: 22px;\n  margin-inline: auto;\n  padding: clamp(16px, 4vw, 42px);\n}\n\n@container tidal-preview (max-width: 390px) {\n  .tidal-scope .address-form-demo {\n    gap: 16px;\n    padding: 12px;\n  }\n}";

const COUNTRIES: readonly TidalAddressOption[] = [
  { value: "US", label: "United States" },
  { value: "CA", label: "Canada" },
];

const REGIONS: Readonly<Record<string, readonly TidalAddressOption[]>> = {
  US: [
    { value: "IL", label: "Illinois" },
    { value: "IN", label: "Indiana" },
    { value: "MI", label: "Michigan" },
  ],
  CA: [
    { value: "ON", label: "Ontario" },
    { value: "QC", label: "Quebec" },
    { value: "BC", label: "British Columbia" },
  ],
};

const INITIAL_SHIPPING: TidalAddressValue = {
  name: "Avery Morgan",
  company: "Northstar Studio",
  line1: "1440 Market Street",
  line2: "Suite 210",
  city: "Chicago",
  region: "IL",
  postalCode: "60607",
  country: "US",
};

const INITIAL_BILLING: TidalAddressValue = {
  name: "Avery Morgan",
  company: "Northstar Studio",
  line1: "28 Wellington Street",
  line2: "",
  city: "Toronto",
  region: "ON",
  postalCode: "M5E 1C7",
  country: "CA",
};

export function AddressFormDemo() {
  const [shipping, setShipping] = useState<TidalAddressValue>({
    ...INITIAL_SHIPPING,
  });
  const [billing, setBilling] = useState<TidalAddressValue>({
    ...INITIAL_BILLING,
  });
  const [sameAsShipping, setSameAsShipping] = useState(true);
  const [busy, setBusy] = useState(false);
  const [status, setStatus] = useState("No unsaved changes.");
  const timerRef = useRef<number | null>(null);

  useEffect(
    () => () => {
      if (timerRef.current !== null) window.clearTimeout(timerRef.current);
    },
    [],
  );

  function cancelPending() {
    if (timerRef.current !== null) {
      window.clearTimeout(timerRef.current);
      timerRef.current = null;
    }
    setBusy(false);
  }

  function updateAddress(
    setter: Dispatch<SetStateAction<TidalAddressValue>>,
    field: TidalAddressField,
    value: string,
  ) {
    cancelPending();
    setter((current) => ({
      ...current,
      [field]: value,
      ...(field === "country" ? { region: "" } : null),
    }));
    setStatus("Unsaved changes.");
  }

  return (
    <section className="address-form-demo" aria-label="Address form preview">
      <TidalAddressForm
        title="Delivery address"
        description="Enter shipping and billing details."
        shipping={{
          value: shipping,
          onValueChange: (field, value) =>
            updateAddress(setShipping, field, value),
          countryOptions: COUNTRIES,
          regionOptions: REGIONS[shipping.country] ?? [],
          legend: "Shipping address",
          namePrefix: "shipping",
          fields: {
            name: {
              inputProps: { required: true, autoCapitalize: "words" },
            },
            line1: { inputProps: { required: true } },
            city: { inputProps: { required: true } },
            region: { selectProps: { required: true } },
            postalCode: { inputProps: { required: true } },
            country: { selectProps: { required: true } },
          },
        }}
        billing={{
          value: billing,
          onValueChange: (field, value) =>
            updateAddress(setBilling, field, value),
          countryOptions: COUNTRIES,
          regionOptions: REGIONS[billing.country] ?? [],
          legend: "Billing address",
          namePrefix: "billing",
          sameAsShipping,
          sameAsLabel: "Billing address matches shipping",
          onSameAsShippingChange: (checked) => {
            cancelPending();
            setSameAsShipping(checked);
            setStatus(
              checked
                ? "Billing matches the shipping address."
                : "Enter a separate billing address.",
            );
          },
          fields: {
            name: { inputProps: { required: true } },
            line1: { inputProps: { required: true } },
            city: { inputProps: { required: true } },
            region: { selectProps: { required: true } },
            postalCode: { inputProps: { required: true } },
            country: { selectProps: { required: true } },
          },
        }}
        busy={busy}
        onSubmit={(event) => {
          event.preventDefault();
          if (busy) return;
          const submittedFields = Array.from(
            new FormData(event.currentTarget).keys(),
          ).length;
          setBusy(true);
          setStatus("Saving address…");
          timerRef.current = window.setTimeout(() => {
            timerRef.current = null;
            setBusy(false);
            setStatus(
              `Address updated in this preview. ${submittedFields} fields checked.`,
            );
          }, 600);
        }}
        onResetRequest={() => {
          cancelPending();
          setShipping({ ...INITIAL_SHIPPING });
          setBilling({ ...INITIAL_BILLING });
          setSameAsShipping(true);
          setStatus("Address reset.");
        }}
        action="/local-address-preview"
        method="post"
        status={
          <span role="status" aria-live="polite">
            {status}
          </span>
        }
        submitButtonProps={{
          formAction: "/local-address-preview",
          formMethod: "post",
        }}
        footer="Sample data. Changes stay in this preview."
      />
    </section>
  );
}

export default function AgentExample() {
  return (
    <div className="tidal-scope" data-theme="light" dir="ltr">
      <style>{tidalExampleStyles}</style>
      <AddressFormDemo />
    </div>
  );
}

```

## Gotchas

- The host application owns data, validation, persistence, navigation, and service side effects described by this API.

## Theme and accessibility

{"tokens":["--t-accent","--t-border","--t-border-strong","--t-canvas","--t-danger","--t-display","--t-ease-out","--t-ease-spring","--t-faint","--t-font","--t-ink","--t-line","--t-muted","--t-primary","--t-primary-contrast","--t-radius-card","--t-radius-control","--t-radius-overlay","--t-radius-panel","--t-ring","--t-shadow-lg","--t-shadow-soft","--t-soft","--t-subtle","--t-surface","--t-wash"],"darkMode":true}

{"keyboard":["Tab and Shift+Tab follow the component's native focus order.","Arrow-key behavior follows the exported composite-control implementation."],"aria":"The component wires labels and relationships from consumer-provided visible text or ARIA props; preserve those labels in production.","notes":"Verify focus visibility, text alternatives, contrast, and reduced motion in the final composition."}

title and shipping configuration are required. Each address is fully controlled and supplies its value, onValueChange, visible legend, native name prefix, consumer-owned country and region options with unique values and string labels, optional linked field errors, native input/select/fieldset attributes and refs. Native autocomplete defaults to shipping or billing name, organization, address lines, city, region, postal code and country while an explicit consumer autoComplete is preserved. Optional billing configuration adds a controlled sameAsShipping native checkbox and independently controlled billing address reveal. The root preserves native form action/method/attributes/ref, final FormData contains the currently mounted named controls, onSubmit is consumer-owned, and busy keeps Submit focusable with aria-disabled while suppressing submission. Native onReset runs before optional onResetRequest and prevention suppresses the higher reset request. Submit/reset preserve native button attributes, form/submitter overrides, refs, explicit aria-disabled false and disabled semantics. Optional description, eyebrow, headings, labels, error summary/ref, status and footer are consumer-owned. The component performs no address lookup, normalization, delivery, payment, account, request, network, storage or persistence work.
