Skip to content

Select

When there are plenty of options, use a drop-down menu to display and select desired ones.

Basic Usage

v-model is the value of tu-select-option that is currently selected.

Disabled Option

Set disabled of tu-select to make it disabled.

Multiple Select

By setting multiple, the selector can support multiple selection. In addition, the maximum number of tags displayed can be set by max-tag-count.

Please select
Please select

Allow Clear

By setting allow-clear, the clear button is displayed.

Please select

Loading

Select boxes and drop-down menus show loading status.

custom dropdown menu header.

Please select

custom dropdown menu footer.

Allow Create

By setting allow-create, the selector can create items that do not exist in the options.

Please select

By setting allow-search, you can make the selector support searching for options, and you can customize the search with filter-option.

By setting monitor the scroll event of the drop-down menu through dropdown-scroll. Or use dropdown-reach-bottom to monitor the event of the drop-down menu scrolling to the bottom.

Use the search event to search remotely and change options.

Group

Use the tu-select-group component to add grouping options.

Please select

Custom Label

The display content of the select box can be customized through the #label slot.

Linkage Select

Show how to realize the linkage selection box.

Option 1-1

Custom Field Names

The format of the data in options can be customized through the field-names attribute.

Option1

Virtual List

How to use the virtual list.

Sizes

Besides default size, tu-select component provides three additional sizes for you to choose among different scenarios. Use attribute size to set additional sizes with mini, small, large.

Please select

Select API

Select Attributes

NameDescriptionTypeDefault
multipleWhether to open multi-select mode (The search is turned on by default in the multi-select mode))Booleanfalse
model-value/v-modelValueString Number Boolean Object-
default-valueDefault value (uncontrolled mode)String Number Boolean Object-
input-valueThe value of the inputString-
default-input-valueThe default value of the input (uncontrolled mode)String''
sizeThe size of the selectStringmedium
placeholderPlaceholderString-
loadingWhether it is loading stateBooleanfalse
disabledWhether to disableBooleanfalse
allow-clearWhether to allow clearBooleanfalse
allow-searchWhether to allow searchBoolean Objectfalse (single) | true (multiple)
allow-createWhether to allow creationBooleanfalse
max-tag-countIn multi-select mode, the maximum number of labels displayed. 0 means unlimitedNumber0
popup-containerMount container for popupString HTMLElement-
default-active-first-optionWhether to select the first option by default when there is no valueBooleantrue
popup-visibleWhether to show the dropdownBoolean-
default-popup-visibleWhether the popup is visible by default (uncontrolled mode)Booleanfalse
unmount-on-closeWhether to destroy the element when the dropdown is closedBooleanfalse
filter-optionWhether to filter optionsBoolean Functiontrue
optionsOption dataArray[]
virtual-list-propsPass the virtual list attribute, pass in this parameter to turn on virtual scrolling VirtualListPropsVirtualListProps-
trigger-propsTrigger props of the drop-down menuTriggerProps-
format-labelFormat display contentFunction-
show-extra-optionsOptions that do not exist in custom valuesBooleantrue
value-keyUsed to determine the option key value attribute nameStringvalue
search-delayDelay time to trigger search eventNumber500
limitMaximum number of choices in multiple choiceNumber0
field-namesCustomize fields in SelectOptionDataSelectFieldNames-
scrollbarWhether to enable virtual scroll barBoolean ScrollbarPropstrue
show-header-on-emptyWhether to display the header in the empty statebooleanfalse
show-footer-on-emptyWhether to display the footer in the empty statebooleanfalse

Select Events

NameDescriptionType
changeTriggered when the value changesFunction
input-value-changeTriggered when the value of the input changesFunction
popup-visible-changeTriggered when the display state of the drop-down box changesFunction
clearTriggered when the clear button is clicked-
removeTriggered when the delete button of the label is clickedFunction
searchTriggered when the user searchesFunction
dropdown-scrollTriggered when the drop-down scrolls-
dropdown-reach-bottomTriggered when the drop-down menu is scrolled to the bottom-
exceed-limitTriggered when multiple selection exceeds the limitFunction

