Skip to content

Autocomplete

YhAutocomplete provides suggestion candidates based on the current input value. It is suitable for search boxes, address completion, quick command search, and similar flows.

Basic Usage

Provide a suggestion fetcher through fetch-suggestions.

Basic Usage

Custom Suggestion Template

Use the default slot to customize each suggestion row.

Custom Suggestion Template

Asynchronous requests can be handled inside fetch-suggestions, and the dropdown updates after the callback resolves.

Remote Search

Disabled State

Set disabled to block input and panel interaction.

Disabled State

Clearable

When clearable is enabled, the clear icon appears while the field has a value and is hovered or focused.

Clearable

Different Sizes

Supports large, default, and small.

Different Sizes

Loading and Empty Slots

Use loading and empty to customize the non-data states of the dropdown panel.

Loading and Empty Slots

Use in Nuxt

After installing @yh-ui/nuxt, YhAutocomplete can be used directly. The input element itself participates in SSR, while the dropdown panel mounts on the client during interaction. When teleported is enabled, the panel is moved into body.

Use in Nuxt

API

Props

NameDescriptionTypeDefault
model-value / v-modelBound input valuestringundefined
placeholderPlaceholder textstringundefined
disabledWhether the component is disabledbooleanfalse
clearableWhether the value can be clearedbooleanfalse
sizeInput size'large' | 'default' | 'small'undefined
fetch-suggestionsSuggestion fetcher(query: string, callback: (suggestions: AutocompleteSuggestion[]) => void) => voidundefined
trigger-on-focusWhether suggestions should be fetched on focusbooleantrue
debounceSuggestion fetch debounce in millisecondsnumber300
placementDropdown placement'top' | 'top-start' | 'top-end' | 'bottom' | 'bottom-start' | 'bottom-end''bottom-start'
value-keyField used as the display value inside a suggestion objectstring'value'
popper-classCustom class name for the dropdown panelstringundefined
teleportedWhether the dropdown is teleported to bodybooleantrue
fit-input-widthWhether the dropdown width follows the input widthbooleantrue
highlight-first-itemWhether the first suggestion is highlighted by defaultbooleanfalse
prefix-iconPrefix icon component or icon namestring | Componentundefined
suffix-iconSuffix icon component or icon namestring | Componentundefined
validate-eventWhether form validation is triggeredbooleantrue
autofocusWhether the input autofocusesbooleanfalse
nameNative name attributestringundefined
autocompleteNative autocomplete attributestring'off'
theme-overridesComponent-level theme overridesComponentThemeVarsundefined

Events

NameDescriptionParameters
update:modelValueTriggered when the bound value changes(value: string) => void
inputTriggered while typing(value: string) => void
changeTriggered after the input change is committed(value: string) => void
focusTriggered when the input gains focus(event: FocusEvent) => void
blurTriggered when the input loses focus(event: FocusEvent) => void
clearTriggered when the clear icon is clicked() => void
selectTriggered when a suggestion item is selected(item: AutocompleteSuggestion) => void

Slots

NameDescriptionParameters
defaultCustom suggestion item content{ item: AutocompleteSuggestion }
prefixInput prefix content-
suffixInput suffix content-
prependContent before the input wrapper-
appendContent after the input wrapper-
loadingCustom loading content-
emptyCustom empty-state content-

Expose

NameDescriptionType
focusFocuses the input() => void
blurBlurs the input() => void
closeCloses the dropdown panel() => void
highlightHighlights a suggestion item by index(index: number) => void
inputRefNative input element referenceHTMLInputElement | undefined

Type Exports

NameDescription
YhAutocompleteSizeSize union type
YhAutocompletePlacementDropdown placement union type
YhAutocompleteSuggestionSuggestion item type
YhAutocompletePropsProps type for YhAutocomplete
YhAutocompleteEmitsEmits type for YhAutocomplete
YhAutocompleteSlotsSlots type for YhAutocomplete
YhAutocompleteExposePublic expose type
YhAutocompleteInstanceComponent instance type

Theme Variables

YhAutocomplete does not currently expose dedicated component-scoped CSS variables. It mainly consumes shared input, border, fill, and text tokens, and can still be adjusted through themeOverrides together with global theme variables.

Released under the MIT License.