Skip to content

USelectMenu create-item="always" not working #3949

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
projct1 opened this issue Apr 21, 2025 · 6 comments
Closed

USelectMenu create-item="always" not working #3949

projct1 opened this issue Apr 21, 2025 · 6 comments
Labels
bug Something isn't working v3 #1289

Comments

@projct1
Copy link

projct1 commented Apr 21, 2025

Environment

Is this bug related to Nuxt or Vue?

Nuxt

Version

Nuxt UI version 3.0.2

Reproduction

<script setup lang="ts">
const model = defineModel()

const query = ref('')
const items = ref([])

const isOpen = ref(false)
const isLoading = ref(false)

const search = useDebounceFn(async () => {
  if (query.value.length > 1) {
    isLoading.value = true

    items.value = (await fetchApi('categories?q=' + query.value)).data

    isLoading.value = false
  }
}, 250)

function create(name) {
  model.value = { name: name.trim() }

  query.value = ''
  isOpen.value = false
}
</script>

<template>
  <USelectMenu v-model="model"
               v-model:open="isOpen"
               v-model:search-term="query"
               :items="items"
               :loading="isLoading"
               label-key="name"
               create-item="always"
               @create="create"
               @update:search-term="search" />
</template>

Description

I want to create new category "Des", but cant, because i found "Deserts".
Option create-item="always" ignored.

Demonstration: https://skr.sh/vVFQ3lvSifh

@projct1 projct1 added bug Something isn't working triage v3 #1289 labels Apr 21, 2025
@projct1 projct1 changed the title InputMenu create-item="always" not working USelectMenu create-item="always" not working Apr 21, 2025
Copy link
Member

I just tried the create-item="always" prop and it works as expected. Would you mind sharing a working reproduction?

@projct1
Copy link
Author

projct1 commented Apr 22, 2025

https://codesandbox.io/p/devbox/dawn-wind-hdn7pj

How i can create new item "Appl"?
Its just clumsy example :P

According to documentation:

The create option shows when no match is found by default. Set it to always to show it even when similar values exist.

So, in my example, similar values exist (starts with "Apple"), but creat option 'Create "Appl"' not shown =\

Copy link
Member

Thanks for the reproduction, I found the issue 😊

BTW unrelated to the issue but here's another approach to implement debounce search:

<script setup lang="ts">
const q = ref('')
const qDebounced = refDebounced(q, 250)

const { data: items, status } = await useFetch('https://dummyjson.com/products/search', {
  params: {
    q: qDebounced
  },
  transform: (data) => {
    return data.products
  },
  lazy: true
})
...
</script>

@projct1
Copy link
Author

projct1 commented Apr 23, 2025

Oh, thanks, that looks concise)

@projct1
Copy link
Author

projct1 commented Apr 25, 2025

By the way, how i can trigger fetch only if query length > 1?

@projct1
Copy link
Author

projct1 commented Apr 25, 2025

@benjamincanac Hey, i guess we don't need to show the create item if the dropdown already has exactly the item we want, otherwise we'll create a duplicate?

Updated: https://codesandbox.io/p/sandbox/dawn-wind-hdn7pj
Video: https://skrinshoter.ru/vVJAaKXxRWR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working v3 #1289
Projects
None yet
Development

No branches or pull requests

2 participants