Core
The address field's behaviour without React, for vanilla JavaScript, Vue, Svelte or web components.
@dk-address/core has the same search, caret handling and details lookup as the React components, without a framework. You connect it to your own input: send the text in, and render the state it gives back.
import { createAddressAutosuggest } from "@dk-address/core";
const store = createAddressAutosuggest({ kind: "address", onSelect: console.log });
const stop = store.subscribe(() => render(store.getState()));
input.addEventListener("input", () => store.setInput(input.value));select(suggestion) either refines the text or completes the field, as How it works describes. After a refine, move the input's caret to state.caret.position. state.slot is { start, end, kind: "houseNumber" | "unit", text } until the user edits outside the gap.
State
| Field | Meaning |
|---|---|
value | The input text |
caret | { position, revision } after a pick, null while typing. revision changes on every move |
slot | The gap being filled, or null |
suggestions | Suggestions for the current text |
status | idle, loading, success or error |
error | The search error while status is error |
open | Whether the list should show |
selection | { suggestion, status, details, error } after a final pick |
Options
| Option | Default | |
|---|---|---|
client | createClient() | See client |
kind | "address" | "accessAddress" stops at house numbers |
debounceMs | 100 | Picks search immediately |
limit | KDS's 100 | Up to 200 |
municipalityCodes | e.g. ["0101"] | |
includeProvisional | false | Provisional (foreløbige) addresses |
houseNumberPrefix | true | Prefix-match house numbers after a street pick |
fetchDetails | true | Look up the full address after a final pick |
onSelect | Called with the selection once details are loaded |
Methods
| Method | Does |
|---|---|
getState() | Returns the current state |
subscribe(listener) | Calls listener on every change; returns an unsubscribe function |
setInput(text) | Sets the text, as typing does |
select(suggestion) | Picks a suggestion |
selectById(id) | Prefills from a stored address id |
setOpen(open) | Opens or closes the list |
setOptions(options) | Changes options; searches again if kind, limit, municipalityCodes or includeProvisional changed |
clear() | Empties the text and the selection |
destroy() | Cancels pending requests; the store stays usable |