Skip to content

Commit 846a2a6

Browse files
authored
feat(select): support filterable (#1945)
* feat(select): support filterable * refactor: update
1 parent 4f822db commit 846a2a6

16 files changed

Lines changed: 427 additions & 43 deletions

File tree

packages/varlet-ui/src/form/__tests__/__snapshots__/index.spec.js.snap

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,17 +248,20 @@ exports[`form with select 1`] = `
248248
"<form class="var-form">
249249
<div class="var-select">
250250
<div class="var-menu var--box var-select__menu" var-select-cover="">
251-
<div class="var-field-decorator var--box var-field-decorator--standard">
251+
<div class="var-field-decorator var--box var-field-decorator--standard var-field-decorator--disabled">
252252
<div class="var-field-decorator__controller var-field-decorator--disabled" style="cursor: pointer; overflow: visible; --field-decorator-middle-offset-left: 0px; --field-decorator-middle-offset-width: 0px; --field-decorator-middle-offset-height: 0px;">
253253
<div class="var-field-decorator__icon"></div>
254254
<div class="var-field-decorator__middle">
255255
<div class="var-select__select var-select--disabled" style="text-align: left;">
256256
<div class="var-select__label">
257257
<div class="var-select__chips">
258258
<transition-stub name="var-fade" appear="false" persisted="false" css="true"><span class="var-chip var--box var-chip--small var--inline-flex var-chip--default var-chip--round var-select__chip" var-select-cover=""><span class="var-chip__text-small"><span>option1</span></span><span class="var-chip--close"><i class="var-icon var-icon--set var-icon-close-circle" style="transition-duration: 0ms;"></i></span></span></transition-stub>
259+
<!--v-if-->
259260
</div>
260261
</div>
261262
<!--v-if-->
263+
<!--v-if-->
264+
<!--v-if-->
262265
</div>
263266
</div>
264267
<!--v-if-->
@@ -290,9 +293,12 @@ exports[`form with select 2`] = `
290293
<div class="var-select__label">
291294
<div class="var-select__chips">
292295
<transition-stub name="var-fade" appear="false" persisted="false" css="true"><span class="var-chip var--box var-chip--small var--inline-flex var-chip--default var-chip--round var-select__chip" var-select-cover=""><span class="var-chip__text-small"><span>option1</span></span><span class="var-chip--close"><i class="var-icon var-icon--set var-icon-close-circle" style="transition-duration: 0ms;"></i></span></span></transition-stub>
296+
<!--v-if-->
293297
</div>
294298
</div>
295299
<!--v-if-->
300+
<!--v-if-->
301+
<!--v-if-->
296302
</div>
297303
</div>
298304
<!--v-if-->

packages/varlet-ui/src/option/Option.vue

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<template>
22
<div
3+
v-show="visible"
34
ref="root"
45
v-ripple="{ disabled: disabled || !ripple }"
56
v-hover:desktop="handleHovering"
@@ -47,6 +48,7 @@ import VarCheckbox from '../checkbox'
4748
import Hover from '../hover'
4849
import VarHoverOverlay, { useHoverOverlay } from '../hover-overlay'
4950
import Ripple from '../ripple'
51+
import { SelectOption } from '../select/props'
5052
import { createNamespace, MaybeVNode } from '../utils/components'
5153
import { props } from './props'
5254
import { OptionProvider, useSelect } from './provide'
@@ -66,26 +68,25 @@ export default defineComponent({
6668
const root = ref<HTMLElement>()
6769
const isFocusing = ref(false)
6870
const optionSelected = ref(false)
71+
const option = computed(
72+
() =>
73+
props.option ??
74+
({
75+
label: props.label,
76+
value: props.value,
77+
disabled: props.disabled,
78+
} as SelectOption),
79+
)
6980
const selected = computed(() => optionSelected.value)
7081
const value = computed<any>(() => props.value)
7182
const disabled = computed(() => props.disabled)
7283
const ripple = computed(() => props.ripple)
7384
const { select, bindSelect } = useSelect()
74-
const { multiple, focusColor, onSelect, computeLabel } = select
85+
const { query, filter, filterable, multiple, focusColor, onSelect, computeLabel } = select
7586
const { hovering, handleHovering } = useHoverOverlay()
7687
77-
const labelVNode = computed(() =>
78-
isFunction(props.label)
79-
? props.label(
80-
props.option ?? {
81-
label: props.label,
82-
value: props.value,
83-
disabled: props.disabled,
84-
},
85-
optionSelected.value,
86-
)
87-
: props.label,
88-
)
88+
const labelVNode = computed<any>(() => (isFunction(props.label) ? option.value : props.label))
89+
const visible = computed(() => !filterable.value || !query.value || filter.value(query.value, option.value))
8990
9091
const optionProvider: OptionProvider = {
9192
label: labelVNode,
@@ -151,6 +152,7 @@ export default defineComponent({
151152
return {
152153
root,
153154
optionSelected,
155+
visible,
154156
multiple,
155157
focusColor,
156158
hovering,

0 commit comments

Comments
 (0)