When to use it#
- Use it to ask for a postal address in separate boxes: street, line 2, postal code and city, in the Nordic order. Each box says what it is for, so a browser can fill in the whole address in one step (autofill). Put the boxes in a plain Fieldset with a legend such as “Your address”, and each box in its own Field with a visible label.
- Set the
country. It decides the shape of the postal code. AddAddressInput.Country, first in the Root, when the service takes addresses outside that country: the person picks the country, and the postal code and the search follow it. Without it, the suggestions offer only the Root’s country. - Give the Root a
geocoderwhen a choice from a list should fill in the postal code and city, for example in a change-of-address form. The street box stays free text, so a resident can ignore the list or add a house number that it does not have. Geocoders come from@kvirn-ui/map.kvirnGeocoderis built for the Kvirn map service, which Kvirn hosts in the EU. - Leave the
geocoderout when you have no address service that you can name in your privacy notice: the text typed in the street box is sent to it. A choice from the list is not a check, so validate the address as you would without it. - Not for an address the service already holds: use a DefinitionList with a change link. Not for the contact details of the page: use an Address. Not for a foreign address of unknown format: use a Textarea.
Example#
import { AddressInput, Field, Fieldset } from '@kvirn-ui/react'
import { useAddressInputTexts } from './texts.ts'
export function DefaultAddressInput() {
const { texts } = useAddressInputTexts()
return (
<Fieldset.Root>
<Fieldset.Legend>{texts.legend}</Fieldset.Legend>
<AddressInput.Root country="SE">
<Field.Root required>
<Field.Label>{texts.street}</Field.Label>
<AddressInput.Line1 name="line1" />
</Field.Root>
<Field.Root>
<Field.Label>{texts.line2}</Field.Label>
<AddressInput.Line2 name="line2" />
<Field.HelpText>{texts.line2Help}</Field.HelpText>
</Field.Root>
<Field.Root required>
<Field.Label>{texts.postalCode}</Field.Label>
<AddressInput.PostalCode name="postalCode" />
<Field.HelpText>{texts.postalCodeHelp}</Field.HelpText>
</Field.Root>
<Field.Root required>
<Field.Label>{texts.city}</Field.Label>
<AddressInput.City name="city" />
</Field.Root>
</AddressInput.Root>
</Fieldset.Root>
)
}Information: Did you know?
The examples set country on the Root, such as "SE". English implies no country, so without one the postal code box has no mask.
Use cases#
Fix the boxes that are wrong
Each box has its own error text. The error summary at the top has one link per wrong box, and each link moves focus to its box.
import { AddressInput, Button, ErrorSummary, Field, Fieldset, Stack } from '@kvirn-ui/react'
import { useId, useState } from 'react'
import { useAddressInputTexts } from './texts.ts'
type Part = 'street' | 'postalCode' | 'city'
type Errors = Record<Part, boolean>
const noErrors: Errors = { street: false, postalCode: false, city: false }
// Your own rules: here the street and the city must be filled in, and a Swedish postal code has
// five digits. A real service checks again on the server.
function check(data: FormData): Errors {
const text = (name: string) => {
const value = data.get(name)
return typeof value === 'string' ? value.trim() : ''
}
return {
street: text('line1') === '',
postalCode: text('postalCode').replaceAll(/\D/g, '').length !== 5,
city: text('city') === '',
}
}
export function ErrorsPerBox() {
const { texts } = useAddressInputTexts()
const idPrefix = useId()
const ids: Record<Part, string> = {
street: `${idPrefix}-street`,
postalCode: `${idPrefix}-postal-code`,
city: `${idPrefix}-city`,
}
const [errors, setErrors] = useState<Errors>(noErrors)
const [submitCount, setSubmitCount] = useState(0)
const [isSent, setIsSent] = useState(false)
const hasErrors = errors.street || errors.postalCode || errors.city
return (
<Stack className="kv-stack--gap-8">
{hasErrors ? (
<ErrorSummary.Root focusKey={submitCount}>
<ErrorSummary.Title />
<ErrorSummary.List>
{errors.street ? (
<ErrorSummary.Item>
<ErrorSummary.Link controlId={ids.street}>{texts.errorStreet}</ErrorSummary.Link>
</ErrorSummary.Item>
) : null}
{errors.postalCode ? (
<ErrorSummary.Item>
<ErrorSummary.Link controlId={ids.postalCode}>
{texts.errorPostalCode}
</ErrorSummary.Link>
</ErrorSummary.Item>
) : null}
{errors.city ? (
<ErrorSummary.Item>
<ErrorSummary.Link controlId={ids.city}>{texts.errorCity}</ErrorSummary.Link>
</ErrorSummary.Item>
) : null}
</ErrorSummary.List>
</ErrorSummary.Root>
) : null}
<form
noValidate
onSubmit={(event) => {
event.preventDefault()
const next = check(new FormData(event.currentTarget))
setErrors(next)
setSubmitCount((count) => count + 1)
setIsSent(!next.street && !next.postalCode && !next.city)
}}
>
<Fieldset.Root>
<Fieldset.Legend>{texts.legend}</Fieldset.Legend>
<AddressInput.Root country="SE">
<Field.Root controlId={ids.street} required invalid={errors.street}>
<Field.Label>{texts.street}</Field.Label>
<AddressInput.Line1 name="line1" />
<Field.ErrorMessage>{texts.errorStreet}</Field.ErrorMessage>
</Field.Root>
<Field.Root>
<Field.Label>{texts.line2}</Field.Label>
<AddressInput.Line2 name="line2" />
<Field.HelpText>{texts.line2Help}</Field.HelpText>
</Field.Root>
<Field.Root controlId={ids.postalCode} required invalid={errors.postalCode}>
<Field.Label>{texts.postalCode}</Field.Label>
<AddressInput.PostalCode
name="postalCode"
defaultValue={texts.incompletePostalCode}
/>
<Field.HelpText>{texts.postalCodeHelp}</Field.HelpText>
<Field.ErrorMessage>{texts.errorPostalCode}</Field.ErrorMessage>
</Field.Root>
<Field.Root controlId={ids.city} required invalid={errors.city}>
<Field.Label>{texts.city}</Field.Label>
<AddressInput.City name="city" />
<Field.ErrorMessage>{texts.errorCity}</Field.ErrorMessage>
</Field.Root>
</AddressInput.Root>
</Fieldset.Root>
<Button type="submit" className="kv-button--primary">
{texts.send}
</Button>
</form>
<output>{isSent ? texts.sent : null}</output>
</Stack>
)
}Warning: Don't forget
Say what is wrong and how to fix it, with the format: “Enter a postal code with 5 digits, like 123 45” (3.3.1 Error Identification, Level A; 3.3.3 Error Suggestion, Level AA).
Report a change of address with address autocomplete
A resident in Sweden reports a new address. They start typing their street, and the address service autocompletes the address. Type “Drottninggatan 6, Stockholm” in the street box. Suggestions appear as you type, and the first is “Drottninggatan 6, 111 51 Stockholm”. Choose it, and the street, postal code and town are filled in. Line 2 is never filled in. Type the town too: “Drottninggatan 6” alone matches that address in many towns. The street box stays free text, so the resident can ignore the list and type on. Enter, with no suggestion chosen, searches for the whole text and never sends the form. After a choice, a screen reader says one polite message, such as “Chosen: Drottninggatan 6, 111 51 Stockholm. The address is filled in below. Check it before you continue.” All the messages are in Announcements. In this example, the text you type in the street box goes to Kvirn’s map service. The suggested addresses come from OpenStreetMap: © OpenStreetMap contributors.
Information: Good to know
import { kvirnGeocoder } from '@kvirn-ui/map/kvirn'
import { AddressInput, Button, Field, Fieldset, Stack } from '@kvirn-ui/react'
import { useState } from 'react'
import { useAddressInputTexts } from './texts.ts'
// Made once, outside the component, so the Root gets the same geocoder on every render.
// This form takes Swedish addresses only, so the service searches Sweden only.
const geocoder = kvirnGeocoder({
url: 'https://geo.kvirn.com',
name: 'Kvirn’s map service',
countries: ['se'],
attribution: null,
})
export function AddressLookup() {
const { texts } = useAddressInputTexts()
const [isReported, setIsReported] = useState(false)
return (
<Stack className="kv-stack--gap-8">
<form
noValidate
onSubmit={(event) => {
event.preventDefault()
setIsReported(true)
}}
>
<Fieldset.Root>
<Fieldset.Legend>{texts.legendNew}</Fieldset.Legend>
<AddressInput.Root country="SE" geocoder={geocoder}>
<Field.Root required>
<Field.Label>{texts.street}</Field.Label>
<AddressInput.Line1 name="line1" privacyNotice={false} />
<Field.HelpText>{texts.lookupPrivacy}</Field.HelpText>
</Field.Root>
<Field.Root>
<Field.Label>{texts.line2}</Field.Label>
<AddressInput.Line2 name="line2" />
<Field.HelpText>{texts.line2Help}</Field.HelpText>
</Field.Root>
<Field.Root required>
<Field.Label>{texts.postalCode}</Field.Label>
<AddressInput.PostalCode name="postalCode" />
<Field.HelpText>{texts.postalCodeHelp}</Field.HelpText>
</Field.Root>
<Field.Root required>
<Field.Label>{texts.city}</Field.Label>
<AddressInput.City name="city" />
</Field.Root>
</AddressInput.Root>
</Fieldset.Root>
<Button type="submit" className="kv-button--primary">
{texts.reportChange}
</Button>
</form>
<output>{isReported ? texts.changeReported : null}</output>
</Stack>
)
}Props in this example:
geocoderon AddressInput.Rootcountryon AddressInput.RootprivacyNoticeon AddressInput.Line1
Warning: Don't forget
Name the address service in your privacy notice: the text typed in the street box and the visitor’s IP address reach it. If it handles that data for you, GDPR Article 28 needs a written agreement with its operator. By default, the notice above the street box says where the text goes, and it is read before anyone types. These examples turn off the notice above the street box (privacyNotice={false}) and the credit (attribution: null). If you do, add both yourself: say where the text goes in the street box’s help text, so it’s still read when the box gets focus, and credit the address data, such as © OpenStreetMap contributors, on the page.
Autocomplete a street inside a postal code
A resident knows the postal code and the town, and is not sure how the street is spelled. They start typing the street, and the address service autocompletes it inside that postal code and town. Type 66530 in Postal code (it shows as 665 30) and Kil in Town. Then type “Storg” in the street box. The list shows only addresses in that postal code and town, such as “Storgatan 41, 665 30 Kil”. Empty the two boxes and type “Storgatan”: the list now shows Storgatan in towns all over Sweden. Filling in the two boxes starts no search. The street box sends their values with its next search. Enter, with no suggestion chosen, searches the same way. If the resident picks a street that has no house numbers, the box asks for the number. The resident types it after the street, and the box asks the service for that exact house and fills in what it finds.
Information: Good to know
import { kvirnGeocoder } from '@kvirn-ui/map/kvirn'
import { AddressInput, Field, Fieldset } from '@kvirn-ui/react'
import { useAddressInputTexts } from './texts.ts'
const geocoder = kvirnGeocoder({
url: 'https://geo.kvirn.com',
name: 'Kvirn’s map service',
countries: ['se'],
attribution: null,
})
export function AddressInPostalArea() {
const { texts } = useAddressInputTexts()
return (
<Fieldset.Root>
<Fieldset.Legend>{texts.legend}</Fieldset.Legend>
<AddressInput.Root country="SE" geocoder={geocoder}>
<Field.Root required>
<Field.Label>{texts.street}</Field.Label>
<AddressInput.Line1 name="line1" privacyNotice={false} />
<Field.HelpText>{texts.lookupPrivacy}</Field.HelpText>
</Field.Root>
<Field.Root>
<Field.Label>{texts.line2}</Field.Label>
<AddressInput.Line2 name="line2" />
<Field.HelpText>{texts.line2Help}</Field.HelpText>
</Field.Root>
<Field.Root required>
<Field.Label>{texts.postalCode}</Field.Label>
<AddressInput.PostalCode name="postalCode" />
<Field.HelpText>{texts.postalCodeHelp}</Field.HelpText>
</Field.Root>
<Field.Root required>
<Field.Label>{texts.city}</Field.Label>
<AddressInput.City name="city" />
</Field.Root>
</AddressInput.Root>
</Fieldset.Root>
)
}Props in this example:
geocoderon AddressInput.Rootcountryon AddressInput.RootprivacyNoticeon AddressInput.Line1
Warning: Don't forget
These examples turn off the notice and the credit: see Report a change of address with address autocomplete for what to add instead.
Register a move to another Nordic country with address autocomplete
A resident registers a move to Norway. They start typing their street, and the address service autocompletes the address in the country they chose. The form starts with Norway. Add AddressInput.Country first in the Root, in a Field of its own. The postal code and the search follow the country. Type “Karl Johans gate 14”: the first suggestion is “Karl Johans gate 14, 0154 Oslo”. Change the country to Sweden, and the postal code box takes the Swedish shape, like 123 45. Or leave Norway chosen and type “Storgatan 8”. The first suggestion is in Sweden, and choosing it sets the country box to Sweden and says so. The service in this example holds addresses in Sweden and Norway. A country other than SE, FI and NO has no mask, so the postal code box takes letters and digits.
Information: Good to know
import { kvirnGeocoder } from '@kvirn-ui/map/kvirn'
import { AddressInput, Button, Field, Fieldset, Stack } from '@kvirn-ui/react'
import { useState } from 'react'
import { addressCountries, useAddressInputTexts } from './texts.ts'
// Made once, outside the component, so the Root gets the same geocoder on every render.
const geocoder = kvirnGeocoder({
url: 'https://geo.kvirn.com',
name: 'Kvirn’s map service',
countries: ['no', 'se'],
attribution: null,
})
export function AddressAbroad() {
const { texts } = useAddressInputTexts()
const [country, setCountry] = useState('NO')
const [isReported, setIsReported] = useState(false)
// The select changes when the user picks a country and when a suggestion is in another country.
const postalCodeHelp =
addressCountries.find((candidate) => candidate.code === country)?.postalCodeHelp ??
texts.postalCodeHelpOther
return (
<Stack className="kv-stack--gap-8">
<form
noValidate
onSubmit={(event) => {
event.preventDefault()
setIsReported(true)
}}
>
<Fieldset.Root>
<Fieldset.Legend>{texts.legendNew}</Fieldset.Legend>
<AddressInput.Root country="NO" geocoder={geocoder}>
<Field.Root required>
<Field.Label>{texts.country}</Field.Label>
<AddressInput.Country
name="country"
value={country}
onChange={(event) => setCountry(event.currentTarget.value)}
/>
</Field.Root>
<Field.Root required>
<Field.Label>{texts.street}</Field.Label>
<AddressInput.Line1 name="line1" privacyNotice={false} />
<Field.HelpText>{texts.lookupPrivacy}</Field.HelpText>
</Field.Root>
<Field.Root>
<Field.Label>{texts.line2}</Field.Label>
<AddressInput.Line2 name="line2" />
<Field.HelpText>{texts.line2Help}</Field.HelpText>
</Field.Root>
<Field.Root required>
<Field.Label>{texts.postalCode}</Field.Label>
<AddressInput.PostalCode name="postalCode" />
<Field.HelpText>{postalCodeHelp}</Field.HelpText>
</Field.Root>
<Field.Root required>
<Field.Label>{texts.city}</Field.Label>
<AddressInput.City name="city" />
</Field.Root>
</AddressInput.Root>
</Fieldset.Root>
<Button type="submit" className="kv-button--primary">
{texts.reportChange}
</Button>
</form>
<output>{isReported ? texts.changeReported : null}</output>
</Stack>
)
}Props in this example:
geocoderon AddressInput.Rootcountryon AddressInput.RootprivacyNoticeon AddressInput.Line1valueon AddressInput.CountryonChangeon AddressInput.Country
Information: Did you know?
Ask for the country first, and preselect your service’s own country. If the country changes after a postal code is typed, the code is kept as typed: check it when the form is sent.
Warning: Don't forget
These examples turn off the notice and the credit: see Report a change of address with address autocomplete for what to add instead.
The service can’t find the address
Every box is filled in, but the address is not found. This is one error about the whole address: it goes on the Fieldset, and the summary links to the first box. A choice from the suggestions is not a check either: validate the address in the same way.
import { AddressInput, Button, ErrorSummary, Field, Fieldset, Stack } from '@kvirn-ui/react'
import { useId, useState } from 'react'
import { useAddressInputTexts } from './texts.ts'
export function AddressNotFound() {
const { texts } = useAddressInputTexts()
const streetId = `${useId()}-street`
const [isNotFound, setIsNotFound] = useState(false)
const [submitCount, setSubmitCount] = useState(0)
return (
<Stack className="kv-stack--gap-8">
{isNotFound ? (
<ErrorSummary.Root focusKey={submitCount}>
<ErrorSummary.Title />
<ErrorSummary.List>
<ErrorSummary.Item>
{/* The error is about the whole address, so the link goes to the first box. */}
<ErrorSummary.Link controlId={streetId}>{texts.errorNotFound}</ErrorSummary.Link>
</ErrorSummary.Item>
</ErrorSummary.List>
</ErrorSummary.Root>
) : null}
<form
noValidate
onChange={() => setIsNotFound(false)}
onSubmit={(event) => {
event.preventDefault()
// A real service asks its own back end here. This one never finds the address.
setIsNotFound(true)
setSubmitCount((count) => count + 1)
}}
>
<Fieldset.Root invalid={isNotFound}>
<Fieldset.Legend>{texts.legend}</Fieldset.Legend>
<AddressInput.Root country="SE">
<Field.Root controlId={streetId} required>
<Field.Label>{texts.street}</Field.Label>
<AddressInput.Line1 name="line1" defaultValue={texts.streetValue} />
</Field.Root>
<Field.Root>
<Field.Label>{texts.line2}</Field.Label>
<AddressInput.Line2 name="line2" />
<Field.HelpText>{texts.line2Help}</Field.HelpText>
</Field.Root>
<Field.Root required>
<Field.Label>{texts.postalCode}</Field.Label>
<AddressInput.PostalCode name="postalCode" defaultValue={texts.postalCodeValue} />
<Field.HelpText>{texts.postalCodeHelp}</Field.HelpText>
</Field.Root>
<Field.Root required>
<Field.Label>{texts.city}</Field.Label>
<AddressInput.City name="city" defaultValue={texts.cityValue} />
</Field.Root>
</AddressInput.Root>
<Fieldset.ErrorMessage>{texts.errorNotFound}</Fieldset.ErrorMessage>
</Fieldset.Root>
<Button type="submit" className="kv-button--primary">
{texts.check}
</Button>
</form>
</Stack>
)
}An address the service already holds
Show the address with a link to change it, not in read-only boxes.
import { DefinitionList } from '@kvirn-ui/react'
import { useAddressInputTexts } from './texts.ts'
export function KnownAddress() {
const { texts } = useAddressInputTexts()
return (
<DefinitionList.Root>
<DefinitionList.Row>
<DefinitionList.Term>{texts.addressTerm}</DefinitionList.Term>
<DefinitionList.Description>{texts.addressValue}</DefinitionList.Description>
<DefinitionList.Actions>
<DefinitionList.Change href="#change-address" />
</DefinitionList.Actions>
</DefinitionList.Row>
</DefinitionList.Root>
)
}Warning: Don't forget
Don’t make people enter again what they gave earlier in the same process (3.3.7 Redundant Entry, Level A).
Accessibility#
What it does for you#
- APG pattern: none for the address as a whole;
Line1with ageocoderis the APG Combobox (editable, list autocomplete), as AddressSearch. There is no APG pattern for an address. An address is four labelled text inputs inside a<fieldset>with a<legend>, which is what the GOV.UK addresses pattern and the Nordic public-sector design systems do, and what autofill, dictation and every screen reader handle well. - Deviations: one, approved by the maintainer on 2026-10-22. In
AddressInput.Line1with ageocoder, Enter with no suggestion active searches and never submits the form, as in AddressSearch. One accessibility trade-off, approved the same day: Line1 keepsautocomplete="address-line1"and itsnamewhile it is a combobox, so autofill and 1.3.5 Identify Input Purpose (AA) stay, and a browser may show its own autofill list beside ours. Decisions: a plainFieldset(notgroup), so each Field marks itself and Line 2 shows "(optional)"; one Field per line, so help texts and errors are per line; no auto-advance (3.2.2 On Input, A); the lookup is opt-in (ageocoderon the Root) and only a helper, so Line1 stays free text;AddressInput.Countryis optional and first; without it the lookup offers only the Root's country, since the form can't record another. The boxes hold no text; the lookup's strings areaddressInput.*, plus theaddressSearch.*ones it reuses. - Native elements used:
<fieldset>and<legend>(the consumer'sFieldset.RootandFieldset.Legend),<div>(AddressInput.Root, and each Field),<label for>(the Field's label),<input type="text">(each box),<select>(Country),<input role="combobox">and<button type="button">(Line1with a geocoder).
An address is one question ("Your address") answered with up to four boxes: street, line 2, postal code and city. AddressInput.Root is the layout and goes inside a plain Fieldset.Root, whose legend names the group. Each part is a TextInput inside the consumer's own Field.Root with a Field.Label, so a line has its own label, help text and error. With a geocoder on the Root, Line1 is the ARIA 1.2 combobox of AddressSearch (in @kvirn-ui/map) instead, in the same Field, with a privacy notice above it, a Search button on request, the popup, help text and a note after a pick. Country, a native select in the consumer's own Field, is optional and first.
| Part | Element / role | ARIA / state | Notes |
|---|---|---|---|
The group (Fieldset.Root) | <fieldset> → group | Named by its <legend>. A whole-address error is the fieldset's Fieldset.ErrorMessage (the Fieldset component) | |
| AddressInput.Root | <div>, no role | none | |
| Line1, Line2, PostalCode, City | <input type="text"> → textbox | Named by the Field's visible label ("(optional)" included). aria-invalid, aria-required and aria-describedby come from the Field. autocomplete is the part's token | |
| Country | <select> → combobox (native) | Named by the consumer's Field label. autocomplete="country" (with the Root's prefix or off). Options named with Intl.DisplayNames in the page's language, the Root's country first. Value: the ISO code | |
| Line1 with a geocoder | <input> → combobox, a listbox | aria-autocomplete="list", aria-expanded, aria-controls, aria-activedescendant, autocomplete="address-line1", its name, spellcheck="false". Named by the Field's label. Described, in this order, by the privacy notice (above it; the default, and left out with privacyNotice={false}), the lookup's help text (with the country searched), the fill note after a pick, the consumer's help text, then the error. The role is fixed while mounted: without a geocoder it is a textbox | |
| Line1's Search, Clear | <button type="button"> | Search: its text, shown only when the search is on request. Clear: combobox.clear, empties Line1 only, no tab stop | |
| Line1's fill note | <p class="kv-field-help-text"> | Plain text after a pick, in Line1's description: not a live region. The Announcer says the same words | |
useAddressInput | the logic, for your own elements | returns country, postalCodeMask, rootProps, getInputProps(part) |
Rules, each proved by a test:
- Autocomplete tokens (1.3.5 Identify Input Purpose, AA). An autocomplete token tells the browser what a box is for, so it can fill it in. Line1
address-line1, Line2address-line2, PostalCodepostal-code, Cityaddress-level2. A RootautoCompleteofoffturns every part off, any other value (section-postal,shipping) goes before each token, and a part's ownautoCompletewins (address-input.test.tsx › each part gets its token, a Root prefix or off, and a part’s own wins). - Text lines are not corrected. Line1, Line2 and City have
spellcheck="false"andautocorrect="off": street names are not words (same test). - The postal code follows the Root's country. SE
123 45, FI00100and NO1234through the existingpostal-codemask, withinputmode="numeric"anddir="ltr". Any other country: no mask,inputmode="text",autocapitalize="characters",dir="ltr", so a foreign code is never refused. The default country is the provider's, then the locale's (address-input.test.tsx › follows the Root’s country: SE groups the digits, DE keeps letters with no mask,› without a country on the Root, the provider’s country is used). - Nothing is rewritten and focus never moves on its own. A full postal code keeps focus in the box, and changing
countryleaves a typed value as it is; the mask applies to the next edit (address-input.test.tsx › a full postal code never moves focus, and changing country never rewrites the value). - Paste is never blocked. No box cancels a paste, and a pasted postal code takes the country's mask (
address-input.test.tsx › paste is never cancelled in any box, and a pasted postal code takes the country’s mask). - Development warnings (shown in the browser console while you build): a Root outside any group; a Root in a
groupFieldset; a part outside a Root (address-input.test.tsx › warns outside a fieldset, in a group fieldset, and for a part outside a Root); aCountrywith no accessible name, not the first control of its Root, or outside a Root (› a Country without a name, not first and outside a Root warns). - The lookup is opt-in and Line1 stays free text. Without a
geocoderon the Root Line1 is a plaintextbox, exactly as before (address-input.test.tsx › without a geocoder Line1 is today’s plain textbox, with no combobox and no lookup text). With one, Line1 is a combobox that keeps its label,nameandautocomplete="address-line1"(› with a geocoder Line1 is the ARIA 1.2 combobox named by the Field label, keeping its token and name, described by the notice, the help text and the consumer’s help) and is submitted with the form as the street (› is submitted with the form as the street, with the other boxes). - The privacy notice is read before typing. It sits above Line1, so a popup never covers it, and is first in Line1's description, then the lookup help (
› the privacy notice is above Line1 and first in its description, then the help text). This differs from AddressSearch, which keeps its notice below. WithprivacyNotice={false}there is no notice and the description starts with the lookup help: the consumer must say where the text goes in the Field's help text, so it is still in the description (› privacyNotice false renders no notice, and the consumer’s help text still describes Line1). A maintainer-approved accessibility trade-off. - Nothing is sent before the visitor types in Line1, and neither autofill nor our own fill searches. Typing in Line 2, the postal code or the city never searches (
› typing in Line 2, the postal code or the city never searches). Aninputevent without a typinginputType(browser autofill, the form fill) sets the text, opens no list, searches nothing and announces nothing (› browser autofill of all the boxes, Line 1 included, searches nothing, opens no list and announces nothing). - A pick fills, and says so. It writes the result's
address.line1(never its label) into Line1 and fills the postal code and the city, as typing does (a controlledvalue, the DOM value, a form library'sinputlistener:› the fill reaches a controlled value, the DOM value of an uncontrolled box and a form’s input listener as typing does;› a pick writes address.line1 into Line 1, never the result’s label, and typing on searches again for house-level matches), never Line 2 (› a pick fills Line 1, the postal code and the city, never Line 2, keeps focus in the lookup and shows the note). Focus stays in Line1 with the caret at the end, so a missing house number is typed straight after, and typing on searches again. A pick replaces what was typed in those three boxes (› a pick replaces what the visitor typed in the three boxes). A box the result has no value for keeps a value the visitor typed and is emptied if an earlier pick left its value (› a result without a postal code keeps a typed one, and empties one an earlier pick left;› a result without a city adds the missing town to the note and empties the earlier pick’s city). A street without a house number is filled the same way and the note asks for the number (› a street without a house number is filled and the note asks for the number). A place with no postal address fills nothing, is shown and announced, the typed text is restored and the list stays open (› a place with no postal address fills nothing, says so in the list, announces it and keeps the list open).onLookupResultgets the whole result (› onLookupResult gets the whole result of each pick). - Narrowing and the house-number lookup only help. Line1's searches send
postalCodeandcityonce those boxes hold a value, and nothing when they are empty; filling them starts no search (› the postal code and city are sent with a search once their boxes have values;› empty postal code and city boxes send neither, and filling them starts no search). After astreetpick, a house number typed after the street calls the geocoder'sstructuredlookup; an exact answer fills the postal code and the city and keeps Line1 as typed, a keystroke cancels a pending lookup, and no answer, a street-level answer, an error or a geocoder withoutstructuredchanges nothing and announces no error (› typing a house number after a street pick looks it up with the parts and fills the postal code and city;› an address not found leaves every box as it was and announces no error;› a failing lookup changes nothing and announces no error;› a street-level answer fills nothing;› a geocoder without a structured lookup does nothing after a number is typed;› a keystroke aborts a pending lookup and only the last text is looked up). - The fill note is plain text. "Filled in from the address search. Check the address." follows a pick, with the sentences for a missing house number, postal code or town and a changed country. It names no address, so an edit never makes it stale, it is in Line1's description and never a live region. After a pick an edit says nothing on request, and as you type only the new search's count is said (
› the fill note is in Line 1’s description after the help text;› the note is plain text, not a live region, and an edit after the pick neither re-searches nor announces). - Which country the lookup searches. Without a
Countrypart the lookup asks for, and keeps, only addresses in the Root's country (country, else the provider's), and the help text names it (› without a Country part only the Root’s country is offered, the count says what is left and the geocoder is asked for it;› without a Country part the Root’s country prop sets the country searched and named). With one, every country is listed, the selected one first, and the geocoder is asked for the selected one (› with a Country part every country is listed and the geocoder is asked for the selected one, which follows the select). A pick in another country sets the select first, with achangeevent as a visitor's, so the postal code's mask follows, then writes the boxes (› a pick in another country switches the select first, the mask follows, the boxes are written, and the note and announcement say so).Countryis a native select with the Root's country first, named in the page's language, andvalue/defaultValue/onChangeas any select (› is a native select named by its Field label, autocomplete country, the Root’s country first and named in the page’s language;› names the countries in the provider’s language and takes the Root’s autocomplete prefix;› the Root’s country is the starting value, and the select follows value and defaultValue). - Strings. The lookup's text is
addressInput.*and theaddressSearch.*keys it reuses (submit,privacy,privacyUnnamed,tooShort,searching,resultCount,pickedFilled), each overridable per instance and per provider (› every string comes from the catalog: the Swedish one translates the help, scope, notice and Search;› a per-instance message replaces the catalog text, for Line 1’s own keys and the reused ones). The boxes andCountryhold no text and Line1's label is the consumer's; country names come fromIntl.DisplayNames. The mask's polite "character not allowed" messages are TextInput's (from TextInput). - No axe violations in every state of the test file and in every story state, in every theme (
address-input.test.tsx › has no violations idle, with results open, rejected, filled with the note, and with a Country part;› has no violations on a status line: too short, error and offline).
What you need to do#
- A plain
Fieldset.Rootwith aFieldset.Legendthat names the address; notgroup. - One
Field.Rootper box with aField.Label,requiredon the ones that are, and aField.HelpTextwith an example for the postal code in the country's form (3.3.2 Labels or Instructions, A). - Per-part errors in
Field.ErrorMessagewithinvalidon that Field, a whole-address error inFieldset.ErrorMessage, and anErrorSummarylink per invalid part (the Field'scontrolId; the whole-address error links to Line1). countryon the Root when the address is not in the provider's country. A country control isAddressInput.Country, first in the Root, in its own Field with aField.Label("Country") and aname; add it when the service takes addresses outside the Root's country.- A lookup only with a
geocoderthe service has chosen, named in its own privacy notice (GDPR: what is typed and the visitor's IP address reach it). The notice above Line1 says where the text goes. WithprivacyNotice={false}you say where the text goes in Line1'sField.HelpText, and withattribution: nullonkvirnGeocoderyou credit the data on the page. autoComplete="off"for someone else's address, andsection-*when a page has two.- An address the user gave earlier in the same process is carried forward: filled into the boxes (
defaultValue) or shown as a summary with a change link (3.3.7 Redundant Entry, A). Prefer the summary to read-only boxes, which look editable. - Validation: the lookup never marks a box invalid, and a pick is not a check. Validate the boxes as you do without it.
Warning: Don't forget
Give the Fieldset a legend and every box a visible label. Without the legend, “Postal code” and “City” have no shared question (1.3.1 Info and Relationships, 3.3.2 Labels or Instructions, both Level A).
Visual and modes#
- Focus indicator: the TextInput's, the select's and the combobox's own, a visible outline with an offset.
- Target size: each box, the select and the lookup are as tall as a TextInput. Search and Clear are at least 24px (2.5.8 Target Size (Minimum), AA), also in compact density.
- Layout: the boxes stack. When the address has room (about 22rem wide), the postal code and the city share a row. The Country field is as wide as its content. At 320px and at 400% zoom the boxes stack, the lookup's help text, notice and note wrap and Search wraps below the input (1.4.10 Reflow, AA; 1.4.12 Text Spacing, AA).
- The fill note has a leading check icon in the text colour, decorative; the words carry the meaning (1.4.1 Use of Color).
- Forced colours mode (the user's own system colours): each box uses the TextInput's system colours. An invalid box keeps its heavy edge, and the error text still names the problem. The status and note icons take the text colour; Search uses the system's button colours; the active suggestion uses the system's highlight colours.
- Reduced motion: the only motion is the lookup's spinner, and only under no-preference.
- Right-to-left languages: the postal code and city row mirrors; Clear then Search sit at the inline end. The postal code box is always read left to right (
dir="ltr"). The check icon is not mirrored.
Focus management#
- Initial focus: none set by AddressInput.
- A search, a result, an error, an offline answer, a pick or a Country change never moves focus (3.2.2): it stays in Line1 (or the select). A pick writes the boxes without focusing them.
- Trap: no.
- Restore to: n/a.
- Not hidden by your page: if your site has a sticky header, keep
scroll-paddingso a focused box and the error under it stay visible (2.4.11 Focus Not Obscured (Minimum), AA).
Warning: Don't forget
If your site has a sticky header, add scroll-padding so a focused box and the error under it are not hidden behind the header (2.4.11 Focus Not Obscured (Minimum), Level AA).
WCAG success criteria#
- 1.3.1 Info and Relationships (A), 4.1.2 Name, Role, Value (A): a fieldset with a legend, a visible label for each box, the select and the lookup; the lookup is a combobox with a listbox.
- 1.3.5 Identify Input Purpose (AA): the four autocomplete tokens, and
countryon the select. - 1.4.1 Use of Color (A): the note and the status lines are words with an icon.
- 1.4.10 Reflow (AA), 1.4.12 Text Spacing (AA): the row wraps; nothing is fixed in height.
- 2.1.1 Keyboard (A), 2.4.3 Focus Order (A): one Tab stop per control, in the order of the page's code, Country first; the lookup is operable by keys alone.
- 2.4.6 Headings and Labels (AA), 2.5.3 Label in Name (A), 2.5.8 Target Size (Minimum) (AA).
- 3.2.2 On Input (A): no auto-advance, and a pick or a country change never moves focus.
- 3.3.1 Error Identification (A), 3.3.2 Labels or Instructions (A), 3.3.3 Error Suggestion (AA): an error for each box with what to do, labels and an example; the lookup's help text and the "or type it in the boxes" way out.
- 3.3.7 Redundant Entry (A): the consumer's (Consumer responsibilities). Every box and Country take
defaultValue/value, so an address given earlier in the process can be carried forward. - 4.1.3 Status Messages (AA): the lookup's searching, count, no result, error, offline and pick messages through the Announcer.
Keyboard#
- Focus
- native. The boxes and
Countryare native controls, and DOM focus stays on Line1 while its active suggestion isaria-activedescendant - Selection follows focus
- n/a
- Arrows wrap
- no (the list stops at its ends)
- Shortcuts
- none
The boxes are native: AddressInput handles no key in them, never calls preventDefault on one and never moves focus when a box is full. Country is a native select: the platform's keys. With a geocoder Line1 is the combobox of AddressSearch with one approved deviation: Enter with no suggestion active searches and never submits the form. The parts are in the order you write them in your code: Country, Line1 (then Search on request), Line2, PostalCode, City.
| Key | Where | What happens |
|---|---|---|
| Tab | before the address, or on a stop | Moves focus to the next stop: Country, Line1, Search (on request only), Line2, PostalCode, City. Clear is no stop. From the last it leaves the address Test: address-input.test.tsx › Tab and Shift+Tab go Country, Line1, Search, Line2, PostalCode, City, and Clear is no stop |
| Shift+Tab | on a stop | Moves focus to the previous stop. From the first it leaves the address Test: address-input.test.tsx › Tab and Shift+Tab go Country, Line1, Search, Line2, PostalCode, City, and Clear is no stop |
| Tab | in a disabled Fieldset | Line1 and its Search button are skipped Test: address-input.test.tsx › disabled, Line 1 and its Search button are skipped by Tab |
| Characters | on the postal code | Types them, shaped by the country's mask. A full code keeps focus: nothing advances Test: address-input.test.tsx › a full postal code never moves focus, and changing country never rewrites the value |
| Characters | on Line1 with a geocoder | Free text. With a geocoder that suggests as you type, searches after the pause, from minLength characters; a pick followed by more typing searches againTest: address-input.test.tsx › a pick writes address.line1 into Line 1, never the result’s label, and typing on searches again for house-level matches |
| ArrowLeft / ArrowRight / Home / End | on a box without a geocoder | Move the caret (the text cursor) inside the box. In right-to-left text the browser flips them. They never move focus Test: text-input.test.tsx › ArrowLeft, ArrowRight, Home and End move the caret and are not intercepted |
| ArrowLeft / ArrowRight / Home / End, Space | on Line1 with a geocoder | Move the caret and type a space: the combobox leaves them to the input and keeps no suggestion active Test: autocomplete.test.tsx › Home, End, ArrowLeft, ArrowRight and Space are left to the input: the caret moves, and no suggestion stays active |
| Enter | on a box, in a form | Submits the form (native). AddressInput does not intercept it. Typing in a box never searches Test: address-input.test.tsx › keys in a box are native: Enter submits the form and typing never searches |
| Escape | on a box | Does nothing: the value and the focus stay Test: text-input.test.tsx › Escape does nothing: the value and the focus stay |
| ArrowUp / ArrowDown, letters, Alt+ArrowDown, Space, Escape | on Country | Native select: change the option, jump by name, open and close the platform's list (platform behaviour, never intercepted). The postal code's mask and the searched country follow; nothing is announced Test: address-input.test.tsx › ArrowDown and letters change the option natively, announce nothing, and set the postal code’s mask |
| Enter | on Line1, no suggestion active, in a form | Searches now and never submits the form (approved deviation, 2026-10-22) Test: address-input.test.tsx › Enter with no suggestion active, inside a form, searches now and the form does not submit |
| Enter | on Line1, text unchanged since the answer | Reopens the last list without a new request and says the count again Test: address-input.test.tsx › Enter on text unchanged since the answer reopens the last list without a new request and says the count again |
| Enter / Space | on Search | Searches. The button is a native type="button": it never submits the formTest: address-input.test.tsx › Search is a native type=button that searches on Enter and on Space and never submits the form |
| ArrowDown / ArrowUp | on Line1, list open | Moves the active suggestion; stops at the ends Test: autocomplete.test.tsx › arrows move the active suggestion and stop at the ends, and typing clears it |
| ArrowDown / ArrowUp | on Line1, list closed | Opens the last list with the first (ArrowDown) or last (ArrowUp) suggestion active, without a new request Test: autocomplete.test.tsx › ArrowDown on the closed input opens it with every suggestion and activates the first; autocomplete.test.tsx › ArrowUp on the closed input activates the last suggestion |
| Alt+ArrowDown | on Line1 | Opens the list without activating a suggestion Test: autocomplete.test.tsx › Alt+ArrowDown opens without activating, and Alt+ArrowUp picks the active suggestion |
| PageDown / PageUp | on Line1, list open | Ten on or back Test: autocomplete.test.tsx › PageDown and PageUp move ten suggestions and stop at the ends |
| Enter, Alt+ArrowUp | on Line1, a suggestion active | Picks: Line1 becomes the result's street, the postal code and the city are filled, focus stays in Line1 with the caret at the end Test: address-input.test.tsx › Enter and Alt+ArrowUp on an active suggestion pick it: Line 1 becomes the street, focus stays, the boxes are filled |
| Escape | on Line1, list open | Closes the list. The text, the focus and the boxes stay Test: address-input.test.tsx › Escape closes the list and keeps the text, the focus and the boxes |
| Escape | on Line1, list closed | Does nothing: the text, the focus and the boxes stay Test: autocomplete.test.tsx › Escape does nothing when the popup is closed |
| Tab | on Line1, list open | Closes the list without picking and moves to the next stop Test: address-input.test.tsx › Tab with the list open closes it without picking and moves to the next stop |
| Shift+Tab | on Line1, list open | Closes the list without picking and moves to the previous stop Test: autocomplete.test.tsx › Shift+Tab closes the popup without picking and moves focus back |
| ArrowLeft / ArrowRight | on Line1, right-to-left text | Only move the caret; ArrowDown and ArrowUp still mean next and previous suggestion Test: autocomplete.test.tsx › right to left: ArrowDown and ArrowUp still mean next and previous suggestion, and ArrowLeft and ArrowRight only move the caret |
| Pointer press | on a suggestion, or Clear | Picks the suggestion / empties Line1 only (the other boxes keep their values), and focus stays in Line1 Test: address-input.test.tsx › a pointer press on a suggestion picks it, and Clear empties Line 1 only |
Information: Did you know?
With a geocoder, Enter in the street box searches and does not send the form. In the other boxes Enter sends it as usual. Keep a visible submit button, so the form can always be sent with the keyboard.
Announcements#
AddressInput tells screen reader users about these changes without moving focus. Each message waits until the screen reader is quiet (polite) or interrupts it (assertive).
| When | What it says | Message key | Politeness |
|---|---|---|---|
| The mask drops a character | Only digits can be entered here. | mask.characterNotAllowed mask.maximumLength | Polite |
| Too short (on request) | Type at least 3 characters to search. | addressSearch.tooShort | Polite |
| Request on its way (dropped if fast) | Searching for addresses | addressSearch.searching | Polite |
| n results | 2 addresses found | addressSearch.resultCount | Polite |
| No results | No address found for “Storgatn”. Keep typing: your address doesn’t have to be in the list. | addressInput.lookupNoResults | Polite |
| Error, timeout | The address search isn’t working right now. Keep typing your address. | addressInput.lookupError | Polite |
| Offline | You’re offline. Keep typing your address. | addressInput.lookupOffline | Polite |
| Pick of a place with no address | This place has no postal address. Choose another, or keep typing your address. | addressInput.noAddressDetails | Polite |
| Pick that fills | Chosen: Storgatan 12, 123 45 Kvirnby. The address is filled in below. Check it before you continue. | addressSearch.pickedFilled addressInput.countryChanged missingPostalCode missingCity missingHouseNumber | Polite |
| House number looked up after a street pick | Postal code and town filled in from the address search. Check the address. | addressInput.filledPostalCodeAndCity filledPostalCode filledCity | Polite |
The text in all five languages
Change the text#
For your whole app, pass messages to KvirnProvider. For one AddressInput, pass its messages prop.
<KvirnProvider messages={{ mask: { characterNotAllowed: 'Only digits can be entered here.' } }}>Warning: Don't forget
Announcements need a KvirnProvider around your app, outside any <form>, or an Announcer of your own. Without one nothing is announced, and a development warning says so.
What a screen reader reads#
| State or action | Read aloud | Politeness | Test |
|---|---|---|---|
| Focus on Line1 | By default the notice first (What you type is sent to <service> to find the address.), then combobox, Street address (optional), <notice> <help text> Suggests addresses in Sweden., has popup listbox, not expanded, autocomplete in list, 1 control, then button, Search | none | address-input.test.tsx › AddressInput.Line1 lookup read aloud › focus: the field is read after the privacy notice, with its label, help text and state |
Focus on Line1 with privacyNotice={false} | combobox, Street address, <lookup help> Suggests addresses in Sweden. <consumer help>, has popup listbox, not expanded, autocomplete in list | none | proved by the description-order test, address-input.test.tsx › AddressInput.Line1 lookup structure › privacyNotice false renders no notice, and the consumer’s help text still describes Line1 |
| Results | polite: 2 addresses found, then option, <address label>, not selected, position 1, set size 2 and the next | polite | address-input.test.tsx › AddressInput.Line1 lookup read aloud › results: the count is said, then the list is read as options |
| Pick | polite: Chosen: <address label>. The address is filled in below. Check it before you continue. | polite | address-input.test.tsx › AddressInput.Line1 lookup read aloud › a pick says the address is filled in and to check it |
| Pick of a street without a number | the pick message, then Type your house number after the street name. | polite | address-input.test.tsx › AddressInput.Line1 lookup read aloud › a pick of a street without a number also asks for the house number |
| House number typed after a street pick | polite: Postal code filled in from the address search. Check the address. (or the town, or both): the only message, also with a geocoder that suggests as you type | polite | address-input.test.tsx › AddressInput.Line1 lookup read aloud › typing the house number says one message, naming what was filled |
| Pick of a place with no postal address | polite: This place has no postal address. Choose another, or keep typing your address. | polite | address-input.test.tsx › AddressInput.Line1 lookup read aloud › a place with no postal address says so and asks for another |
| Pick in another country | the pick message, then The country is now Finland. | polite | address-input.test.tsx › AddressInput.Line1 lookup read aloud › a pick in another country adds the new country to the message |
| Browser autofill | nothing | none | address-input.test.tsx › AddressInput.Line1 lookup read aloud › browser autofill says nothing |
| Clear | nothing | none | address-input.test.tsx › AddressInput.Line1 lookup read aloud › Clear says nothing |
API reference#
import { AddressInput, useAddressInput } from '@kvirn-ui/react'
import { kvirnGeocoder } from '@kvirn-ui/map/kvirn' // only for the address lookupAddressInput.Root
Renders <div> with no role. It holds the boxes, the country they share and the address lookup. Put it in a plain Fieldset (not a group one) whose legend names the address. It takes every attribute of a <div> and passes ref to it. Also exported as AddressInputRoot. The default theme is described on Theming.
| Prop | Type | Default | Description |
|---|---|---|---|
country | string | – | The address’s country as an ISO 3166-1 alpha-2 code, such as SE. It picks the postal code’s mask, width and keypad: SE, FI and NO have a mask, and any other country has none. Without it: the provider’s country, then the country the page’s language implies (Swedish SE, Finnish FI, Norwegian NO). English implies none. It is the address’s country, not the page’s, and changing it never rewrites what was typed. With an AddressInput.Country it is the country listed first and the starting country. Without one, the lookup offers only addresses in this country. |
autoComplete | string | – | "off" turns autofill off for every box (someone else’s address). Anything else, such as "section-postal" or "shipping", goes before each box’s purpose, so two addresses on one page stay apart. A box’s own autoComplete wins. |
geocoder | GeocoderProvider | – | Turns the address lookup on: AddressInput.Line1 becomes a combobox that suggests addresses and stays free text. What is typed in Line1, and the visitor’s IP address, reach this geocoder, and nothing is sent before minLength characters. Geocoders come from @kvirn-ui/map (kvirnGeocoder, nominatim, googlePlaces). Without it, Line1 is a plain text box and AddressInput makes no network call. |
onLookupResult | (result: AddressResult) => void | – | Called after a choice that filled in the boxes, with the whole result, for its position or id. Not called when the text is cleared, or for a place with no postal address. |
ref | Ref<HTMLDivElement> | – | Reaches the <div>. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-address-input | always | The layout class: the boxes stacked, with the postal code and the city side by side when there is room. |
AddressInput.Country
Renders A native <select> (role combobox) of every country, named in the language of the page, with the Root’s country first. Put it first in the Root, in its own Field with a visible Field.Label and a name. It sets the shape of the postal code and the country the lookup searches in. A suggestion in another country sets it too. It never changes what the user typed. It takes every attribute of a <select> except children and passes ref to it. Also exported as AddressInputCountry.
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | – | Controlled: the country as an ISO 3166-1 alpha-2 code from your form state, such as SE. Pass it with onChange. |
defaultValue | string | the Root’s country | Uncontrolled: the starting country. Without it: the Root’s country, then the provider’s. |
onChange | (event: ChangeEvent<HTMLSelectElement>) => void | – | Called when the country changes, by the user or by a choice in another country. event.currentTarget.value is the code. |
ref | Ref<HTMLSelectElement> | – | Reaches the <select>. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-listbox-native, kv-address-input-country | always | The part classes. The Country field is as wide as its content. |
autocomplete | "country", or "off" | The autofill purpose (1.3.5 Identify Input Purpose), after the Root’s prefix. |
AddressInput.Line1
Renders The street address. Also exported as AddressInputLine1. An <input type="text"> (a TextInput) with the role textbox. Put it in its own Field with a visible Field.Label: the label, help text and error are wired to it. It takes the props of a TextInput and passes ref to it. You cannot set type. The street, line 2 and city boxes also take no mask or announceRejections. Only the street box takes messages, to change the texts of the lookup. With a geocoder on the Root it is an <input> with the role combobox instead, and it stays free text. By default it comes with a privacy notice above it, a Clear button, a Search button when the search runs on request, the list of suggestions, a help text and, after a choice, a note. It keeps your Field.Label, its name and its autofill purpose.
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | – | Controlled: the value from your form state. Pass it with onValueChange. |
defaultValue | string | – | Uncontrolled: the native input keeps the value, and a form submit sends it. |
onValueChange | (value: string, details: TextInputChangeDetails) => void | – | Reports each change. onChange still works. |
autoComplete | string | the box’s purpose | The autofill purpose, with the Root’s prefix in front. Yours wins, so "off" turns autofill off for one box. |
ref | Ref<HTMLInputElement> | – | Reaches the <input>. |
messages | AddressInputLine1Messages | – | With a geocoder: replaces the lookup’s texts for this box. The keys are those of addressInput, and submit, privacy, privacyUnnamed, tooShort, searching, resultCount and pickedFilled from addressSearch. |
minLength | number | 3 | With a geocoder: the fewest characters, trimmed, before a search is sent. Nothing is sent below it. |
debounce | number | false | 400 | With a geocoder that suggests as you type: the milliseconds of no typing before a search. false: search only when the user presses Enter or Search. A geocoder that does not allow search as you type is always searched on request. |
privacyNotice | boolean | true | Shows where the typed text goes above the street box. Turn it off only if you say it in the street box’s help text. |
timeoutMilliseconds | number | 10000 | With a geocoder: how long to wait for an answer. After that it counts as an error. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-input, kv-address-input-line1 | always | The part classes. |
autocomplete | "address-line1", or "off" | The autofill purpose (1.3.5 Identify Input Purpose), after the Root’s prefix. |
spellcheck, autocorrect | "false", "off" | A street or a town is not a word to correct. |
id, aria-describedby | in a Field | From the Field. aria-describedby lists the help text, then the error, and your own ids after them. |
aria-invalid, aria-required | "true" or absent | In a Field with invalid or required. |
data-invalid, data-required, data-disabled | present or absent | The state of the Field. |
role, aria-autocomplete, aria-expanded, aria-controls, aria-activedescendant | with a geocoder | The ARIA 1.2 combobox: role combobox and aria-autocomplete "list". aria-expanded is true while the list is open. The role is fixed while mounted: without a geocoder it is a textbox. |
aria-describedby | with a geocoder | Lists, in this order: the privacy notice above the box (unless privacyNotice is false), the lookup’s help text (with the country searched), the note after a choice, your help text, then the error. |
kv-address-lookup-notice, kv-address-lookup-status, kv-address-lookup-submit, kv-address-input-lookup-note | with a geocoder | The classes of the privacy notice, the status line in the list, the Search button and the note after a choice. |
AddressInput.Line2
Renders The second line, such as c/o and a name. Most services make it optional. Also exported as AddressInputLine2. An <input type="text"> (a TextInput) with the role textbox. Put it in its own Field with a visible Field.Label: the label, help text and error are wired to it. It takes the props of a TextInput and passes ref to it. You cannot set type. The street, line 2 and city boxes also take no mask or announceRejections. Only the street box takes messages, to change the texts of the lookup.
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | – | Controlled: the value from your form state. Pass it with onValueChange. |
defaultValue | string | – | Uncontrolled: the native input keeps the value, and a form submit sends it. |
onValueChange | (value: string, details: TextInputChangeDetails) => void | – | Reports each change. onChange still works. |
autoComplete | string | the box’s purpose | The autofill purpose, with the Root’s prefix in front. Yours wins, so "off" turns autofill off for one box. |
ref | Ref<HTMLInputElement> | – | Reaches the <input>. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-input, kv-address-input-line2 | always | The part classes. |
autocomplete | "address-line2", or "off" | The autofill purpose (1.3.5 Identify Input Purpose), after the Root’s prefix. |
spellcheck, autocorrect | "false", "off" | A street or a town is not a word to correct. |
id, aria-describedby | in a Field | From the Field. aria-describedby lists the help text, then the error, and your own ids after them. |
aria-invalid, aria-required | "true" or absent | In a Field with invalid or required. |
data-invalid, data-required, data-disabled | present or absent | The state of the Field. |
AddressInput.PostalCode
Renders The postal code. It follows the country: the Root’s, or the one in AddressInput.Country when there is one. SE, FI and NO get a mask, a number keypad and a box as wide as the code. Any other country gets no mask: the box takes what is typed, asks phone keyboards for capital letters and is ten characters wide. Also exported as AddressInputPostalCode. An <input type="text"> (a TextInput) with the role textbox. Put it in its own Field with a visible Field.Label: the label, help text and error are wired to it. It takes the props of a TextInput and passes ref to it. You cannot set type. The street, line 2 and city boxes also take no mask or announceRejections. Only the street box takes messages, to change the texts of the lookup.
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | – | Controlled: the value from your form state. Pass it with onValueChange. |
defaultValue | string | – | Uncontrolled: the native input keeps the value, and a form submit sends it. |
onValueChange | (value: string, details: TextInputChangeDetails) => void | – | Reports each change. details has reason and event, and with a mask also unmaskedValue, isComplete, isWithinRange and rejected. onChange still works. |
mask | MaskInput | false | the country’s postal code mask | Replaces the country’s mask. false: no mask, the box takes what is typed. Your own mask’s keypad and direction win over the country’s. |
announceRejections | boolean | true | With a mask: announces politely, at most once every few seconds, when it drops characters. Needs a KvirnProvider. |
messages | Partial<KvirnMessages['mask']> | – | With a mask: per-instance overrides for the rejection announcements. |
autoComplete | string | "postal-code" | The autofill purpose, with the Root’s prefix in front. Yours wins. |
ref | Ref<HTMLInputElement> | – | Reaches the <input>. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-input, kv-address-input-postal-code | always | The part classes. |
kv-input--numeric, kv-input--width-6, -4 or -10 | SE and FI: numeric and 6; NO: numeric and 4; any other country: 10 | Tabular figures, and a box as wide as the longest postal code the country writes. |
inputmode, autocapitalize | "numeric" with a mask; "text" and "characters" without | The digit keypad for a masked code. For a country with no mask, a keyboard that starts in capital letters. The text is kept as typed. |
dir | "ltr" | A postal code is read left to right in every direction. |
autocomplete | "postal-code", or "off" | The autofill purpose (1.3.5 Identify Input Purpose), after the Root’s prefix. |
id, aria-describedby | in a Field | From the Field. aria-describedby lists the help text, then the error, and your own ids after them. |
aria-invalid, aria-required | "true" or absent | In a Field with invalid or required. |
data-invalid, data-required, data-disabled | present or absent | The state of the Field. |
AddressInput.City
Renders The town or city. It is never filled in from the postal code. Also exported as AddressInputCity. An <input type="text"> (a TextInput) with the role textbox. Put it in its own Field with a visible Field.Label: the label, help text and error are wired to it. It takes the props of a TextInput and passes ref to it. You cannot set type. The street, line 2 and city boxes also take no mask or announceRejections. Only the street box takes messages, to change the texts of the lookup.
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | – | Controlled: the value from your form state. Pass it with onValueChange. |
defaultValue | string | – | Uncontrolled: the native input keeps the value, and a form submit sends it. |
onValueChange | (value: string, details: TextInputChangeDetails) => void | – | Reports each change. onChange still works. |
autoComplete | string | the box’s purpose | The autofill purpose, with the Root’s prefix in front. Yours wins, so "off" turns autofill off for one box. |
ref | Ref<HTMLInputElement> | – | Reaches the <input>. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-input, kv-address-input-city | always | The part classes. |
autocomplete | "address-level2", or "off" | The autofill purpose (1.3.5 Identify Input Purpose), after the Root’s prefix. |
spellcheck, autocorrect | "false", "off" | A street or a town is not a word to correct. |
id, aria-describedby | in a Field | From the Field. aria-describedby lists the help text, then the error, and your own ids after them. |
aria-invalid, aria-required | "true" or absent | In a Field with invalid or required. |
data-invalid, data-required, data-disabled | present or absent | The state of the Field. |
useAddressInput
Use it for markup of your own. Give getInputProps(part) and postalCodeMask to a TextInput, each in its own Field inside a plain Fieldset. It holds no value and never moves focus. It does not look addresses up: the lookup is the Root’s geocoder.
Options
| Prop | Type | Default | Description |
|---|---|---|---|
country | string | – | The address’s country as an ISO 3166-1 alpha-2 code, such as SE. It picks the postal code’s mask, width and keypad: SE, FI and NO have a mask, and any other country has none. Without it: the provider’s country, then the country the page’s language implies (Swedish SE, Finnish FI, Norwegian NO). English implies none. Changing it never rewrites what was typed. |
autoComplete | string | – | "off" turns autofill off for every box (someone else’s address). Anything else, such as "section-postal" or "shipping", goes before each box’s purpose, so two addresses on one page stay apart. A box’s own autoComplete wins. |
Result
| Prop | Type | Default | Description |
|---|---|---|---|
country | string | undefined | – | The country that applies, in upper case, or undefined when no source says. |
postalCodeMask | MaskInput | undefined | – | The postal code mask of the country for SE, FI and NO, and undefined for any other country. Give it to a TextInput’s mask. |
rootProps | AddressInputRootPartProps | – | Spread on the <div> that holds the boxes: the class kv-address-input. |
getInputProps | (part: 'line1' | 'line2' | 'postalCode' | 'city' | 'country') => AddressInputInputPartProps | – | The props of one box: its class, its autofill purpose with the Root’s prefix, and the attributes of the box. Spread them on a TextInput next to the Field’s own wiring. "country" is for a select of your own: it gives the class and the autofill purpose only. |
Strings
These are the default texts in @kvirn-ui/i18n.
For your whole app, pass messages to KvirnProvider. For one AddressInput, pass its messages prop.
The boxes hold no text: the labels, help texts and errors are yours, in your own translations. The lookup has the texts below, and messages on AddressInput.Line1 replaces them for one box.
addressInput.lookupHelpSuggest
The help text under the street box when the search runs as you type. The line about the country follows it.
| Language | Default text |
|---|---|
| Svenska | Adresser föreslås efter 3 tecken. Välj en för att fylla i postnummer och ort, eller fortsätt skriva. |
| Suomi | Osoitteita ehdotetaan 3 merkin jälkeen. Valitse yksi täyttääksesi postinumeron ja postitoimipaikan tai jatka kirjoittamista. |
| Norsk bokmål | Adresser foreslås etter 3 tegn. Velg en for å fylle ut postnummer og sted, eller fortsett å skrive. |
| Norsk nynorsk | Adresser blir føreslåtte etter 3 teikn. Vel ei for å fylle ut postnummer og stad, eller hald fram å skrive. |
| English | Addresses are suggested after 3 characters. Choose one to fill in the postal code and town, or keep typing. |
addressInput.lookupHelpRequest
The help text when the search runs on request (Enter or Search). The line about the country follows it.
| Language | Default text |
|---|---|
| Svenska | Tryck på Sök för att slå upp din gata och fylla i postnummer och ort, eller fortsätt skriva. |
| Suomi | Paina Hae hakeaksesi katusi ja täyttääksesi postinumeron ja postitoimipaikan tai jatka kirjoittamista. |
| Norsk bokmål | Trykk på Søk for å slå opp gaten din og fylle ut postnummer og sted, eller fortsett å skrive. |
| Norsk nynorsk | Trykk på Søk for å slå opp gata di og fylle ut postnummer og stad, eller hald fram å skrive. |
| English | Press Search to look up your street and fill in the postal code and town, or keep typing. |
addressInput.lookupScope
The country that is searched, added after the help text.
| Language | Default text |
|---|---|
| Svenska | Föreslår adresser i Sweden. |
| Suomi | Ehdottaa osoitteita maasta Sweden. |
| Norsk bokmål | Foreslår adresser i Sweden. |
| Norsk nynorsk | Føreslår adresser i Sweden. |
| English | Suggests addresses in Sweden. |
addressInput.lookupNoResults
Shown in the list and announced when nothing is found.
| Language | Default text |
|---|---|
| Svenska | Ingen adress hittades för ”Storgatn”. Fortsätt skriva: din adress behöver inte finnas i listan. |
| Suomi | Osoitetta ”Storgatn” ei löytynyt. Jatka kirjoittamista: osoitteesi ei tarvitse olla luettelossa. |
| Norsk bokmål | Fant ingen adresse for «Storgatn». Fortsett å skrive: adressen din trenger ikke å stå i listen. |
| Norsk nynorsk | Fann inga adresse for «Storgatn». Hald fram å skrive: adressa di treng ikkje stå i lista. |
| English | No address found for “Storgatn”. Keep typing: your address doesn’t have to be in the list. |
addressInput.lookupError
Shown and announced when the search fails or takes too long.
| Language | Default text |
|---|---|
| Svenska | Adresssökningen fungerar inte just nu. Fortsätt skriva din adress. |
| Suomi | Osoitehaku ei toimi juuri nyt. Jatka osoitteesi kirjoittamista. |
| Norsk bokmål | Adressesøket fungerer ikke akkurat nå. Fortsett å skrive adressen din. |
| Norsk nynorsk | Adressesøket fungerer ikkje akkurat no. Hald fram å skrive adressa di. |
| English | The address search isn’t working right now. Keep typing your address. |
addressInput.lookupOffline
Shown and announced when the visitor is offline. No request is sent.
| Language | Default text |
|---|---|
| Svenska | Du är offline. Fortsätt skriva din adress. |
| Suomi | Olet offline-tilassa. Jatka osoitteesi kirjoittamista. |
| Norsk bokmål | Du er frakoblet. Fortsett å skrive adressen din. |
| Norsk nynorsk | Du er fråkopla. Hald fram å skrive adressa di. |
| English | You’re offline. Keep typing your address. |
addressInput.noAddressDetails
Shown and announced when a choice has no postal address, such as a park. Nothing is filled in.
| Language | Default text |
|---|---|
| Svenska | Den här platsen har ingen postadress. Välj en annan eller fortsätt skriva din adress. |
| Suomi | Tällä paikalla ei ole postiosoitetta. Valitse toinen tai jatka osoitteesi kirjoittamista. |
| Norsk bokmål | Dette stedet har ingen postadresse. Velg et annet, eller fortsett å skrive adressen din. |
| Norsk nynorsk | Denne staden har inga postadresse. Vel ein annan, eller hald fram å skrive adressa di. |
| English | This place has no postal address. Choose another, or keep typing your address. |
addressInput.filledNote
The note under the street box after a choice that filled in the boxes.
| Language | Default text |
|---|---|
| Svenska | Ifylld från adresssökningen. Kontrollera adressen. |
| Suomi | Täytetty osoitehaun perusteella. Tarkista osoite. |
| Norsk bokmål | Fylt ut fra adressesøket. Sjekk adressen. |
| Norsk nynorsk | Fylt ut frå adressesøket. Sjekk adressa. |
| English | Filled in from the address search. Check the address. |
addressInput.missingPostalCode
Added to the note and the announcement when the choice has no postal code.
| Language | Default text |
|---|---|
| Svenska | Lägg till postnumret: det fanns inte i sökningen. |
| Suomi | Lisää postinumero: haku ei löytänyt sitä. |
| Norsk bokmål | Legg til postnummeret: søket hadde det ikke. |
| Norsk nynorsk | Legg til postnummeret: søket hadde det ikkje. |
| English | Add the postal code: the search didn’t have it. |
addressInput.missingCity
Added to the note and the announcement when the choice has no town.
| Language | Default text |
|---|---|
| Svenska | Lägg till orten: den fanns inte i sökningen. |
| Suomi | Lisää postitoimipaikka: haku ei löytänyt sitä. |
| Norsk bokmål | Legg til stedet: søket hadde det ikke. |
| Norsk nynorsk | Legg til staden: søket hadde han ikkje. |
| English | Add the town or city: the search didn’t have it. |
addressInput.missingHouseNumber
Added to the note and the announcement when the choice is a street with no house number.
| Language | Default text |
|---|---|
| Svenska | Skriv ditt husnummer efter gatunamnet. |
| Suomi | Kirjoita talon numero kadun nimen perään. |
| Norsk bokmål | Skriv husnummeret ditt etter gatenavnet. |
| Norsk nynorsk | Skriv husnummeret ditt etter gatenamnet. |
| English | Type your house number after the street name. |
addressInput.countryChanged
Added to the note and the announcement when a choice is in another country than the country box showed.
| Language | Default text |
|---|---|
| Svenska | Landet är nu Finland. |
| Suomi | Maa on nyt Finland. |
| Norsk bokmål | Landet er nå Finland. |
| Norsk nynorsk | Landet er no Finland. |
| English | The country is now Finland. |
These are the default texts in @kvirn-ui/i18n.
These texts belong to the address search that AddressInput shares with AddressSearch, so the same keys work on AddressInput.Line1’s messages and on KvirnProvider.
addressSearch.submit
The name of the Search button, which shows only when the search runs on request.
| Language | Default text |
|---|---|
| Svenska | Sök |
| Suomi | Hae |
| Norsk bokmål | Søk |
| Norsk nynorsk | Søk |
| English | Search |
addressSearch.privacy
The notice above the street box, with the name of the service.
| Language | Default text |
|---|---|
| Svenska | Det du skriver skickas till the Kvirn map service för att hitta adressen. |
| Suomi | Kirjoittamasi teksti lähetetään palveluun the Kvirn map service osoitteen hakemiseksi. |
| Norsk bokmål | Det du skriver, sendes til the Kvirn map service for å finne adressen. |
| Norsk nynorsk | Det du skriv, blir sendt til the Kvirn map service for å finne adressa. |
| English | What you type is sent to the Kvirn map service to find the address. |
addressSearch.privacyUnnamed
The notice when the geocoder has no name.
| Language | Default text |
|---|---|
| Svenska | Det du skriver skickas till en adresstjänst för att hitta adressen. |
| Suomi | Kirjoittamasi teksti lähetetään osoitepalveluun osoitteen hakemiseksi. |
| Norsk bokmål | Det du skriver, sendes til en adressetjeneste for å finne adressen. |
| Norsk nynorsk | Det du skriv, blir sendt til ei adresseteneste for å finne adressa. |
| English | What you type is sent to an address service to find the address. |
addressSearch.tooShort
Shown and announced when the search runs on request and the text is too short.
| Language | Default text |
|---|---|
| Svenska | Skriv minst 3 tecken för att söka. |
| Suomi | Kirjoita vähintään 3 merkkiä hakeaksesi. |
| Norsk bokmål | Skriv minst 3 tegn for å søke. |
| Norsk nynorsk | Skriv minst 3 teikn for å søkje. |
| English | Type at least 3 characters to search. |
addressSearch.searching
Shown and announced when a request is on its way. It is left out when the answer is quick.
| Language | Default text |
|---|---|
| Svenska | Söker efter adresser |
| Suomi | Haetaan osoitteita |
| Norsk bokmål | Søker etter adresser |
| Norsk nynorsk | Søkjer etter adresser |
| English | Searching for addresses |
addressSearch.resultCount
Announced with the number of addresses found.
| Language | Default text |
|---|---|
| Svenska | 2 adresser hittades |
| Suomi | 2 osoitetta löytyi |
| Norsk bokmål | 2 adresser funnet |
| Norsk nynorsk | 2 adresser funne |
| English | 2 addresses found |
addressSearch.pickedFilled
Announced after a choice, with the sentences for what is missing after it.
| Language | Default text |
|---|---|
| Svenska | Vald: Drottninggatan 6, 111 51 Stockholm. Adressen är ifylld nedan. Kontrollera den innan du fortsätter. |
| Suomi | Valittu: Drottninggatan 6, 111 51 Stockholm. Osoite on täytetty alle. Tarkista se ennen kuin jatkat. |
| Norsk bokmål | Valgt: Drottninggatan 6, 111 51 Stockholm. Adressen er fylt ut nedenfor. Sjekk den før du fortsetter. |
| Norsk nynorsk | Vald: Drottninggatan 6, 111 51 Stockholm. Adressa er fylt ut nedanfor. Sjekk ho før du held fram. |
| English | Chosen: Drottninggatan 6, 111 51 Stockholm. The address is filled in below. Check it before you continue. |
These are the default texts in @kvirn-ui/i18n.
The postal code announces the mask’s strings, and messages on AddressInput.PostalCode replaces them for one box.
mask.characterNotAllowed
Announced when the postal code mask leaves out a character.
| Language | Default text |
|---|---|
| Svenska | Här kan du bara skriva siffror. |
| Suomi | Tähän voi kirjoittaa vain numeroita. |
| Norsk bokmål | Her kan du bare skrive sifre. |
| Norsk nynorsk | Her kan du berre skrive siffer. |
| English | Only digits can be entered here. |
mask.maximumLength
Announced when the postal code mask leaves out a character because the box is full.
| Language | Default text |
|---|---|
| Svenska | Du har skrivit alla 5 tecken. |
| Suomi | Olet kirjoittanut kaikki 5 merkkiä. |
| Norsk bokmål | Du har skrevet alle 5 tegnene. |
| Norsk nynorsk | Du har skrive alle 5 teikna. |
| English | You’ve entered all 5 characters. |
Known issues#
- Eastern Arabic and full-width digits in a masked postal code are refused today (the pattern mask takes 0-9). Set
mask={false}onAddressInput.PostalCodewhere those keyboards are expected. - DK and IS have no postal-code mask (masks exist for SE, FI and NO only): the box takes what is typed, asks phone keyboards for capital letters and is ten characters wide.
Information: Did you know?
If an issue here affects your service, list it in your accessibility statement with its workaround.
Testing#
The automated tests prove the keyboard behaviour, the names and states, that axe finds no violations in every story and theme, and, for the components they cover, that the stories hold up in forced colours, reduced motion, text spacing and a 320 pixel width. An Automated row passes on these tests alone. A Core or Release row passes only when an automated agent check and a person on the real assistive technology have both checked it. "agent-verified" means automated tests in the repository (with a virtual screen reader for the screen reader rows), not the real assistive technology.
| AT + browser + OS | Agent check | Human check | Result | Notes |
|---|---|---|---|---|
| Automated (re-runnable tests) | ||||
| axe, WCAG 2.2 A and AA, every story, 4 themes | pass | n/a | pass | address-input.stories.tsx, every story, 4 themes |
| Markup and ARIA (roles, names, ids, states) | pass | n/a | pass | address-input.test.tsx: the roles, names, descriptions and states of Line1's lookup and Country, and axe in each state |
| Keyboard contract rows (Vitest browser) | pass | n/a | pass | every row names a test in text-input.test.tsx, autocomplete.test.tsx or address-input.test.tsx |
| Focus order and management | pass | n/a | pass | address-input.test.tsx: a full postal code never moves focus, and changing country never rewrites the value |
| Display modes (forced colours, 320px reflow, text spacing, reduced motion) | pass | n/a | pass | the four sweep projects (storybook-forced-colors, -reduced-motion, -reflow, -text-spacing), run in CI |
| Core (required for beta) | ||||
| NVDA + Chrome + Windows | pending | pending | pending | |
| VoiceOver + Safari + iOS | pending | pending | pending | |
| Release (before 1.0 and each minor) | ||||
| JAWS + Chrome + Windows | pending | pending | pending | |
| TalkBack + Chrome + Android | pending | pending | pending | |
| VoiceOver + Safari + macOS | pending | pending | pending |
What to check#
- Tab through the address. Focus moves from the country (if there is one) to the street, line 2, postal code and city. A screen reader reads the group name (for example "Your address") and then each box's label.
- Let the browser's autofill fill in the address. Every box gets the right part of it. No list opens and nothing is announced.
- Type a full postal code. The code takes the country's shape and focus stays in the box. Change the country after that: the code stays as it was typed.
- Send the form with a box wrong. The error summary has a link for that box, and the link moves focus to it.
- With a lookup: type part of a street. The number of addresses is heard. Press Enter with no suggestion chosen: the search runs and the form is not sent. Turn the network off and search: the message points to the boxes.
- Choose a suggestion. The street, postal code and city are filled in, and focus stays in the street box. One message says the address is filled in, and names anything missing (the house number, the postal code, a new country). Type the house number straight after the street.