Skip to content

Commit

Permalink
feat: add isEmpty to useSelect
Browse files Browse the repository at this point in the history
  • Loading branch information
abichinger committed Nov 6, 2023
1 parent 54664bb commit 3ea62ba
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions core/src/components/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ export function useSelect<T, V>(options: SelectOptions<T, V>) {
selectedStr.value = items.map(getText).join(',')
})

const isEmpty = computed(() => {
return multiple
? !Array.isArray(selected.value) || selected.value.length == 0
: !!selected.value
})

return {
...s,
select,
Expand All @@ -163,6 +169,7 @@ export function useSelect<T, V>(options: SelectOptions<T, V>) {
itemRows: splitArray(items, cols),
setItems,
setValues,
isEmpty,
}
}

Expand Down Expand Up @@ -199,20 +206,14 @@ export const RenderlessSelect = defineComponent({
{ immediate: true },
)

const isEmpty = computed(() => {
return props.multiple
? !Array.isArray(s.selected.value) || s.selected.value.length == 0
: !!s.selected.value
})

return () => {
const slotProps = {
selectedStr: props.selection || s.selectedStr.value,
modelValue: props.modelValue,
items: props.items,
select: s.select,
isSelected: s.has,
clearable: props.clearable && !isEmpty.value,
clearable: props.clearable && !s.isEmpty.value,
clear: s.clear,
cols: props.cols,
rows: s.itemRows.length,
Expand Down

0 comments on commit 3ea62ba

Please sign in to comment.