﻿# nf-virtual-select {#virtual-select}

Standard/virtual select supporting single/multiple selection, select-all, aliases, keyword highlighting, comma-separated exact matches, remote filters, option slots and scroll methods.

## Examples {#examples}

### Event and property configuration: method one {#example-1}

### Event and property configuration: method one
```vue
<template>
  <NfConfigProvider theme="chalk" locale="en-US">
<div class='nf-virtual-select-demo'>
    <div class="select-demo">
  <div class="select-demo-result"><pre>{{ area.province }}</pre></div>
  <div class="select-demo-controls">
<NfVirtualSelect
       v-model="area.province"
       :placeholder="'Select a province'"
       virtual-list
       multiple
       style='width: 227px'
       :clearable="true"
       @change='changeData'
       @visible-change='visibleChange'
       @remove-tag='removeTag'
       @clear='clear'
       @focus='focus'
       size='mini'
       @scroll='scroll'
       @totop='totop'
       @tobottom='tobottom'
       @resized='resized'

       :options="[
        ...provinceList.map(item => {
           return {
             label: item.city_name,
             value: item.province_code,
             templateId: item.province_code
           }
         })
       ]"
    />
  </div>
</div>
  </div>
  </NfConfigProvider>
</template>

<script setup lang="ts">
import { computed, reactive } from 'vue'
import { NfConfigProvider, NfVirtualSelect } from '@94ai-plus/common-ui'

const area = reactive({
    province: []
  })

  const provinceList = Object.freeze([{"province_code":"110000","city_name":"北京市北京市北京市北京市北京市北京市北京市北京市北京市北京市天津市天津市天津市天津市天津市天津市天津市"},{"province_code":"120000","city_name":"天津市"},{"province_code":"130000","city_name":"河北省"},{"province_code":"140000","city_name":"山西省"},{"province_code":"150000","city_name":"内蒙古自治区"},{"province_code":"210000","city_name":"辽宁省"},{"province_code":"220000","city_name":"吉林省"},{"province_code":"230000","city_name":"黑龙江省"},{"province_code":"310000","city_name":"上海市"},{"province_code":"320000","city_name":"江苏省"},{"province_code":"330000","city_name":"浙江省"},{"province_code":"340000","city_name":"安徽省"},{"province_code":"350000","city_name":"福建省"},{"province_code":"360000","city_name":"江西省"},{"province_code":"370000","city_name":"山东省"},{"province_code":"410000","city_name":"河南省"},{"province_code":"420000","city_name":"湖北省"},{"province_code":"430000","city_name":"湖南省"},{"province_code":"440000","city_name":"广东省"},{"province_code":"450000","city_name":"广西壮族自治区"},{"province_code":"460000","city_name":"海南省"},{"province_code":"500000","city_name":"重庆市"},{"province_code":"510000","city_name":"四川省"},{"province_code":"520000","city_name":"贵州省"},{"province_code":"530000","city_name":"云南省"},{"province_code":"540000","city_name":"西藏自治区"},{"province_code":"610000","city_name":"陕西省"},{"province_code":"620000","city_name":"甘肃省"},{"province_code":"630000","city_name":"青海省"},{"province_code":"640000","city_name":"宁夏回族自治区"},{"province_code":"650000","city_name":"新疆维吾尔自治区"},{"province_code":"710000","city_name":"台湾省"},{"province_code":"810000","city_name":"香港特别行政区"},{"province_code":"820000","city_name":"澳门特别行政区"}])


  const changeData = (v) => {
    console.log('change' ,v)
  }
   const visibleChange = (v) => {
    console.log('visibleChange', v)
  }
   const removeTag = (v) => {
    console.log('removeTag', v)
  }
   const clear = (v) => {
    console.log('clear', v)
  }
  const focus = (v) => {
    console.log('focus', v)
  }
  const scroll = (v) => {
    console.log('scroll', v)
  }
  const totop = (v) => {
    console.log('totop', v)
  }
  const tobottom = (v) => {
    console.log('tobottom', v)
  }
  const resized = (v) => {
    console.log('resized', v)
  }
</script>

<style scoped>
.select-demo { display: flex; flex-direction: column; gap: 16px; max-width: 100%; }
.select-demo-result > pre { margin: 0; }
.select-demo-controls { display: flex; flex-direction: column; align-items: flex-start; gap: 16px; max-width: 100%; }
.select-demo-controls > * { max-width: 100%; }
</style>
```

