AddressAutocomplete

Type a street and pick from live suggestions. Lookups wait for a pause, show a spinner and drop stale answers. Picking confirms the full address underneath. Inputs.

Open playground

About

AddressAutocomplete is a React component in the Inputs category of smoui. It is typed, ships no stylesheet, follows your theme through CSS variables, and honors prefers-reduced-motion. Import it with import { AddressAutocomplete } from "@ashutoshswamy/smoui" and set source, label, value among its 5 props.

Install

Terminal
npm i @ashutoshswamy/smoui

Usage

TSX
import { AddressAutocomplete } from "@ashutoshswamy/smoui";

<AddressAutocomplete
  label="Delivery address"
  source={(q) => fetch(`/api/places?q=${q}`).then((r) => r.json())}
  onChange={setAddress}
/>

Props 5

source

Your lookup. Wire it to Places, Mapbox or your own table.

(query: string) => Address[] | Promise<Address[]>
label

Label above the field.

string
value / defaultValue

The confirmed address: line1, city, region, postcode, country.

Addressnull
onChange

Called on pick, and with null when the confirmed address is edited or cleared.

(address: Address | null) => void
minChars

Characters typed before the first lookup.

numberdefault 3