react-thaizip

Full address form

Capture house number, moo, soi, and street alongside an ordered address selection in one form

ThaiAddressForm is for forms that need a full address: house number/moo/soi/street plus sub-district, district, and province. It embeds a cascade select internally.

Install

npx react-thaizip add address-form

The command adds the component, the embedded thai-address-cascade-select.tsx file, 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 { ThaiAddressForm } from '@/components/thai-address-form'

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

onValueChange receives FullThaiAddress | null. It is only non-null once the house number is filled in and all three cascade levels are selected.

Thai input

ฟอร์มที่อยู่แบบเต็ม

กรอกบ้านเลขที่พร้อมหมู่/ซอย/ถนน แล้วเลือกจังหวัด อำเภอ/เขต และตำบล/แขวง

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

English input

Use locale="en" for English labels and options, for both the free-text fields and the embedded cascade select.

Address form

Enter a house number plus moo/soi/street, then choose the province, district, and sub-district.

Province
District
Sub-district
Postal code

Controlled value

Pass value to control the whole address, or defaultValue to seed it. An in-progress, not-yet-complete cascade selection is never cleared, even while the controlled value is null.

<ThaiAddressForm name="address" value={address} onValueChange={setAddress} />
ฟอร์มที่อยู่แบบเต็ม

กรอกบ้านเลขที่พร้อมหมู่/ซอย/ถนน แล้วเลือกจังหวัด อำเภอ/เขต และตำบล/แขวง

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

Disabled and invalid states

Pass disabled to disable every text field and select, or aria-invalid to mark them invalid.

ฟอร์มที่อยู่แบบเต็ม

กรอกบ้านเลขที่พร้อมหมู่/ซอย/ถนน แล้วเลือกจังหวัด อำเภอ/เขต และตำบล/แขวง

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

กรอกบ้านเลขที่พร้อมหมู่/ซอย/ถนน แล้วเลือกจังหวัด อำเภอ/เขต และตำบล/แขวง

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

Props

Value

PropTypeDescription
valueFullThaiAddress | nullControlled value; pass null to clear it.
defaultValueFullThaiAddress | nullUncontrolled seed value; pre-fills both the text fields and the embedded cascade.
onValueChange(address: FullThaiAddress | null) => voidCalled once the house number is non-blank and all three levels are selected, or when the value becomes incomplete again.

Field

PropTypeDescription
namestringRenders 8 hidden inputs: the cascade's own 4 (-subdistrict/-district/-province/-zipcode) plus this component's own 4 (-houseno/-moo/-soi/-street).
locale'th' | 'en'Text and label locale for both this component and the embedded cascade; defaults to 'th'.
disabledbooleanDisables every text field and the embedded cascade.
requiredbooleanMarks the house-number field and the embedded cascade as required (moo/soi/street stay always optional).
aria-invalidReact.AriaAttributes['aria-invalid']Marks the four text inputs and the cascade's triggers invalid.
onBlurReact.FocusEventHandler<HTMLInputElement>Runs only when the house-number input loses focus.
onError(error: Error) => voidRuns if the address index cannot load (handled by the embedded cascade).

Text

PropTypeDescription
textsPartial<ThaiAddressFormTexts>Overrides the house-number/moo/soi/street labels and placeholders.
cascadeTextsPartial<ThaiAddressCascadeSelectTexts>Forwarded as the embedded cascade select's own texts prop.

Class slots

PropApplied to
classNameRoot wrapper
labelClassNameLabels of the text fields and the cascade
inputClassNameThe house-number/moo/soi/street inputs
triggerClassNameThe cascade's select triggers and postal-code input
popupClassNameThe cascade's option popups
itemClassNameEach of the cascade's option items

Ref

PropTypeDescription
refReact.Ref<HTMLInputElement>Forwarded to the house-number input.

See Forms to submit address values and Customization to change the presentation. For the embedded component on its own, see cascade select.

On this page