### Event and property configuration: method two {#example-2}

### Event and property configuration: method two
```vue
<template>
  <NfConfigProvider theme="chalk" locale="en-US">
<div class='nf-virtual-select-demo'>
    <div class="select-demo">
  <div class="select-demo-result"><pre>{{ area.province }}</pre></div>
  <div class="select-demo-controls">
<NfVirtualSelect v-model="area.province" :item-options="optionTemplate" style='width: 227px' />
  </div>
</div>
  </div>
  </NfConfigProvider>
</template>

<script setup lang="ts">
import { computed, reactive } from 'vue'
import { NfConfigProvider, NfVirtualSelect } from '@94ai-plus/common-ui'

const area = reactive({
    province: []
  })

  const provinceList = Object.freeze([{"province_code":"110000","city_name":"北京市"},{"province_code":"120000","city_name":"天津市"},{"province_code":"130000","city_name":"河北省"},{"province_code":"140000","city_name":"山西省"},{"province_code":"150000","city_name":"内蒙古自治区"},{"province_code":"210000","city_name":"辽宁省"},{"province_code":"220000","city_name":"吉林省"},{"province_code":"230000","city_name":"黑龙江省"},{"province_code":"310000","city_name":"上海市"},{"province_code":"320000","city_name":"江苏省"},{"province_code":"330000","city_name":"浙江省"},{"province_code":"340000","city_name":"安徽省"},{"province_code":"350000","city_name":"福建省"},{"province_code":"360000","city_name":"江西省"},{"province_code":"370000","city_name":"山东省"},{"province_code":"410000","city_name":"河南省"},{"province_code":"420000","city_name":"湖北省"},{"province_code":"430000","city_name":"湖南省"},{"province_code":"440000","city_name":"广东省"},{"province_code":"450000","city_name":"广西壮族自治区"},{"province_code":"460000","city_name":"海南省"},{"province_code":"500000","city_name":"重庆市"},{"province_code":"510000","city_name":"四川省"},{"province_code":"520000","city_name":"贵州省"},{"province_code":"530000","city_name":"云南省"},{"province_code":"540000","city_name":"西藏自治区"},{"province_code":"610000","city_name":"陕西省"},{"province_code":"620000","city_name":"甘肃省"},{"province_code":"630000","city_name":"青海省"},{"province_code":"640000","city_name":"宁夏回族自治区"},{"province_code":"650000","city_name":"新疆维吾尔自治区"},{"province_code":"710000","city_name":"台湾省"},{"province_code":"810000","city_name":"香港特别行政区"},{"province_code":"820000","city_name":"澳门特别行政区"}])

  const optionTemplate = computed(()=> {
    return {
      size: 'mini',
      element: 'el-select',
      placeholder: 'Select a province',
      filterable: true,
      multiple: true,
      clearable: true,
      collapseTags: false,
      virtualList: true,
      options: [
        ...provinceList.map(item => {
          return {
            label: item.city_name,
            value: item.province_code,
            templateId: item.province_code
          }
        })
      ],
      events:{
        change: (v)=>{
          console.log('change', v)
        },
        focus: (v)=>{
          console.log('focus', v)
        },
        scroll: (v)=>{
          console.log('scroll', v)
        },
        totop: (v)=>{
          console.log('totop', v)
        },
        tobottom: (v)=>{
          console.log('tobottom', v)
        },
        resized: (v)=>{
          console.log('resized', v)
        },
        'visible-change': (v)=>{
          console.log('visibleChange', v)
        },
        'remove-tag': (v)=>{
          console.log('removeTag', v)
        },
      }
    }
  })
</script>

<style scoped>
.select-demo { display: flex; flex-direction: column; gap: 16px; max-width: 100%; }
.select-demo-result > pre { margin: 0; }
.select-demo-controls { display: flex; flex-direction: column; align-items: flex-start; gap: 16px; max-width: 100%; }
.select-demo-controls > * { max-width: 100%; }
</style>
```

### Keyword highlighting {#example-3}

