-
Notifications
You must be signed in to change notification settings - Fork 624
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(SelectMenu): allow creating option despite search (#1080)
* chore: initial * chore: use reusable vnode * fix: use component with vnode * chore: option placement * chore: finish * up * up * up * fix(selectmenu): non-object custom options * up --------- Co-authored-by: Benjamin Canac <[email protected]>
- Loading branch information
1 parent
23770d8
commit 0fdc8f7
Showing
5 changed files
with
96 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
docs/components/content/examples/SelectMenuExampleCreatableAlways.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<script setup> | ||
const options = ref([ | ||
{ id: 1, name: 'bug' }, | ||
{ id: 2, name: 'documentation' }, | ||
{ id: 3, name: 'duplicate' }, | ||
{ id: 4, name: 'enhancement' }, | ||
{ id: 5, name: 'good first issue' }, | ||
{ id: 6, name: 'help wanted' }, | ||
{ id: 7, name: 'invalid' }, | ||
{ id: 8, name: 'question' }, | ||
{ id: 9, name: 'wontfix' } | ||
]) | ||
const selected = ref([]) | ||
const labels = computed({ | ||
get: () => selected.value, | ||
set: async (labels) => { | ||
const promises = labels.map(async (label) => { | ||
if (label.id) { | ||
return label | ||
} | ||
// In a real app, you would make an API call to create the label | ||
const response = { | ||
id: options.value.length + 1, | ||
name: label.name | ||
} | ||
options.value.push(response) | ||
return response | ||
}) | ||
selected.value = await Promise.all(promises) | ||
} | ||
}) | ||
</script> | ||
|
||
<template> | ||
<USelectMenu | ||
v-model="labels" | ||
by="id" | ||
name="labels" | ||
:options="options" | ||
option-attribute="name" | ||
multiple | ||
searchable | ||
creatable | ||
show-create-option-when="always" | ||
placeholder="Select labels" | ||
/> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0fdc8f7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
ui – ./
ui-git-dev-nuxt-js.vercel.app
ui.nuxt.com
ui-nuxt-js.vercel.app