-
Notifications
You must be signed in to change notification settings - Fork 1
/
MultiSearchField.vue
89 lines (80 loc) · 2 KB
/
MultiSearchField.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<script setup lang="ts">
import { Location } from '@/models/location'
import { ref } from 'vue'
import locationData from '@/mock/location.json'
const locations = [
{
region: 'America',
cities: locationData.america,
},
{
region: 'Europ',
cities: locationData.europ,
},
{
region: 'Asia',
cities: locationData.asia,
},
]
const locationList = ref<Location[]>(locations)
const selectedValue = ref<Location>()
const menu = ref(false)
const search = ref('')
const searchItem = (value: string) => {
search.value = value
const filteredLocations = locations.map((location) => {
const filteredCities = location.cities.filter((city) =>
city.name.toLowerCase().includes(value.toLowerCase())
)
return { ...location, cities: filteredCities }
})
locationList.value = filteredLocations
}
const selectItem = (value: Location) => {
selectedValue.value = value
menu.value = false
search.value = ''
locationList.value = locations
}
</script>
<template>
<v-row class="h-100 ma-0">
<v-col cols="4">
<p class="text-h6">VAutocomplete field for</p>
<p class="text-h6"><b>Multi Search functionality</b></p>
</v-col>
<v-divider vertical></v-divider>
<v-col cols="8">
<v-autocomplete
label="Mulit Search"
variant="solo-filled"
chips
no-filter
:items="locationList"
item-title="region"
:menu="menu"
:search="search"
v-model="selectedValue"
@update:menu="(val: boolean) => (menu = val)"
@update:search="searchItem"
>
<template v-slot:chip="{ item }">
<span>{{ item.value.name }}</span>
</template>
<template v-slot:item="{ item }">
<v-list class="my-n4">
<v-list-item-title class="bg-primary pa-3">
{{ item.title }}
</v-list-item-title>
<v-list-item
v-for="option in item.raw.cities"
@click="() => selectItem(option)"
>{{ option.name }}</v-list-item
>
</v-list>
</template>
</v-autocomplete>
</v-col>
</v-row>
</template>
<style scoped></style>