Address Autocomplete
Type to search addresses. Works out of the box with a bundled offline mock — override onSearch with Mapbox Search (or any geocoder) in production.
Gallery
Search, select, and clear. Pass any async onSearch — demos use the bundled mock.
Loading…
Installation
CLI
Also needs
npx @sonojs/ui@latest add command input-groupnpm i lucide-reactUsage
address-autocomplete.tsx
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| onSearch | (query: string) => Promise<AddressSuggestion[]> | searchMockAddresses | Async lookup. Defaults to the bundled mock; replace with your geocoder in production. Stale responses are ignored. |
| value | AddressValue · null | - | Controlled selected address. |
| defaultValue | AddressValue · null | null | Initial address when uncontrolled. |
| onValueChange | (value: AddressValue · null) => void | - | Fires on select or clear. |
| debounceMs | number | 300 | Delay before calling `onSearch`. |
| minChars | number | 2 | Minimum query length before searching. |
| placeholder | string | "Search address…" | Input placeholder when empty. |
| emptyMessage | string | "No addresses found." | Shown when `onSearch` returns an empty list. |
| loadingMessage | string | "Searching…" | Shown while `onSearch` is pending. |
| errorMessage | string | "Could not load addresses." | Shown when `onSearch` throws. |
| disabled | boolean | false | Disables the field. |
| invalid | boolean | false | Destructive border via `aria-invalid`. |
| className | string | - | Merged onto the `InputGroup` root. |
Related
- Command, suggestion list keyboard chrome
- Input Group, pin icon and clear addon
- Field, label and describe the control