react-thaizip

Address cascade select

Choose province, district, and sub-district in order

ThaiAddressCascadeSelect is for forms where people choose an address in the order province → district → sub-district.

Install

npx react-thaizip add cascade-select

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

Basic usage

Import from the location generated in your project:

import { ThaiAddressCascadeSelect } from '@/components/thai-address-cascade-select'

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

onValueChange receives ResolvedThaiAddress | null once all three levels have been chosen.

Thai choices

เลือกที่อยู่แบบลำดับชั้น

เลือกจังหวัด อำเภอ/เขต และตำบล/แขวงตามลำดับ

จังหวัด
อำเภอ/เขต
ตำบล/แขวง
รหัสไปรษณีย์

English choices

Use locale="en" for English labels and options.

<ThaiAddressCascadeSelect locale="en" onValueChange={(address) => console.log(address)} />
Address cascade select

Choose a province, district, and sub-district in order.

Province
District
Sub-district
Postal code

Controlled value

Pass value to control the full selection, or defaultValue to seed the selected address. This example includes a clear button and shows the callback value.

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

<ThaiAddressCascadeSelect value={address} onValueChange={setAddress} />
เลือกที่อยู่แบบลำดับชั้น

เลือกจังหวัด อำเภอ/เขต และตำบล/แขวงตามลำดับ

จังหวัด
อำเภอ/เขต
ตำบล/แขวง
รหัสไปรษณีย์
ค่าจาก callback
null

Changing a parent choice

After a complete selection, changing the province or district emits onValueChange(null) and clears downstream selections that no longer match. The person then chooses the remaining address levels again.

Disabled and invalid states

Pass disabled to disable every select, or aria-invalid to mark all three triggers invalid.

เลือกที่อยู่แบบลำดับชั้น

เลือกจังหวัด อำเภอ/เขต และตำบล/แขวงตามลำดับ

จังหวัด
อำเภอ/เขต
ตำบล/แขวง
รหัสไปรษณีย์
เลือกที่อยู่แบบลำดับชั้น

เลือกจังหวัด อำเภอ/เขต และตำบล/แขวงตามลำดับ

จังหวัด
อำเภอ/เขต
ตำบล/แขวง
รหัสไปรษณีย์

Props

Value

PropTypeDescription
valueResolvedThaiAddress | nullControlled value; pass null to clear it.
defaultValueResolvedThaiAddress | nullUncontrolled seed value; pre-selects the complete address chain.
onValueChange(address: ResolvedThaiAddress | null) => voidCalled when an address is completed or cleared.

Field

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

Text

PropTypeDescription
textsPartial<ThaiAddressCascadeSelectTexts>Overrides labels, placeholders, and loading/error/retry text.

Class slots

PropApplied to
classNameRoot grid wrapper
labelClassNameEvery field label
triggerClassNameSelect triggers and the postal-code input
popupClassNameOption popups
itemClassNameEach option item

Ref

PropTypeDescription
refReact.Ref<HTMLButtonElement>Forwarded to the province trigger, the cascade's primary control.

Both ref and onBlur target the province trigger, not the district or sub-district trigger.

See Forms to submit address values and Customization to change the presentation. For free-text search, see autocomplete.

On this page