react-thaizip

Address autocomplete

Search Thai addresses from typed text and receive a structured address value

ThaiAddressAutocomplete is for forms where people can search an address by sub-district, district, province, or postal code.

Install

npx react-thaizip add autocomplete

The command adds the component plus utils and the address-index loading hook to the directories recorded in thaizip.config.json.

Basic usage

Import from the location generated in your project:

import { ThaiAddressAutocomplete } from '@/components/thai-address-autocomplete'

export function AddressField() {
  return <ThaiAddressAutocomplete onValueChange={(address) => console.log(address)} />
}

onValueChange receives ResolvedThaiAddress | null. Selecting a suggestion yields a structured address; typing an empty query clears an existing resolved selection with null.

ค้นหาที่อยู่

ค้นหาที่อยู่ไทยด้วยการพิมพ์ข้อมูลส่วนใดส่วนหนึ่งของที่อยู่

Use locale="en" for English labels, placeholders, and suggestions. The returned data still includes Thai and English names.

<ThaiAddressAutocomplete locale="en" onValueChange={(address) => console.log(address)} />
Address autocomplete

Search for a Thai address by typing any part of it.

Controlled value

Pass value to control the selection, or defaultValue to seed uncontrolled state. This example includes a clear button for the controlled value and shows the callback output.

const [address, setAddress] = useState<ResolvedThaiAddress | null>(null)

<ThaiAddressAutocomplete value={address} onValueChange={setAddress} />
ค้นหาที่อยู่

ค้นหาที่อยู่ไทยด้วยการพิมพ์ข้อมูลส่วนใดส่วนหนึ่งของที่อยู่

ที่อยู่ที่เลือก
null

Disabled and invalid states

Pass disabled to turn off the search field, or aria-invalid after failed form validation.

ค้นหาที่อยู่

ค้นหาที่อยู่ไทยด้วยการพิมพ์ข้อมูลส่วนใดส่วนหนึ่งของที่อยู่

ค้นหาที่อยู่

ค้นหาที่อยู่ไทยด้วยการพิมพ์ข้อมูลส่วนใดส่วนหนึ่งของที่อยู่

Props

Value

PropTypeDescription
valueResolvedThaiAddress | nullControlled value; pass null to clear it.
defaultValueResolvedThaiAddress | nullUncontrolled seed value; also pre-fills the initial search text.
onValueChange(address: ResolvedThaiAddress | null) => voidCalled when an address is selected or cleared.
PropTypeDescription
limitnumberMaximum suggestions; passed to the core hook.
debouncenumberSearch delay in milliseconds; passed to the core hook.
thresholdnumberMinimum query length; passed to the core hook.

Field

PropTypeDescription
namestringRenders four hidden inputs for subdistrict, district, province, and zipcode.
locale'th' | 'en'Text and label locale; defaults to 'th'.
disabledbooleanDisables the search input.
requiredbooleanMarks the input as required.
aria-invalidReact.AriaAttributes['aria-invalid']Marks the input as invalid.
onBlurReact.FocusEventHandler<HTMLInputElement>Runs when the input loses focus.
onError(error: Error) => voidRuns if the address index cannot load.

Text

PropTypeDescription
textsPartial<ThaiAddressAutocompleteTexts>Overrides the placeholder, loading/error/empty states, and clear/retry labels.

Class slots

PropApplied to
classNameRoot wrapper
inputClassNameSearch input
popupClassNameResults popup
itemClassNameEach result item

Ref

PropTypeDescription
refReact.Ref<HTMLInputElement>Forwarded to the input.

See Forms to submit address values and Customization to change the presentation. For ordered address selection, see cascade select.

On this page