Skip to content

SmartAddress

A specialized address input component with an integrated smart parsing workflow. It can extract name, phone number, and region fields from pasted text, and supports input, select, and cascader region modes.

Basic Usage (Input Mode)

By default, the region fields are rendered as three plain inputs. Paste address text into the parser area and click "Smart Parse" to fill the form.

Basic Usage

Set region-type="select" and pass region-options to render linked province, city, and district selects.

Guangdong
Shenzhen
Nanshan
Select Mode

Cascader Mode

Set region-type="cascader" to use a cascader picker for region selection.

Cascader Mode

Custom Fields and Codes

When backend region data uses custom field names such as name/code/items, configure label-field, value-field, and children-field to map the structure.

440000
440300
440305
Custom Fields and Codes

Label Placement

Set label-placement="top" to move labels above the fields.

Top Aligned Labels

Usage in Nuxt

YhSmartAddress can be used directly in Nuxt after registering the YH-UI module. The form renders during SSR, and parser or linked region interactions continue on the client after hydration.

Usage in Nuxt

How to Configure

Register the module in nuxt.config.ts:

ts
export default defineNuxtConfig({
  modules: ['@yh-ui/nuxt'],
  yhUI: {
    components: ['YhSmartAddress']
  }
})

API

Props

AttributeDescriptionTypeDefault
model-value / v-modelCurrent address valueAddressValue{ name: '', phone: '', province: '', city: '', district: '', street: '', detail: '' }
region-typeProvince/city/district mode'input' | 'select' | 'cascader''input'
region-optionsRegion tree data sourceRegionOption[][]
label-fieldField name for labelsstring'label'
value-fieldField name for valuesstring'value'
children-fieldField name for childrenstring'children'
show-nameWhether to display the name fieldbooleantrue
show-phoneWhether to display the phone fieldbooleantrue
show-streetWhether to display the street fieldbooleanfalse
show-parserWhether to display the smart parserbooleantrue
parse-placeholderPlaceholder for the parser inputstring''
parse-button-textText for the parse buttonstring''
requiredWhether fields are requiredbooleanfalse
disabledWhether to disable the componentbooleanfalse
label-placementLabel placement'left' | 'top''left'
parserCustom parser function(raw: string) => ParsedAddressnull
theme-overridesTheme variables overrideComponentThemeVars{}

Events

Event NameDescriptionCallback Parameters
update:modelValueTriggered when value changes(val: AddressValue) => void
parsedTriggered after smart parsing(val: ParsedAddress) => void
changeTriggered when any field changes(val: AddressValue) => void

Slots

Slot NameDescription
parse-iconIcon slot on the left side of the parse button
regionSlot for custom region input area
extraSlot for additional content at the bottom

Expose

This component does not expose public instance methods or properties.

Types

AddressValue

ts
interface AddressValue {
  name: string
  phone: string
  province: string
  city: string
  district: string
  street: string
  detail: string
}

RegionOption

ts
interface RegionOption {
  label?: string
  value?: string | number
  children?: RegionOption[]
  [key: string]: unknown
}

ParsedAddress

ts
interface ParsedAddress {
  name: string
  phone: string
  province: string
  city: string
  district: string
  street: string
  detail: string
}

Theme Variables

YhSmartAddress supports themeOverrides. The following CSS variables are available:

Variable NameDescriptionDefault Value
--yh-smart-address-parser-bgBackground of smart parse areavar(--yh-color-primary-light-9)
--yh-smart-address-input-bgBackground of input fieldsvar(--yh-fill-color-blank)
--yh-smart-address-parse-btn-bgBackground of parse buttonvar(--yh-color-primary)
--yh-smart-address-tip-successColor of success tipvar(--yh-color-success)
--yh-smart-address-tip-errorColor of error tipvar(--yh-color-danger)
--yh-smart-address-label-widthWidth of form labels72px

Type Exports

NameDescription
YhSmartAddressPropsComponent props type
YhSmartAddressEmitsComponent emits type
YhSmartAddressSlotsComponent slots type
YhAddressValueAddress value type
YhRegionOptionRegion option type
YhParsedAddressParsed address type
YhSmartAddressInstanceComponent instance type

Released under the MIT License.