### Keyword highlighting
```vue
<template>
  <NfConfigProvider theme="chalk" locale="en-US">
<div class='nf-virtual-select-demo'>
    <div class="select-demo">
  <div class="select-demo-result"><pre>{{ area.province }}</pre></div>
  <div class="select-demo-controls">
<NfVirtualSelect v-model="area.province" reserve-keyword :item-options="optionTemplate" style='width: 227px' />
  </div>
</div>
  </div>
  </NfConfigProvider>
</template>

<script setup lang="ts">
import { computed, reactive } from 'vue'
import { NfConfigProvider, NfVirtualSelect } from '@94ai-plus/common-ui'

const area = reactive({
    province: []
  })

  const provinceList = Object.freeze([{"province_code":"110000","city_name":"北京市"},{"province_code":"120000","city_name":"天津市"},{"province_code":"130000","city_name":"河北省"},{"province_code":"140000","city_name":"山西省"},{"province_code":"150000","city_name":"内蒙古自治区"},{"province_code":"210000","city_name":"辽宁省"},{"province_code":"220000","city_name":"吉林省"},{"province_code":"230000","city_name":"黑龙江省"},{"province_code":"310000","city_name":"上海市"},{"province_code":"320000","city_name":"江苏省"},{"province_code":"330000","city_name":"浙江省"},{"province_code":"340000","city_name":"安徽省"},{"province_code":"350000","city_name":"福建省"},{"province_code":"360000","city_name":"江西省"},{"province_code":"370000","city_name":"山东省"},{"province_code":"410000","city_name":"河南省"},{"province_code":"420000","city_name":"湖北省"},{"province_code":"430000","city_name":"湖南省"},{"province_code":"440000","city_name":"广东省"},{"province_code":"450000","city_name":"广西壮族自治区"},{"province_code":"460000","city_name":"海南省"},{"province_code":"500000","city_name":"重庆市"},{"province_code":"510000","city_name":"四川省"},{"province_code":"520000","city_name":"贵州省"},{"province_code":"530000","city_name":"云南省"},{"province_code":"540000","city_name":"西藏自治区"},{"province_code":"610000","city_name":"陕西省"},{"province_code":"620000","city_name":"甘肃省"},{"province_code":"630000","city_name":"青海省"},{"province_code":"640000","city_name":"宁夏回族自治区"},{"province_code":"650000","city_name":"新疆维吾尔自治区"},{"province_code":"710000","city_name":"台湾省"},{"province_code":"810000","city_name":"香港特别行政区"},{"province_code":"820000","city_name":"澳门特别行政区"}])

  const optionTemplate = computed(()=> {
    return {
      size: 'mini',
      element: 'el-select',
      placeholder: 'Select a province',
      filterable: true,
      multiple: true,
      clearable: true,
      collapseTags: false,
      virtualList: true,
      keywordHighlight: true,
      options: [
        ...provinceList.map(item => {
          return {
            label: item.city_name,
            value: item.province_code,
            templateId: item.province_code
          }
        })
      ],
      events:{
        change: (v)=>{
          console.log('change', v)
        },
        focus: (v)=>{
          console.log('focus', v)
        },
        scroll: (v)=>{
          console.log('scroll', v)
        },
        totop: (v)=>{
          console.log('totop', v)
        },
        tobottom: (v)=>{
          console.log('tobottom', v)
        },
        resized: (v)=>{
          console.log('resized', v)
        },
        'visible-change': (v)=>{
          console.log('visibleChange', v)
        },
        'remove-tag': (v)=>{
          console.log('removeTag', v)
        },
      }
    }
  })
</script>

<style scoped>
.select-demo { display: flex; flex-direction: column; gap: 16px; max-width: 100%; }
.select-demo-result > pre { margin: 0; }
.select-demo-controls { display: flex; flex-direction: column; align-items: flex-start; gap: 16px; max-width: 100%; }
.select-demo-controls > * { max-width: 100%; }
</style>
```

## Props {#props}

Descriptions preserve common-ui semantics; defaults and signatures follow the current Vue 3 implementation. Compatibility props do not enable unsupported legacy rendering.

