Component libraries
Drive Ant Design, MUI or Mantine's own autocomplete with the address store.
This guide connects the address search to an autocomplete your component library already has, like Ant Design's AutoComplete, MUI's Autocomplete or Mantine's Autocomplete. If you style everything yourself, for example with shadcn/ui, follow Styling AddressInput instead.
Connect the hook
Your library's autocomplete already does the ARIA, the keyboard, the popup and the styling. Don't render ours next to it; drive yours with the store instead. useAddressAutosuggest(options) renders nothing and returns { state, store, inputRef }:
import { suggestionKey, useAddressAutosuggest } from "@dk-address/react";
const { state, store, inputRef } = useAddressAutosuggest({ kind: "address" });Then connect it to your library's props:
| Store | Typical autocomplete prop |
|---|---|
state.value | the controlled input text (value, inputValue) |
store.setInput(text) | the typing callback (onSearch, onInputChange) |
state.suggestions | options, keyed by suggestionKey(suggestion), labelled however you like |
store.select(suggestion) | the pick callback (onSelect, onChange with a picked option) |
state.open, store.setOpen(open) | controlled open and its change callback |
state.status | loading and empty content |
inputRef | the real <input> element, so the caret moves into the gap after a pick |
state.selection | the form value, usually state.selection.details.id |
Avoid common pitfalls
Library autocompletes assume they own the text and the popup. These are the places where that clashes with the address search, and how the Ant Design block handles each:
- Keep typing and picking apart. Ant Design and others also call their change handler with the picked option's value. Send only typing to
setInput, or the option key ends up in the input. - Turn the library's filtering off. KDS already filtered the results (
filterOption={false},filterOptions={(options) => options}…). - The library closes the popup after every pick. When a pick only refines the text (a street, a building), the store keeps the list open. Ignore the library's close request that follows a pick; it may arrive a render later, not in the same tick.
- Listen for the pick, not the text change. Picking an option whose label equals the current text may not change the text at all.
- Find the real input. Use the library's ref, an input-props slot (
inputProps,renderInput), ornativeElement.querySelector("input"), and assign it toinputRef.current. - Use the address id as the form value. Report the id once a final address is picked and
undefinedwhen the text is edited; prefill an id withstore.selectById(id).
Start from a block
Blocks are files you copy into your app and own. Each is tested against a real version of its library and has a live demo:
| Block | What you get |
|---|---|
| Ant Design | Ant Design 6 AutoComplete that works as a Form.Item control, with the address id as its value |
| shadcn/ui | AddressInput styled with your shadcn/ui theme. Not a library autocomplete: it's the headless parts, styled. |