Forms

VeeCombobox

A combobox component that uses the composition API provided by Vee-Validate to perform validation.

Source code

Click to see the source code for this component on GitHub. Feel free to copy it and adjust it for your own use.

Installation

Usage

UiVeeCombobox wraps UiCombobox with a label, hint and animated error message, and registers the value with the surrounding Vee-Validate form. The form stores the value of the selected option (an array of values when multiple), while the input and the tags show its label. Any other attribute (open-on-focus, ignore-filter, ...) is forwarded to UiCombobox.

Basic example

options takes an array of strings, numbers or { value, label, disabled, group } objects. The form stores the value, the input shows the label. The required prop only adds the asterisk and aria-required, so enforce it in your schema.

Pick the framework you want to start with.

Default value

Bind a value with v-model (or initialValues on useForm). Add clearable to show a button that clears the selection.

Starts with a default value. Use the clear button to remove it.

Current value: Nuxt

Groups

Give options a group to render them under a label. Ungrouped options are rendered first.

Multiple

Set multiple to select more than one option. The value is an array and the selection is shown as removable tags.

TypeScript

Pick up to 4 languages.

Custom items

The default slot replaces the generated options. With object values, set by to compare them and display-value to control what the input shows.

Search your team by name.

Icons and trigger

Use icon for a leading icon, clearable for a clear button and show-trigger for a chevron that toggles the list.

Async options

The search event is emitted with the text in the input as the user types. Load the options from your API and add ignore-filter so they are not filtered a second time.

Options are loaded from the server as you type.

Disabled

Set disabled to prevent interaction.

Contact support to change your plan.

Form

A full form with a single and a multiple combobox.

Create project

Choose a framework and where to deploy it.

Pick at least one region.

Props

PropTypeDescription
namestringField name registered with Vee-Validate. Falls back to a generated id.
labelstringLabel shown above the input.
label-hintstringExtra hint shown next to the label.
hintstringHelper text. Hidden while there is an error.
placeholderstringPlaceholder of the input.
iconstringIcon shown at the start of the input.
options(string | number | { value: any; label?: string; disabled?: boolean; group?: string })[]Options to render. value is stored in the form, label (defaults to the value) is displayed.
multiplebooleanAllow selecting more than one option. The value is an array shown as tags.
bystring | ((a: any, b: any) => boolean)Property name or comparator used to compare object values.
display-value(value: any) => stringText shown for a selected value. Defaults to the label of the matching option. Needed for object values used with the default slot.
empty-textstringMessage shown when nothing matches. While empty (and no empty slot is used) the popup stays hidden when there is no match.
clearablebooleanShows a button that clears the selection.
show-triggerbooleanShows a chevron button that toggles the list.
rulesanyVee-Validate rules (or use a schema on useForm).
v-modelanyCurrent value.
requiredbooleanShows the required asterisk and sets aria-required.
disabledbooleanPrevents interaction.
validate-on-mountbooleanValidates as soon as the field mounts.
classHTMLAttributes["class"]Classes for the wrapper element.

Events

EventPayloadDescription
searchstringEmitted with the text in the input as the user types.

Slots

SlotDescription
defaultReplaces the generated options inside the popup.
labelCustom label. Receives error-message and value.
iconCustom leading icon.
emptyCustom empty state.
hintCustom hint. Receives error-message and value.
errorMessageCustom error message. Receives error-message and value.

Accessibility

The input keeps the semantics of UiCombobox, including keyboard navigation. The label is linked to the input, the hint and error message are linked with aria-describedby, and the input is marked aria-invalid (and the wrapper styled) when validation fails. The field is marked as touched when the input loses focus, and like the other Vee components, errors are shown after a value change or on submit.