| Attribute | Description | Type | Values | Default |
| --- | --- | --- | --- | --- |
| `modelValue / v-model (value)` | Bound value; value remains compatible; prefer v-model in Vue 3 | `SelectModelValue` | — | `undefined` |
| `tag` | Custom rendering tag; div or custom-select-dropdown displays an inline list | `string \| Component` | — | `'el-select'` |
| `keyValue` | Fields used for option label and value | `[string, string]` | — | `['label', 'value']` |
| `options` | List of selectable options | `SelectOption[]` | — | `[]` |
| `itemOptions` | Configure list properties and events together; event names accept kebab-case or camelCase | `Record<string, unknown>` | — | `{}` |
| `virtualList` | Enable virtual scrolling | `boolean` | — | `false` |
| `dataKey` | Unique virtual row key: field name or function | `string \| ((row: SelectOption) => string \| number)` | — | `'templateId'` |
| `dataComponent` | Custom option component receiving source, index and extraProps | `Component` | — | `undefined` |
| `estimateSize` | Estimated row height in px | `number` | — | `34` |
| `keeps` | Minimum inline virtual window; dropdown virtualization is managed by SelectV2 | `number` | — | `30` |
| `height` | Scrollable list height | `string` | — | `'245px'` |
| `width` | Selector width | `string` | — | `'100%'` |
| `maxWidth` | Maximum selector width | `string` | — | `undefined` |
| `showTip` | Show option tooltip | `boolean` | — | `true` |
| `multiple` | Enable multiple selection | `boolean` | — | `false` |
| `selectAll` | Show select-all control | `boolean` | — | `false` |
| `keywordHighlight` | Highlight search keyword | `boolean` | — | `true` |
| `keywordLabelAlias` | Compatibility field; highlighting uses text nodes, without HTML injection | `string` | — | `'keywordHighlightLabel'` |
| `disabled` | Disable interaction | `boolean` | — | `Inherited configuration` |
| `size` | Input size; mini / medium map to small / default | `SelectSize` | `small / default / large / mini / medium` | `Inherited configuration` |
| `clearable` | Show the clear selection control | `boolean` | — | `false` |
| `collapseTags` | Collapse selected tags in multiple mode | `boolean` | — | `multiple` |
| `multipleLimit` | Maximum selected items; 0 means unlimited | `number` | — | `0` |
| `autocomplete` | Input autocomplete attribute | `string` | — | `'off'` |
| `placeholder` | Input placeholder | `string` | — | `Locale configuration` |
| `loading` | Loading state | `boolean` | — | `false` |
| `loadingText` | Loading message | `string` | — | `Locale configuration` |
| `noMatchText` | No-match text; can use the empty slot | `string` | — | `Locale configuration` |
| `noDataText` | Empty list text; can use the empty slot | `string` | — | `Locale configuration` |
| `popperClass` | Dropdown CSS class | `string` | — | `undefined` |
| `popperAppendToBody` | Teleport dropdown to body; maps to Element Plus teleported | `boolean` | — | `true` |
| `start` | Initial inline scroll index | `number` | — | `0` |
| `offset` | Initial inline scroll offset in px | `number` | — | `0` |
| `direction` | Compatibility field; currently has no effect | `String` | `vertical` | `undefined` |
| `pageMode` | Compatibility field; currently has no effect | `boolean` | — | `undefined` |
| `topThreshold` | Top threshold for totop; may fire repeatedly | `number` | — | `0` |
| `bottomThreshold` | Bottom threshold for tobottom; may fire repeatedly | `number` | — | `0` |
| `rootTag` | Inline list root tag | `String` | — | `'div'` |
| `wrapTag` | Inline list wrapper tag | `String` | — | `'div'` |
| `wrapClass` | Compatibility field; currently has no effect | `String` | — | `undefined` |
| `wrapStyle` | Inline list wrapper style | `CSSProperties` | — | `undefined` |
| `itemTag` | Inline row wrapper tag | `String` | — | `'div'` |
| `itemClass` | Inline row CSS class | `String` | — | `undefined` |
| `itemClassAdd` | Extra row class function (index, row) | `(index: number, row: SelectOption) => string` | — | `undefined` |
| `itemStyle` | Inline row style | `CSSProperties` | — | `undefined` |
| `itemScopedSlots` | Compatibility field; currently has no effect | `Object` | — | `undefined` |
| `headerTag` | Compatibility field; currently has no effect | `String` | — | `undefined` |
| `headerClass` | Compatibility field; currently has no effect | `String` | — | `undefined` |
| `headerStyle` | Compatibility field; currently has no effect | `CSSProperties` | — | `undefined` |
| `footerTag` | Compatibility field; currently has no effect | `String` | — | `undefined` |
| `footerClass` | Compatibility field; currently has no effect | `String` | — | `undefined` |
| `footerStyle` | Compatibility field; currently has no effect | `CSSProperties` | — | `undefined` |
| `selectAllText` | Select-all label | `string` | — | `Locale configuration` |
| `reserveKeyword` | Keep the search keyword after selection | `boolean` | — | `true` |
| `filterable` | Enable searching | `boolean` | — | `false` |
| `filterMethod` | Custom filtering function | `(query: string) => void \| Promise<void>` | — | `undefined` |
| `remote` | Use remote filtering | `boolean` | — | `false` |
| `defaultFirstOption` | Select the first match on Enter | `boolean` | — | `false` |
| `allowCreate` | Allow new options; requires filterable | `boolean` | — | `false` |
| `automaticDropdown` | Open non-filterable select on focus | `boolean` | — | `false` |
| `name` | Native input name | `string` | — | `undefined` |
| `echoValueTop` | Move selected rows to top in virtual list | `boolean` | — | `true` |
| `extraProps` | Extra props passed to custom option component | `Record<string, unknown>` | — | `undefined` |
| `headeClass` | Compatibility field; currently has no effect | `string` | — | `undefined` |
| `beforeVisibleChange` | Post-visibility hook; return break to skip subsequent internal handling | `(visible: boolean) => void \| "break" \| "discard-cache" \| Promise<void \| "break" \| "discard-cache">` | — | `undefined` |
| `placement` | Dropdown placement | `SelectProps["placement"]` | — | `undefined` |

