Address field
A postal address input with the parts, order and labels of each country, optional autocomplete from your address provider.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
value | AddressValue | { ...EMPTY } | The address. Set it as an object, or as JSON on the attribute. |
country | string | US | The country to start with, when value has none. |
countries | string[] | [] | The countries offered, as ISO codes; every country with a format when empty. |
name | string | — | The form field name: the form receives name[part] for each part. |
label | string | — | The group's accessible name; "Address" by default. |
required | boolean | false | The address must be given; otherwise it may be left empty, but once started, the country's required parts are. |
disabled | boolean | false | Turns every part off; a disabled address is not submitted. |
Events
| Name | Type | Description |
|---|---|---|
input | Event | A part changed. |
change | Event | A part was committed, or a suggestion filled the address. |
address-change | CustomEvent<AddressChangeEventDetail> | The address changed: detail.value and whether it is complete. |
CSS parts
Shadow DOM styling hooks used with ::part(name). Prefer CSS custom properties when they cover the change.
| Name | Description |
|---|---|
address | The grid of parts. |
row | A row of parts. |
country | Shadow DOM styling hook for the country element. |
CSS custom properties
Grouped by semantic target and state from --c2-<component>__<target>__<state>--<property>. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-address-field--width | length | 100% | The field's width; its rows wrap to one part each when narrow. |
--c2-address-field--gap | length | 12px | Space between parts on a row. |
--c2-address-field--row-gap | length | 12px | Space between rows. |
--c2-address-field__part--min-width | length | 120px | A row wraps when its parts would be narrower. |
Text and languages
The text the component shows, in English. It shows another language when the app adds one with addTranslations, under address-field, and the nearest lang asks for it; any message not translated stays in English. {0}, {1}… stand for the values a message carries. Languages guide.
| Key | English | Values |
|---|---|---|
addressGroup | Address | — |
country | Country or region | — |
select | Select | — |
optional | {0} (optional) | {0} label |
required | {0} is required | {0} label |
postalInvalid | {0} should look like {1} | {0} label {1} example |
filled | Address filled in | — |
address | Address | — |
addressLine1 | Address line 1 | — |
street | Street address | — |
apartment | Apartment, suite, etc. | — |
addressLine2 | Address line 2 | — |
building | Building, floor | — |
city | City | — |
town | Town or city | — |
cityWard | City / ward | — |
suburb | Suburb | — |
district | District | — |
neighborhood | Neighbourhood | — |
colonia | Colonia | — |
state | State | — |
province | Province | — |
prefecture | Prefecture | — |
county | County | — |
emirate | Emirate | — |
region | State / region | — |
area | Area | — |
zip | ZIP code | — |
postcode | Postcode | — |
postalCode | Postal code | — |
pin | PIN code | — |
cep | CEP | — |
eircode | Eircode | — |