Select Slots

NameDescriptionType
triggerCustom trigger element-
prefixPrefix-
search-iconSearch icon for select box-
loading-iconLoading icon for select box-
arrow-iconArrow icon for select box-
footerThe footer of the drop-down box-
headerThe header of the drop-down box-
labelDisplay content of labeldata: SelectOptionData
optionDisplay content of optionsdata: SelectOptionData
emptyDisplay content when the option is empty-

Select Option Attributes

NameDescriptionTypeDefault
valueOption value (if not filled, it will be obtained from the content)StringNumberBooleanObject-
labelOption label (if not filled, it will be obtained from the content)String-
disabledWhether to disableBooleanfalse
tag-propsDisplayed tag attributesTagProps-
extraExtra dataObject-
indexIndex for manually specifying optionNumber-

Select Group Attributes

NameDescriptionTypeDefault
labelTitle of option groupstring-

Select Group Slots

NameDescriptionType
labelTitle of option group-

Type

ts
type Option = string | number | SelectOptionData | SelectOptionGroup;

type FilterOption = boolean | ((inputValue: string, option: SelectOptionData) => boolean);
type Option = string | number | SelectOptionData | SelectOptionGroup;

type FilterOption = boolean | ((inputValue: string, option: SelectOptionData) => boolean);

SelectOptionData

NameDescriptionTypeDefault
valueOption ValueStringNumberBooleanRecord-
labelOption contentString-
disabledWhether to disableBooleanfalse
tagPropsProps of the multi-select label corresponding to the optionany-
renderCustom renderRenderFunction-

SelectOptionGroup

NameDescriptionTypeDefault
isGroupWhether it is an option groupBoolean-
labelOption group titleString-
optionsOptions in the option groupArray-

VirtualListProps

NameDescriptionTypeDefault
heightViewable area heightStringNumber-
thresholdThe threshold of the number of elements to enable virtual scrolling. When the number of data is less than the threshold, virtual scrolling will not be enabled.Number-
fixedSizeIs the element height fixed.Booleanfalse
estimatedSizeIs the element height fixed.Number-
bufferThe number of elements mounted in advance outside the boundary of the viewport.Number10

FAQ

Use Object format as option value

When using the Object format as the value of the option, you need to specify the field name to obtain the unique identifier for the selector through the value-key attribute, and the default value is value. In addition, the object value of value needs to be defined in setup, and the object cannot be created in the template, which will lead to repeated rendering of the Option component.

For example, when I need to specify key as a unique identifier:

vue
<template>
  <tu-select v-model="value" placeholder="Please select" value-key="key">
    <tu-select-option v-for="item of data" :value="item" :label="item.label" />
  </tu-select>
</template>

<script setup>
import { ref } from 'vue';

const value = ref();
const options = [
  {
    value: 'option1',
    label: 'option1',
    key: 'extra1'
  },
  {
    value: 'option2',
    label: 'option2',
    key: 'extra3'
  },
  {
    value: 'option3',
    label: 'option3',
    key: 'extra3'
  },
]
</script>
<template>
  <tu-select v-model="value" placeholder="Please select" value-key="key">
    <tu-select-option v-for="item of data" :value="item" :label="item.label" />
  </tu-select>
</template>

<script setup>
import { ref } from 'vue';

const value = ref();
const options = [
  {
    value: 'option1',
    label: 'option1',
    key: 'extra1'
  },
  {
    value: 'option2',
    label: 'option2',
    key: 'extra3'
  },
  {
    value: 'option3',
    label: 'option3',
    key: 'extra3'
  },
]
</script>

The Select component does not enable the container scrolling event monitoring function by default. If you encounter the problem of separating the drop-down menu in the scrolling container, you can manually enable the updateAtScroll function of the internal Trigger component.

If this is the case in the global environment, you can use the ConfigProvider component to enable this property by default.

vue
<tu-select :trigger-props="{updateAtScroll:true}"></tu-select>
<tu-select :trigger-props="{updateAtScroll:true}"></tu-select>