Skip to Content
dk-address

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

FieldMeaning
valueThe input text
caret{ position, revision } after a pick, null while typing. revision changes on every move
slotThe gap being filled, or null
suggestionsSuggestions for the current text
statusidle, loading, success or error
errorThe search error while status is error
openWhether the list should show
selection{ suggestion, status, details, error } after a final pick

Options

OptionDefault
clientcreateClient()See client
kind"address""accessAddress" stops at house numbers
debounceMs100Picks search immediately
limitKDS's 100Up to 200
municipalityCodese.g. ["0101"]
includeProvisionalfalseProvisional (foreløbige) addresses
houseNumberPrefixtruePrefix-match house numbers after a street pick
fetchDetailstrueLook up the full address after a final pick
onSelectCalled with the selection once details are loaded

Methods

MethodDoes
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