Skip to content

Commit 3ea62ba

Browse files
committed
feat: add isEmpty to useSelect
1 parent 54664bb commit 3ea62ba

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

core/src/components/select.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ export function useSelect<T, V>(options: SelectOptions<T, V>) {
155155
selectedStr.value = items.map(getText).join(',')
156156
})
157157

158+
const isEmpty = computed(() => {
159+
return multiple
160+
? !Array.isArray(selected.value) || selected.value.length == 0
161+
: !!selected.value
162+
})
163+
158164
return {
159165
...s,
160166
select,
@@ -163,6 +169,7 @@ export function useSelect<T, V>(options: SelectOptions<T, V>) {
163169
itemRows: splitArray(items, cols),
164170
setItems,
165171
setValues,
172+
isEmpty,
166173
}
167174
}
168175

@@ -199,20 +206,14 @@ export const RenderlessSelect = defineComponent({
199206
{ immediate: true },
200207
)
201208

202-
const isEmpty = computed(() => {
203-
return props.multiple
204-
? !Array.isArray(s.selected.value) || s.selected.value.length == 0
205-
: !!s.selected.value
206-
})
207-
208209
return () => {
209210
const slotProps = {
210211
selectedStr: props.selection || s.selectedStr.value,
211212
modelValue: props.modelValue,
212213
items: props.items,
213214
select: s.select,
214215
isSelected: s.has,
215-
clearable: props.clearable && !isEmpty.value,
216+
clearable: props.clearable && !s.isEmpty.value,
216217
clear: s.clear,
217218
cols: props.cols,
218219
rows: s.itemRows.length,

0 commit comments

Comments
 (0)