Address Input
AddressInput starts with a country, then shows line 1, line 2, city, region and postal code. The US, Canada and Australia get a state or province select, the UK gets no region field, and other countries get a free-text region. Switch the country to the United Kingdom to see the region field go, or to France for a free-text one.
@dentil/address-inputOn this page
{
"line1": "1 Market St",
"city": "San Francisco",
"state": "CA",
"postal_code": "94105",
"country": "US"
}components/demos/address-input-overview.tsx
'use client';
import { useState } from 'react';
import { AddressInput, type Address } from '@/components/dentil/address-input/address-input';
export function AddressInputOverviewDemo() {
const [address, setAddress] = useState<Address | undefined>({
line1: '1 Market St',
city: 'San Francisco',
state: 'CA',
postal_code: '94105',
country: 'US',
});
return (
<div className="grid w-full max-w-2xl gap-6 md:grid-cols-2">
<AddressInput value={address} onChange={setAddress} />
<pre className="bg-muted text-foreground overflow-x-auto rounded-md p-3 font-mono text-xs">
{JSON.stringify(address ?? null, null, 2)}
</pre>
</div>
);
}Installation
pnpm dlx shadcn@latest add @dentil/address-inputnpx shadcn@latest add @dentil/address-inputyarn dlx shadcn@latest add @dentil/address-inputbunx --bun shadcn@latest add @dentil/address-inputFiles land in components/dentil/address-input/. Uses the stock shadcn input and native-select, and installs Country Select and Select Search.
Adding regions
Pass regions to add a list for any country. The select stores the region code. Use hideStateFor for countries whose addresses have no region.
import { AddressInput } from '@/components/dentil/address-input/address-input';
<AddressInput
value={address}
onChange={setAddress}
regions={{
IE: {
label: 'County',
regions: [
{ code: 'D', name: 'Dublin' },
{ code: 'CO', name: 'Cork' },
// …
],
},
}}
hideStateFor={['GB', 'FR', 'DE']}
/>;API reference
AddressInput
| Prop | Type | Default | Description |
|---|---|---|---|
| value | Address | null | undefined | — | { line1, line2, city, state, postal_code, country }, all optional strings. |
| onChange | (value: Address | undefined) => void | — | Called with only the non-empty fields, or undefined when every field is empty. Changing the country clears the other fields. |
| error | string | — | Shown under the fields, which get aria-invalid and aria-describedby pointing at it. |
| disabled | boolean | false | Disables every field. |
| allowCountryChange | boolean | true | When false, the country select is disabled. |
| defaultCountry | string | — | Country used while value has none. The fields appear once there is a country. |
| regions | Record<string, { label: string; regions: { code; name }[] }> | — | Region lists by country code, merged over the built-in US, CA and AU lists. A listed country gets a select whose value is the region code. |
| hideStateFor | string[] | ['GB'] | Countries with no region field. Other countries without a list get a free-text field. |
| placeholders | Partial<Record<keyof Address, string>> | — | Placeholders and accessible labels for each field. |
| allowedCountries | string[] | — | Passed to CountrySelect. |
| preferredCountries | string[] | — | Passed to CountrySelect. |
| showFlags | boolean | false | Passed to CountrySelect. |
| locale | string | 'en' | Passed to CountrySelect. |