feat(SelectMenu): handle async search (#426)

Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
Marc-Olivier Castagnetti
2023-07-18 15:58:16 +02:00
committed by GitHub
parent 46b444a3e0
commit 5f8fe8559f
3 changed files with 76 additions and 10 deletions

View File

@@ -149,6 +149,40 @@ props:
---
::
### Async search
Pass a function to the `searchable` prop to customize the search behavior and filter options according to your needs. The function will receive the query as its first argument and should return an array.
Use the `debounce` prop to adjust the delay of the function.
::component-example
#default
:select-menu-example-async-search{class="max-w-[12rem] w-full"}
#code
```vue
<script setup>
const search = async (q) => {
const users = await $fetch('https://jsonplaceholder.typicode.com/users', { params: { q } })
return users.map(user => ({ id: user.id, label: user.name, suffix: user.email })).filter(Boolean)
}
const selected = ref([])
</script>
<template>
<USelectMenu
v-model="selected"
:searchable="search"
placeholder="Search for a user..."
multiple
by="id"
/>
</template>
```
::
## Slots
### `label`