## Events {#events}

| Event | Description | Arguments |
| --- | --- | --- |
| `update:modelValue` | Selection changed; update v-model | `(value: SelectModelValue)` |
| `update:value` | Selection changed; compatibility event | `(value: SelectModelValue)` |
| `input` | Selection changed; compatibility event | `(value: SelectModelValue)` |
| `change` | Fires when selection changes | `(value: SelectModelValue)` |
| `focus` | Input gains focus | `(event: FocusEvent)` |
| `blur` | Input loses focus | `(event: FocusEvent)` |
| `clear` | Clear control activated | `()` |
| `remove-tag` | Tag removed in multiple mode | `(value: SelectValue)` |
| `visible-change` | Dropdown shown: true; hidden: false | `(visible: boolean)` |
| `select-item` | Option clicked; returns its value | `(value: SelectValue)` |
| `scroll` | List scroll; Event only, without the old range argument | `(event: Event)` |
| `totop` | List reaches top threshold | `(event?: Event)` |
| `tobottom` | List reaches bottom threshold | `(event?: Event)` |
| `resized` | List viewport measurement | `(id: string \| number, size: number)` |

## Slots {#slots}

| Slot | Description | Scope |
| --- | --- | --- |
| `default` | Below regular/inline list; use footer for virtual dropdown | — |
| `option` | Custom option content | `{ row: SelectOption, item: SelectOption, index: number }` |
| `header` | List header | — |
| `footer` | List footer | — |
| `prefix` | Input prefix | — |
| `empty` | Empty option list content | — |
| `loading` | Custom loading state | — |
| `tag` | Custom selected tags | `Element Plus tag slot props` |

## Exposed methods and state {#methods}

- `currentVal`
- `nfVirtualSelect`
- `virtualSelectList`
- `keyword`
- `selectArr`
- `optionsList`
- `config`
- `init()`
- `filterMethod(query)`
- `highLightFilterMethod(query)`
- `visibleChange(boolean)`
- `reset()`
- `scrollToBottom()`
- `scrollToIndex(index)`
- `scrollToOffset(offset)`
- `getSize()`
- `getClientSize()`
- `getScrollSize()`
- `updatePageModeFront()`
- `toggleCheckAll(boolean)`
- `focus()`
- `blur()`

## Migration notes {#migration}

Vue 3 uses `modelValue` / `update:modelValue`; legacy `value`, `update:value` and `input` remain available on selection components. The implementation uses public Element Plus APIs, not Element UI internals. `mini` maps to `small`; `medium` maps to `default`.

`virtualList` uses fixed-height vertical SelectV2 rows. Legacy horizontal / pageMode behavior is not supported. Root/wrap/item customization applies to the inline list only; use the exposed methods instead of private Element UI refs.
