Skip to Content
dk-address

Ant Design

An Ant Design 6 AutoComplete driven by the KDS address store, ready to use as a Form.Item control.

AutoCompleteForm
Loading demo…

Both fields are real Ant Design Form.Items: the first is required, the second starts filled in from initialValues. Press Save to see the submitted address ids.

Install the block

  1. Install the dependencies:

    npm i antd@6 @ant-design/icons@6 @dk-address/react
  2. Copy address-auto-complete.tsx (the Code tab) into your app.

  3. Recommended: Ant Design's Select, and so AutoComplete, renders autocomplete="new-password" by default, which makes password managers offer to generate a password for the address field. Turn it off app-wide with <ConfigProvider select={{ autoComplete: "off" }}>, as the demo does.

Use it in a form

import { Form } from "antd";
import { AddressAutoComplete } from "./address-auto-complete";

<Form initialValues={{ addressId: savedId }} onFinish={(values) => save(values.addressId)}>
  <Form.Item
    label="Address"
    name="addressId"
    rules={[{ required: true, message: "Pick an address from the list" }]}
  >
    <AddressAutoComplete />
  </Form.Item>
</Form>;
  • The value is the address id. Picking a final address sets it; editing or clearing the text sets it to undefined, so required means "an address was picked", not "something was typed".
  • Prefill and reset go through the form. An id from initialValues or setFieldsValue fills in the text; resetting clears it.
  • Details come as the second argument of onChange(id, details): floor, door, municipality, postal code and the position.
  • Props: every core option (kind, municipalityCodes, limit, includeProvisional, debounceMs, client) plus placeholder, disabled, status, className, style and id. Form.Item sets id and status, so its label and error state work like any Ant Design control.

Change your copy

The block is useAddressAutosuggest() connected to Ant Design's AutoComplete. Keep these connections when you edit it, or the caret and the popup stop working:

  • Typing and picking stay apart: typing goes through showSearch.onSearch and picks through onSelect. Ant Design calls onChange with the picked option's key, so the block doesn't use it.
  • Filtering stays off: showSearch.filterOption is false, since KDS already filtered the results.
  • The store controls open: Ant Design asks to close the popup after every pick. The block ignores that request, so the list stays open while the address is refined.
  • The real <input> goes to inputRef: that's how the caret moves into the gap after a pick.

To change how the popup looks, edit popupRender, which adds the gap hint above the options, and the option labels, which show an icon and a hint for each type.