feat: filterable autocomplete

This commit is contained in:
Shariq Ansari 2023-11-13 23:42:22 +05:30
parent f0fae04018
commit e9bbd2fba7
2 changed files with 32 additions and 9 deletions

View File

@ -10,6 +10,7 @@
:size="attrs.size || 'sm'"
:variant="attrs.variant"
:placeholder="attrs.placeholder"
:filterable="false"
>
<template #target="{ open, togglePopover }">
<slot name="target" v-bind="{ open, togglePopover }" />

View File

@ -121,14 +121,36 @@ import {
import { Popover, Button, FeatherIcon } from 'frappe-ui'
import { ref, computed, useAttrs, useSlots, watch, nextTick } from 'vue'
const props = defineProps([
'modelValue',
'options',
'placeholder',
'variant',
'size',
'disabled',
])
const props = defineProps({
modelValue: {
type: String,
default: '',
},
options: {
type: Array,
default: () => [],
},
size: {
type: String,
default: 'md',
},
variant: {
type: String,
default: 'subtle',
},
placeholder: {
type: String,
default: '',
},
disabled: {
type: Boolean,
default: false,
},
filterable: {
type: Boolean,
default: true,
},
})
const emit = defineEmits(['update:modelValue', 'update:query', 'change'])
const query = ref('')
@ -170,7 +192,7 @@ const groups = computed(() => {
key: i,
group: group.group,
hideLabel: group.hideLabel || false,
items: filterOptions(group.items),
items: props.filterable ? filterOptions(group.items) : group.items,
}
})
.filter((group) => group.items.length > 0)