Components/Select

Select

A control for choosing one or more values from a dropdown list.

VerifiedSince 0.3.4

Usage

Basic

Loading demo...

Local Filtering

searchable renders a search field in the panel that filters registered option labels.

Loading demo...

Pair remote with editable: the trigger becomes editable and typing emits search while the panel is open. Show pending results with loading.

Loading demo...

Multiple Tags

With multiple, v-model is an array; clicking an option toggles it and keeps the panel open.

Loading demo...

Inline Creation

With allowCreate, Enter or the footer button emits create from the current input and selects the new value.

Loading demo...

options accepts { label, options } groups; the footer slot holds add buttons, helper text, or shortcuts.

Loading demo...

Icons and Descriptions

Options can carry an icon (a class resolved by the host app's styles) and a second-line description.

Loading demo...

Status Border

status only draws the border; keep validation messages in the form item.

Loading demo...

Disabled

Disable the whole select when the value is read-only; disable a single TuffSelectItem to keep an unavailable choice in the list.

Loading demo...
Loading demo...

Scrolling Panel

dropdownMaxHeight caps the panel height; on open, the selected item scrolls into view.

Loading demo...

Width

The trigger defaults to 240px and the panel always matches it; set a width on the component to change both.

Loading demo...

Best Practices

  • Use options for data-driven lists and TuffSelectItem for a few static items with inline markup; don't mix the two.
  • Name a single select with an adjacent <label for> and id, or aria-label; name a multiple select with aria-label / aria-labelledby. Don't wrap the select in a label.
  • Keep remote requests in the host and limit them with searchDebounce.
  • To show a created option again, add it to your own options in the create handler.
  • Match modelValue to multiple: a scalar for single, an array for multiple.

API Reference

TuffSelect

Props

PropTypeDefaultDescription
modelValue / v-modelstring | number | Array<string | number>''Selected value; an array with multiple.
placeholderstring'Please select'Trigger placeholder when nothing is selected.
disabledbooleanfalseDisables the trigger, closes the panel, and blocks selection.
multiplebooleanfalseMultiple selection, shown as tags.
status'default' | 'error' | 'warning''default'Validation border state.
eagerbooleantrueMounts the panel up front so slot options register reliably.
optionsTxSelectOptionLike[][]Plain or grouped options.
maxTagCountnumber-Maximum visible tags; the rest collapse into + N ....
maxTagTextLengthnumber-Maximum tag text length before truncation.
searchablebooleanfalseShows a local search field in the panel when not editable.
searchPlaceholderstring'Search'Placeholder of the panel search field.
editablebooleanfalseMakes the trigger text editable as the query and opens on focus.
remotebooleanfalseEditable remote mode; emits search while the panel is open.
allowCreatebooleanfalseAllows creating an option from the current input.
createTextstring'Add item'Label of the default create button.
loadingbooleanfalseShows the loading state.
loadingTextstring'Loading...'Default loading text.
emptyTextstring'No results'Default empty text.
searchDebouncenumber0Debounce of the remote search, in milliseconds.
dropdownMaxHeightnumber280Maximum panel list height in pixels.
dropdownOffsetnumber6Distance between the panel and the trigger.
contentPaddingnumber8Spacing inside the panel.
optionPaddingnumber0Horizontal inset compensation for options.
animationBaseAnchorAnimationOptions-Animation options forwarded to Popover / BaseAnchor.
panelVariant'solid' | 'dashed' | 'plain''solid'Panel surface style.
panelBackground'pure' | 'mask' | 'blur' | 'glass' | 'refraction''refraction'Panel background.
panelShadow'none' | 'soft' | 'medium''soft'Panel shadow strength.
panelRadiusnumber18Panel corner radius.
panelPaddingnumber0Panel padding.
panelCardBaseAnchorPanelCardProps-Card overrides forwarded to the panel.

Events

EventParamsDescription
update:modelValue(value: string | number | Array<string | number>)Fires after a selection or clear; an array with multiple.
change(value: string | number | Array<string | number>)Fires together with update:modelValue.
search(query: string)In remote mode, fires when the input text changes while the panel is open.
create(option: TxSelectOption)Fires when allowCreate creates an option from the input.

Slots

SlotPropsDescription
default-Options declared with TuffSelectItem (legacy form).
option{ option, selected }Content of one option in options mode.
tag{ option, remove }Content of a selected tag.
group{ group }Group heading.
loading-Loading state.
empty-Empty state.
footer{ query, canCreate, create }Panel footer content.

Exposed Methods

MethodDescription
open()Opens the panel.
close()Closes the panel.
toggle()Toggles the panel.
focus()Focuses the trigger input.
blur()Blurs the trigger input.
clear()Clears the value and selected label; emits '' in single mode, [] in multiple mode.

TuffSelectItem

Props

PropTypeDefaultDescription
valuestring | number-Value written to the select when picked.
labelstring-Displayed and selected-state text; defaults to the slot text.
disabledbooleanfalseCan't be picked but stays in the list.
iconstring-Class of the leading icon, resolved by the host app's styles.
descriptionstring-Secondary text under the label.

Slots

SlotPropsDescription
default-Title content of the option row; falls back to label, then the value.

Types

EXAMPLE.TS
type TxSelectValue = string | number

interface TxSelectOption {
  value: TxSelectValue
  label: string
  disabled?: boolean
  icon?: string
  description?: string
}

interface TxSelectOptionGroup {
  label: string
  disabled?: boolean
  options: TxSelectOption[]
}

type TxSelectOptionLike = TxSelectOption | TxSelectOptionGroup

Overview

  • When options is set it renders the list, and TuffSelectItem registers only without it. A missing label falls back to the slot text, then the raw value.
  • In non-editable mode, clicking the trigger toggles the panel; with editable or remote, focus opens it.
  • A single select closes after an enabled option is picked; a multiple select stays open.
  • searchable filters locally only when not editable; remote turns local filtering off and emits search only while the panel is open.
  • A value passed before its options mount gets its label once they register; finite numeric strings and numbers match by numeric value.
  • The trigger is a combobox (aria-haspopup="listbox", aria-expanded), the list a listbox (aria-multiselectable with multiple), and each option an option with aria-selected. id and accessible names land on the actual combobox; class and style stay on the root.

Technologies

  • The panel renders through Popover; TuffSelectItem registers its value and label with the parent through injection.
  • Source: packages/tuffex/packages/components/src/select/; exports TuffSelect and TuffSelectItem (aliases TxSelect, TxSelectItem) and the public types.
查看源码
packages/tuffex/packages/components/src/select/index.ts