react.form.address-fields
A UK or international address form under one legend: each line labelled and autocompleted, checked by form.address.
React ^19 · TypeScript only A React component: use it from a TypeScript project with React installed. A client component ("use client").
1.0.0 · published 2026-10-10 by charlie · Anterra
Pinned by 10 tests, run in TypeScript.
What it does
A postal address under one legend, following the GOV.UK address pattern: one text input per line, each with its own label and the autocomplete token that lets a browser fill it. GB (and the Crown Dependencies GG, JE and IM) get the UK form; any other country gets an international form with that country's labels from `form.address` (ZIP code and State for the US, Eircode for Ireland), and its postcode optional where the country has none.
"use client";
import { AddressFields } from "#fune/react.form.address-fields@^1";
import { validateAddress } from "#fune/form.address@^1";
<AddressFields id="address" legend="What is your address?" value={address} onChange={setAddress}
showErrors={submitted} countries={[{ value: "GB", label: "United Kingdom" }, { value: "US", label: "United States" }]} />
// On the server, the same check (TypeScript, Python or Rust):
const check = validateAddress(submitted); // check.address is trimmed, its postcode normalised
For example
-
the UK form: lines, town, county and postcode, each labelled and autocompleted
<AddressFields id="address" legend="What is your address?" />renders
<div class="fune-field fune-address"><fieldset class="fune-fieldset"><legend class="fune-legend">What is your address?</legend><div class="fune-field"><label class="fune-label" for="address-line1">Address line 1</label><input class="fune-input" id="address-line1" type="text" autoComplete="address-line1" name="address-line1" value=""/></div><div class="fune-field"><label class="fune-label" for="address-line2">Address line 2 (optional)</label><input class="fune-input" id="address-line2" type="text" autoComplete="address-line2" name="address-line2" value=""/></div><div class="fune-field fune-field--width-20"><label class="fune-label" for="address-town">Town or city</label><input class="fune-input" id="address-town" type="text" autoComplete="address-level2" name="address-town" value=""/></div><div class="fune-field fune-field--width-20"><label class="fune-label" for="address-region">County (optional)</label><input class="fune-input" id="address-region" type="text" autoComplete="address-level1" name="address-region" value=""/></div><div class="fune-field fune-field--width-10"><label class="fune-label" for="address-postcode">Postcode</label><input class="fune-input" id="address-postcode" type="text" autoComplete="postal-code" spellCheck="false" name="address-postcode" value=""/></div><input type="hidden" readOnly="" name="address-country" value="GB"/></fieldset></div> -
a controlled UK address with its values
<AddressFields id="address" legend="What is your address?" value={{"line1":"10 Downing Street","line2":null,"town":"London","region":null,"postcode":"SW1A 2AA","country":"GB"}} />renders
<div class="fune-field fune-address"><fieldset class="fune-fieldset"><legend class="fune-legend">What is your address?</legend><div class="fune-field"><label class="fune-label" for="address-line1">Address line 1</label><input class="fune-input" id="address-line1" type="text" autoComplete="address-line1" name="address-line1" value="10 Downing Street"/></div><div class="fune-field"><label class="fune-label" for="address-line2">Address line 2 (optional)</label><input class="fune-input" id="address-line2" type="text" autoComplete="address-line2" name="address-line2" value=""/></div><div class="fune-field fune-field--width-20"><label class="fune-label" for="address-town">Town or city</label><input class="fune-input" id="address-town" type="text" autoComplete="address-level2" name="address-town" value="London"/></div><div class="fune-field fune-field--width-20"><label class="fune-label" for="address-region">County (optional)</label><input class="fune-input" id="address-region" type="text" autoComplete="address-level1" name="address-region" value=""/></div><div class="fune-field fune-field--width-10"><label class="fune-label" for="address-postcode">Postcode</label><input class="fune-input" id="address-postcode" type="text" autoComplete="postal-code" spellCheck="false" name="address-postcode" value="SW1A 2AA"/></div><input type="hidden" readOnly="" name="address-country" value="GB"/></fieldset></div>
The function
Written for React ^19, in TypeScript only. A component: it takes its props and renders HTML, which the tests below pin exactly.
A React capability: React ^19 · TypeScript only. This capability has no Rust implementation, so it is shown in TypeScript. A Rust project cannot use it: fune build stops and names where it was required. Your choice of Rust is kept for every other page.
export function AddressFields(props: AddressFieldsProps): JSX.Element
Its props, AddressFieldsProps. A ? marks one the caller may leave out.
| legend | ReactNode | the question, such as "What is your address?" |
| id? | string | the fieldset's id; the inputs are <id>-line1, <id>-line2, <id>-town, <id>-region, <id>-postcode and <id>-country; React's useId() when left out |
| name? | string | the start of the inputs' names, <name>-line1 and so on; the id when left out |
| hint? | ReactNode | help under the legend |
| value? | Address | the address, for a controlled form (with onChange) |
| defaultValue? | Address | the starting address, for an uncontrolled one; country GB when both are left out |
| onChange? | (value: Address) => void | called with the whole address whenever a field changes |
| onBlur? | () => void | called when any field loses focus, to mark the address touched |
| errors? | readonly AddressError[] | errors to show, such as validateAddress's on the server; each marks its field |
| showErrors? | boolean | check the current address with validateAddress and show its errors |
| countries? | readonly SelectOption[] | the countries to choose from (ISO codes as values): shows a country select; left out, the country is fixed |
| isPageHeading? | boolean | the legend is the page's heading |
| disabled? | boolean | shown but not editable, and not submitted |
| className? | string | added to the wrapper's classes |
| renders | JSX.Element |
The type it declares, generated into your project
/** One postal address: the UK form for GB, or an international one with the country's labels. */
export interface AddressFieldsProps {
/** the question, such as "What is your address?" */
readonly legend: ReactNode;
/** the fieldset's id; the inputs are <id>-line1, <id>-line2, <id>-town, <id>-region, <id>-postcode and <id>-country; React's useId() when left out */
readonly id?: string;
/** the start of the inputs' names, <name>-line1 and so on; the id when left out */
readonly name?: string;
/** help under the legend */
readonly hint?: ReactNode;
/** the address, for a controlled form (with onChange) */
readonly value?: Address;
/** the starting address, for an uncontrolled one; country GB when both are left out */
readonly defaultValue?: Address;
/** called with the whole address whenever a field changes */
readonly onChange?: (value: Address) => void;
/** called when any field loses focus, to mark the address touched */
readonly onBlur?: () => void;
/** errors to show, such as validateAddress's on the server; each marks its field */
readonly errors?: readonly AddressError[];
/** check the current address with validateAddress and show its errors */
readonly showErrors?: boolean;
/** the countries to choose from (ISO codes as values): shows a country select; left out, the country is fixed */
readonly countries?: readonly SelectOption[];
/** the legend is the page's heading */
readonly isPageHeading?: boolean;
/** shown but not editable, and not submitted */
readonly disabled?: boolean;
/** added to the wrapper's classes */
readonly className?: string;
}
Your code names it in one line, in the file that uses it
import { AddressFields } from "#fune/react.form.address-fields@^1";
Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.
"use client";
import { useId, useState, type JSX } from "react";
import { addressFormat, validateAddress, type Address, type AddressError, type AddressFormat } from "./form_address.ts"; ← from form.address ^1.0.0 · built alongside by fune
import { Fieldset } from "./react_form_fieldset.ts"; ← from react.form.fieldset ^1.0.0 · built alongside by fune
import { Select } from "./react_form_select.ts"; ← from react.form.select ^1.0.0 · built alongside by fune
import { TextField } from "./react_form_text_field.ts"; ← from react.form.text-field ^1.0.0 · built alongside by fune
import type { AddressFieldsProps } from "./react_form_address_fields_types.ts";
type Line = "line1" | "line2" | "town" | "region" | "postcode";
const EMPTY: Address = { line1: "", line2: null, town: "", region: null, postcode: null, country: "GB" };
// A country not in the list (or none chosen yet) still gets a usable form:
// the international labels, with the postcode optional.
function formatFor(country: string): AddressFormat {
try {
return addressFormat(country);
} catch {
return { country, name: country, uk: false, postcodeLabel: "Postal code", postcodeRequired: false, postcodeExample: null, regionLabel: "Region" };
}
}
/**
* The GOV.UK address pattern: several text inputs under one legend, each with
* its own label and the autocomplete token that lets a browser fill it
* (WCAG 1.3.5). For GB (and the Crown Dependencies) it is the UK form:
* address lines, town or city, county and postcode. For anywhere else the
* labels are that country's (ZIP code and State for the US), the postcode is
* optional where the country has none, and a country select is shown when
* countries are given. Errors come from validateAddress, field by field, the
* same check a server makes of the submitted address.
*/
export function AddressFields(props: AddressFieldsProps): JSX.Element {
const auto = useId();
const { legend, hint, value, defaultValue, onChange, onBlur, errors, showErrors, countries, isPageHeading, disabled, className } = props;
const id = props.id ?? auto;
const name = props.name ?? id;
const [own, setOwn] = useState<Address>(value ?? defaultValue ?? EMPTY);
const current = value ?? own;
const format = formatFor(current.country);
const shown: readonly AddressError[] = errors ?? (showErrors ? validateAddress(current).errors : []);
const message = (field: string) => shown.find((e) => e.field === field)?.message;
function change(field: Line | "country", text: string): void {
const next: Address = { ...current, [field]: text };
setOwn(next);
onChange?.(next);
}
const optional = (label: string) => `${label} (optional)`;
const line = (field: Line, label: string, autoComplete: string, width?: string) => {
const text = current[field];
return (
<TextField
id={`${id}-${field}`}
name={`${name}-${field}`}
label={label}
error={message(field)}
value={value ? (text ?? "") : undefined}
defaultValue={value ? undefined : (text ?? "")}
onChange={(next) => change(field, next)}
onBlur={onBlur}
autoComplete={autoComplete}
spellCheck={field === "postcode" ? false : undefined}
disabled={disabled}
className={width}
/>
);
};
return (
<Fieldset id={id} legend={legend} hint={hint} isPageHeading={isPageHeading} className={className ? `fune-address ${className}` : "fune-address"}>
{line("line1", "Address line 1", "address-line1")}
{line("line2", optional("Address line 2"), "address-line2")}
{line("town", "Town or city", "address-level2", "fune-field--width-20")}
{line("region", optional(format.regionLabel), "address-level1", "fune-field--width-20")}
{line("postcode", format.postcodeRequired ? format.postcodeLabel : optional(format.postcodeLabel), "postal-code", "fune-field--width-10")}
{countries ? (
<Select
id={`${id}-country`}
name={`${name}-country`}
label="Country"
options={countries}
placeholder="Choose a country"
error={message("country")}
value={value ? current.country : undefined}
defaultValue={value ? undefined : current.country}
onChange={(next) => change("country", next)}
onBlur={onBlur}
autoComplete="country"
disabled={disabled}
/>
) : (
<input type="hidden" name={`${name}-country`} value={current.country} readOnly />
)}
</Fieldset>
);
}Install
npm install react react-dom
fune build
With that line in your source, in a TypeScript project (language typescript in fune.project) with React ^19 installed (Functional Weave does not ship it, and fune build stops with the npm install line if it is missing), fune build resolves it and its 4 dependencies, pins them in fune.lock, downloads only the TypeScript package of each, and builds the code above into your project’s .fune/build, one readable file per capability with a header linking back here. Or pin a range in fune.project and build in one step:
fune add react.form.address-fields
The manifest, vectors and README with only the TypeScript implementation. Install it without the registry with fune add ./react.form.address-fields-1.0.0-typescript.fune, or fetch it from a terminal with fune pull react.form.address-fields@1.0.0:typescript.
It is React ^19 · TypeScript only, so there is no package for Python or Rust. The full package is one file too: react.form.address-fields-1.0.0.fune, 36,873 bytes, sha256 02bb646f22d3fcdeee165c689ee0b0e7d3c749cd85f60ac124efecc55bc07519.
Customise it in your app
The seams this capability offers. Put a marker directly above a function of your own and fune build wires it into the built code; the package on the registry is not changed, the built file’s header lists it under CUSTOMISED, and fune hooks lists every hook in the project. How hooks work.
before — your function gets the arguments and returns them, changed or not, or throws to refuse the call.
// fune: before react.form.address-fields
after — your function gets the result and the arguments, and returns the final result.
// fune: after react.form.address-fields
replace — inside this capability’s code only, calls to a dependency go to your function, with the same signature. Other capabilities that use it are unaffected; write in * to replace it everywhere.
// fune: replace form.address in react.form.address-fields
// fune: replace react.form.fieldset in react.form.address-fields
// fune: replace react.form.select in react.form.address-fields
// fune: replace react.form.text-field in react.form.address-fields
step — your function runs at a numbered point inside the function’s body, receives the in-scope values it names as parameters, and may return replacements. List the points with fune show react.form.address-fields --steps.
// fune: step react.form.address-fields after <n|label>
Tests
A version published now needs at least 8 tests for every function, and one that expects the error for each function that throws; the registry refuses it otherwise. fune verify --all runs each case in TypeScript alone, with the React in tooling/react, and a project runs them again with fune verify. This page lists the cases; it does not run them. The exact JSON is vectors.json. A component’s tests are render tests: the props go in, and the HTML renderToStaticMarkup makes of them has to match exactly; a React warning during the render fails the test.
-
the UK form: lines, town, county and postcode, each labelled and autocompleted
<AddressFields id="address" legend="What is your address?" />renders
<div class="fune-field fune-address"><fieldset class="fune-fieldset"><legend class="fune-legend">What is your address?</legend><div class="fune-field"><label class="fune-label" for="address-line1">Address line 1</label><input class="fune-input" id="address-line1" type="text" autoComplete="address-line1" name="address-line1" value=""/></div><div class="fune-field"><label class="fune-label" for="address-line2">Address line 2 (optional)</label><input class="fune-input" id="address-line2" type="text" autoComplete="address-line2" name="address-line2" value=""/></div><div class="fune-field fune-field--width-20"><label class="fune-label" for="address-town">Town or city</label><input class="fune-input" id="address-town" type="text" autoComplete="address-level2" name="address-town" value=""/></div><div class="fune-field fune-field--width-20"><label class="fune-label" for="address-region">County (optional)</label><input class="fune-input" id="address-region" type="text" autoComplete="address-level1" name="address-region" value=""/></div><div class="fune-field fune-field--width-10"><label class="fune-label" for="address-postcode">Postcode</label><input class="fune-input" id="address-postcode" type="text" autoComplete="postal-code" spellCheck="false" name="address-postcode" value=""/></div><input type="hidden" readOnly="" name="address-country" value="GB"/></fieldset></div> -
a controlled UK address with its values
<AddressFields id="address" legend="What is your address?" value={{"line1":"10 Downing Street","line2":null,"town":"London","region":null,"postcode":"SW1A 2AA","country":"GB"}} />renders
<div class="fune-field fune-address"><fieldset class="fune-fieldset"><legend class="fune-legend">What is your address?</legend><div class="fune-field"><label class="fune-label" for="address-line1">Address line 1</label><input class="fune-input" id="address-line1" type="text" autoComplete="address-line1" name="address-line1" value="10 Downing Street"/></div><div class="fune-field"><label class="fune-label" for="address-line2">Address line 2 (optional)</label><input class="fune-input" id="address-line2" type="text" autoComplete="address-line2" name="address-line2" value=""/></div><div class="fune-field fune-field--width-20"><label class="fune-label" for="address-town">Town or city</label><input class="fune-input" id="address-town" type="text" autoComplete="address-level2" name="address-town" value="London"/></div><div class="fune-field fune-field--width-20"><label class="fune-label" for="address-region">County (optional)</label><input class="fune-input" id="address-region" type="text" autoComplete="address-level1" name="address-region" value=""/></div><div class="fune-field fune-field--width-10"><label class="fune-label" for="address-postcode">Postcode</label><input class="fune-input" id="address-postcode" type="text" autoComplete="postal-code" spellCheck="false" name="address-postcode" value="SW1A 2AA"/></div><input type="hidden" readOnly="" name="address-country" value="GB"/></fieldset></div> -
UK errors with showErrors: each field marked with its own message
<AddressFields id="address" legend="What is your address?" showErrors value={{"line1":"","line2":null,"town":"","region":null,"postcode":"SW1A","country":"GB"}} />renders
<div class="fune-field fune-address"><fieldset class="fune-fieldset"><legend class="fune-legend">What is your address?</legend><div class="fune-field fune-field--error"><label class="fune-label" for="address-line1">Address line 1</label><p class="fune-error-message" id="address-line1-error"><span class="fune-visually-hidden">Error:</span> Enter address line 1, typically the building and street</p><input class="fune-input fune-input--error" id="address-line1" type="text" autoComplete="address-line1" aria-describedby="address-line1-error" aria-invalid="true" name="address-line1" value=""/></div><div class="fune-field"><label class="fune-label" for="address-line2">Address line 2 (optional)</label><input class="fune-input" id="address-line2" type="text" autoComplete="address-line2" name="address-line2" value=""/></div><div class="fune-field fune-field--error fune-field--width-20"><label class="fune-label" for="address-town">Town or city</label><p class="fune-error-message" id="address-town-error"><span class="fune-visually-hidden">Error:</span> Enter town or city</p><input class="fune-input fune-input--error" id="address-town" type="text" autoComplete="address-level2" aria-describedby="address-town-error" aria-invalid="true" name="address-town" value=""/></div><div class="fune-field fune-field--width-20"><label class="fune-label" for="address-region">County (optional)</label><input class="fune-input" id="address-region" type="text" autoComplete="address-level1" name="address-region" value=""/></div><div class="fune-field fune-field--error fune-field--width-10"><label class="fune-label" for="address-postcode">Postcode</label><p class="fune-error-message" id="address-postcode-error"><span class="fune-visually-hidden">Error:</span> Enter a real postcode</p><input class="fune-input fune-input--error" id="address-postcode" type="text" autoComplete="postal-code" spellCheck="false" aria-describedby="address-postcode-error" aria-invalid="true" name="address-postcode" value="SW1A"/></div><input type="hidden" readOnly="" name="address-country" value="GB"/></fieldset></div> -
a valid UK address with showErrors shows no errors
<AddressFields id="address" legend="What is your address?" showErrors value={{"line1":"1 High Street","line2":null,"town":"Leeds","region":null,"postcode":"ls1 1aa","country":"GB"}} />renders
<div class="fune-field fune-address"><fieldset class="fune-fieldset"><legend class="fune-legend">What is your address?</legend><div class="fune-field"><label class="fune-label" for="address-line1">Address line 1</label><input class="fune-input" id="address-line1" type="text" autoComplete="address-line1" name="address-line1" value="1 High Street"/></div><div class="fune-field"><label class="fune-label" for="address-line2">Address line 2 (optional)</label><input class="fune-input" id="address-line2" type="text" autoComplete="address-line2" name="address-line2" value=""/></div><div class="fune-field fune-field--width-20"><label class="fune-label" for="address-town">Town or city</label><input class="fune-input" id="address-town" type="text" autoComplete="address-level2" name="address-town" value="Leeds"/></div><div class="fune-field fune-field--width-20"><label class="fune-label" for="address-region">County (optional)</label><input class="fune-input" id="address-region" type="text" autoComplete="address-level1" name="address-region" value=""/></div><div class="fune-field fune-field--width-10"><label class="fune-label" for="address-postcode">Postcode</label><input class="fune-input" id="address-postcode" type="text" autoComplete="postal-code" spellCheck="false" name="address-postcode" value="ls1 1aa"/></div><input type="hidden" readOnly="" name="address-country" value="GB"/></fieldset></div> -
the US form: State and ZIP code, with a country select
<AddressFields id="addr" legend="Delivery address" countries={[{"value":"GB","label":"United Kingdom"},{"value":"US","label":"United States"},{"value":"IE","label":"Ireland"}]} value={{"line1":"1600 Pennsylvania Avenue NW","line2":null,"town":"Washington","region":"DC","postcode":"20500","country":"US"}} />renders
<div class="fune-field fune-address"><fieldset class="fune-fieldset"><legend class="fune-legend">Delivery address</legend><div class="fune-field"><label class="fune-label" for="addr-line1">Address line 1</label><input class="fune-input" id="addr-line1" type="text" autoComplete="address-line1" name="addr-line1" value="1600 Pennsylvania Avenue NW"/></div><div class="fune-field"><label class="fune-label" for="addr-line2">Address line 2 (optional)</label><input class="fune-input" id="addr-line2" type="text" autoComplete="address-line2" name="addr-line2" value=""/></div><div class="fune-field fune-field--width-20"><label class="fune-label" for="addr-town">Town or city</label><input class="fune-input" id="addr-town" type="text" autoComplete="address-level2" name="addr-town" value="Washington"/></div><div class="fune-field fune-field--width-20"><label class="fune-label" for="addr-region">State (optional)</label><input class="fune-input" id="addr-region" type="text" autoComplete="address-level1" name="addr-region" value="DC"/></div><div class="fune-field fune-field--width-10"><label class="fune-label" for="addr-postcode">ZIP code</label><input class="fune-input" id="addr-postcode" type="text" autoComplete="postal-code" spellCheck="false" name="addr-postcode" value="20500"/></div><div class="fune-field"><label class="fune-label" for="addr-country">Country</label><select class="fune-select" id="addr-country" name="addr-country" autoComplete="country"><option value="">Choose a country</option><option value="GB">United Kingdom</option><option value="US" selected="">United States</option><option value="IE">Ireland</option></select></div></fieldset></div> -
a bad ZIP code with showErrors
<AddressFields id="addr" legend="Delivery address" countries={[{"value":"GB","label":"United Kingdom"},{"value":"US","label":"United States"},{"value":"IE","label":"Ireland"}]} showErrors value={{"line1":"1 Main St","line2":null,"town":"Springfield","region":null,"postcode":"1234","country":"US"}} />renders
<div class="fune-field fune-address"><fieldset class="fune-fieldset"><legend class="fune-legend">Delivery address</legend><div class="fune-field"><label class="fune-label" for="addr-line1">Address line 1</label><input class="fune-input" id="addr-line1" type="text" autoComplete="address-line1" name="addr-line1" value="1 Main St"/></div><div class="fune-field"><label class="fune-label" for="addr-line2">Address line 2 (optional)</label><input class="fune-input" id="addr-line2" type="text" autoComplete="address-line2" name="addr-line2" value=""/></div><div class="fune-field fune-field--width-20"><label class="fune-label" for="addr-town">Town or city</label><input class="fune-input" id="addr-town" type="text" autoComplete="address-level2" name="addr-town" value="Springfield"/></div><div class="fune-field fune-field--width-20"><label class="fune-label" for="addr-region">State (optional)</label><input class="fune-input" id="addr-region" type="text" autoComplete="address-level1" name="addr-region" value=""/></div><div class="fune-field fune-field--error fune-field--width-10"><label class="fune-label" for="addr-postcode">ZIP code</label><p class="fune-error-message" id="addr-postcode-error"><span class="fune-visually-hidden">Error:</span> Enter a real ZIP code</p><input class="fune-input fune-input--error" id="addr-postcode" type="text" autoComplete="postal-code" spellCheck="false" aria-describedby="addr-postcode-error" aria-invalid="true" name="addr-postcode" value="1234"/></div><div class="fune-field"><label class="fune-label" for="addr-country">Country</label><select class="fune-select" id="addr-country" name="addr-country" autoComplete="country"><option value="">Choose a country</option><option value="GB">United Kingdom</option><option value="US" selected="">United States</option><option value="IE">Ireland</option></select></div></fieldset></div> -
Ireland: the Eircode is optional
<AddressFields id="addr" legend="Delivery address" countries={[{"value":"GB","label":"United Kingdom"},{"value":"US","label":"United States"},{"value":"IE","label":"Ireland"}]} defaultValue={{"line1":"","line2":null,"town":"","region":null,"postcode":null,"country":"IE"}} />renders
<div class="fune-field fune-address"><fieldset class="fune-fieldset"><legend class="fune-legend">Delivery address</legend><div class="fune-field"><label class="fune-label" for="addr-line1">Address line 1</label><input class="fune-input" id="addr-line1" type="text" autoComplete="address-line1" name="addr-line1" value=""/></div><div class="fune-field"><label class="fune-label" for="addr-line2">Address line 2 (optional)</label><input class="fune-input" id="addr-line2" type="text" autoComplete="address-line2" name="addr-line2" value=""/></div><div class="fune-field fune-field--width-20"><label class="fune-label" for="addr-town">Town or city</label><input class="fune-input" id="addr-town" type="text" autoComplete="address-level2" name="addr-town" value=""/></div><div class="fune-field fune-field--width-20"><label class="fune-label" for="addr-region">County (optional)</label><input class="fune-input" id="addr-region" type="text" autoComplete="address-level1" name="addr-region" value=""/></div><div class="fune-field fune-field--width-10"><label class="fune-label" for="addr-postcode">Eircode (optional)</label><input class="fune-input" id="addr-postcode" type="text" autoComplete="postal-code" spellCheck="false" name="addr-postcode" value=""/></div><div class="fune-field"><label class="fune-label" for="addr-country">Country</label><select class="fune-select" id="addr-country" name="addr-country" autoComplete="country"><option value="">Choose a country</option><option value="GB">United Kingdom</option><option value="US">United States</option><option value="IE" selected="">Ireland</option></select></div></fieldset></div> -
no country chosen with showErrors: Select a country
<AddressFields id="addr" legend="Delivery address" countries={[{"value":"GB","label":"United Kingdom"},{"value":"US","label":"United States"},{"value":"IE","label":"Ireland"}]} showErrors value={{"line1":"1 Rue de Rivoli","line2":null,"town":"Paris","region":null,"postcode":null,"country":""}} />renders
<div class="fune-field fune-address"><fieldset class="fune-fieldset"><legend class="fune-legend">Delivery address</legend><div class="fune-field"><label class="fune-label" for="addr-line1">Address line 1</label><input class="fune-input" id="addr-line1" type="text" autoComplete="address-line1" name="addr-line1" value="1 Rue de Rivoli"/></div><div class="fune-field"><label class="fune-label" for="addr-line2">Address line 2 (optional)</label><input class="fune-input" id="addr-line2" type="text" autoComplete="address-line2" name="addr-line2" value=""/></div><div class="fune-field fune-field--width-20"><label class="fune-label" for="addr-town">Town or city</label><input class="fune-input" id="addr-town" type="text" autoComplete="address-level2" name="addr-town" value="Paris"/></div><div class="fune-field fune-field--width-20"><label class="fune-label" for="addr-region">Region (optional)</label><input class="fune-input" id="addr-region" type="text" autoComplete="address-level1" name="addr-region" value=""/></div><div class="fune-field fune-field--width-10"><label class="fune-label" for="addr-postcode">Postal code (optional)</label><input class="fune-input" id="addr-postcode" type="text" autoComplete="postal-code" spellCheck="false" name="addr-postcode" value=""/></div><div class="fune-field fune-field--error"><label class="fune-label" for="addr-country">Country</label><p class="fune-error-message" id="addr-country-error"><span class="fune-visually-hidden">Error:</span> Select a country</p><select class="fune-select fune-select--error" id="addr-country" name="addr-country" autoComplete="country" aria-describedby="addr-country-error" aria-invalid="true"><option value="" selected="">Choose a country</option><option value="GB">United Kingdom</option><option value="US">United States</option><option value="IE">Ireland</option></select></div></fieldset></div> -
errors passed in, such as the server's, mark their fields
<AddressFields id="address" legend="What is your address?" errors={[{"field":"postcode","message":"We do not deliver to this postcode"}]} value={{"line1":"1 Croft Road","line2":null,"town":"Lerwick","region":null,"postcode":"ZE1 0AA","country":"GB"}} />renders
<div class="fune-field fune-address"><fieldset class="fune-fieldset"><legend class="fune-legend">What is your address?</legend><div class="fune-field"><label class="fune-label" for="address-line1">Address line 1</label><input class="fune-input" id="address-line1" type="text" autoComplete="address-line1" name="address-line1" value="1 Croft Road"/></div><div class="fune-field"><label class="fune-label" for="address-line2">Address line 2 (optional)</label><input class="fune-input" id="address-line2" type="text" autoComplete="address-line2" name="address-line2" value=""/></div><div class="fune-field fune-field--width-20"><label class="fune-label" for="address-town">Town or city</label><input class="fune-input" id="address-town" type="text" autoComplete="address-level2" name="address-town" value="Lerwick"/></div><div class="fune-field fune-field--width-20"><label class="fune-label" for="address-region">County (optional)</label><input class="fune-input" id="address-region" type="text" autoComplete="address-level1" name="address-region" value=""/></div><div class="fune-field fune-field--error fune-field--width-10"><label class="fune-label" for="address-postcode">Postcode</label><p class="fune-error-message" id="address-postcode-error"><span class="fune-visually-hidden">Error:</span> We do not deliver to this postcode</p><input class="fune-input fune-input--error" id="address-postcode" type="text" autoComplete="postal-code" spellCheck="false" aria-describedby="address-postcode-error" aria-invalid="true" name="address-postcode" value="ZE1 0AA"/></div><input type="hidden" readOnly="" name="address-country" value="GB"/></fieldset></div> -
a hint, a page heading, a name and a class of its own
<AddressFields id="home" name="homeAddress" legend="Where do you live?" hint="Your main home" isPageHeading className="app-address" />renders
<div class="fune-field fune-address app-address"><fieldset class="fune-fieldset" aria-describedby="home-hint"><legend class="fune-legend fune-legend--heading"><h1 class="fune-legend-heading">Where do you live?</h1></legend><div class="fune-hint" id="home-hint">Your main home</div><div class="fune-field"><label class="fune-label" for="home-line1">Address line 1</label><input class="fune-input" id="home-line1" type="text" autoComplete="address-line1" name="homeAddress-line1" value=""/></div><div class="fune-field"><label class="fune-label" for="home-line2">Address line 2 (optional)</label><input class="fune-input" id="home-line2" type="text" autoComplete="address-line2" name="homeAddress-line2" value=""/></div><div class="fune-field fune-field--width-20"><label class="fune-label" for="home-town">Town or city</label><input class="fune-input" id="home-town" type="text" autoComplete="address-level2" name="homeAddress-town" value=""/></div><div class="fune-field fune-field--width-20"><label class="fune-label" for="home-region">County (optional)</label><input class="fune-input" id="home-region" type="text" autoComplete="address-level1" name="homeAddress-region" value=""/></div><div class="fune-field fune-field--width-10"><label class="fune-label" for="home-postcode">Postcode</label><input class="fune-input" id="home-postcode" type="text" autoComplete="postal-code" spellCheck="false" name="homeAddress-postcode" value=""/></div><input type="hidden" readOnly="" name="homeAddress-country" value="GB"/></fieldset></div>
Verification
Verified by the operator, not the sandbox 10 test vectors declared; none run by the registry.
Verified locally by the registry's operator, not by the sandbox. This version was published with FUNE_VERIFY_MODE=inline-dev (the operator's import of the first-party registry, or a development server): the server validated the package - its manifest, signatures, imports, safety lint and test rules - but the registry did not run its test vectors in its sandbox. The operator runs them with `fune verify --all` before importing.
Signed by the registry with key fw-9dc887227da47575 (ed25519), over its integrity and this report's digest. The full report · JSON
More from the author
| Field | Label | autocomplete | |-------|-------|--------------| | line1 | Address line 1 | address-line1 | | line2 | Address line 2 (optional) | address-line2 | | town | Town or city | address-level2 | | region | County (optional), or the country's region label | address-level1 | | postcode | Postcode, or the country's label; "(optional)" where not required | postal-code | | country | Country (a select, when `countries` is given; else a hidden input) | country |
- **Errors** come field by field: from `errors` (such as the server's `validateAddress(...).errors`), or with `showErrors` from checking the current address. Each marks its own input (`aria-invalid`, `aria-describedby` to its message) through `react.form.text-field`. - **The country decides the form.** Changing the country select relabels the region and postcode at once. A country code the list does not know still renders, with the international labels. - **Not an address lookup.** Finding the address from a postcode needs Royal Mail's PAF or a lookup service, which is network work and yours.
It is a client component. Classes: those of `react.form.fieldset`, `react.form.text-field` and `react.form.select`, plus `fune-address` on the wrapper and `fune-field--width-20` / `fune-field--width-10` on the town, region and postcode fields.
Sources: GOV.UK Design System, "Addresses" pattern https://design-system.service.gov.uk/patterns/addresses/ ; HTML, autofill tokens https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill .
## Notices
Portions derived from GOV.UK Frontend (https://github.com/alphagov/govuk-frontend), Copyright (c) 2017 Crown Copyright (Government Digital Service), under the MIT License; the full notice is in NOTICE.
Files
| Path | Bytes |
|---|---|
| NOTICE | 1,223 |
| README.md | 2,761 |
| impl/typescript.tsx | 4,322 |
| vectors.json | 20,951 |