Replies: 9 comments 14 replies
-
I am interested in this too. If this component is truly meant as an autocomplete component the user should be able to enter query that may not show up in the autocomplete suggestions dropdown. |
Beta Was this translation helpful? Give feedback.
-
Hey! Thank you for your suggestion! I'm not 100% sure what you mean. But is your goal to allow to let's say create a new record (based on the query) if it doesn't exist in a certain list? Is this what you mean? https://codesandbox.io/s/condescending-grass-konu6w?file=/src/App.js |
Beta Was this translation helpful? Give feedback.
-
I am interested in this as well. Basically a high-fidelity version of |
Beta Was this translation helpful? Give feedback.
-
I can get behind this, as well. I would be great if we can use ComboBox to simply show suggestions. The user would be free to use them or ignore them altogether. I understand there are use-cases for both scenarios (ie, sometimes you want to force the user to make a selection). |
Beta Was this translation helpful? Give feedback.
-
I implemented this by having an invisible "insert custom value" <script setup lang="ts">
const query = ref('')
// this can't return null because we need headlessui to pick always see it
const customValue = computed(() => (query.value === '' ? {} : { id: null, name: query.value }))
const updateValue = (value) => {
// if the user has typed in a custom value always prioritize that, otherwise take what headlessui gives you
emit('update:modelValue', customValue.value?.name ? customValue.value : value)
// reset query.value for future interactions
query.value = ''
}
</script>
<template>
<Combobox :model-value="modelValue" @update:model-value="updateValue">
...
<ComboboxOptions>
<ComboboxOption :value="customValue" class="h-0 w-0 overflow-hidden"></ComboboxOption>
...
</ComboboxOptions>
...
</template> |
Beta Was this translation helpful? Give feedback.
-
I agree with @ragulka To make Combobox have universal use, it should at least feature:
Much like react-aria as demonstrated here: https://codesandbox.io/s/hardcore-moon-xzc4r?file=/src/Popover.tsx |
Beta Was this translation helpful? Give feedback.
-
@RobinMalfait is there any workaround for this one. any ideas on how we can achieve this using headlessui |
Beta Was this translation helpful? Give feedback.
-
Hey! Here is an example on how you can achieve something like this: https://headlessui.com/react/combobox#allowing-custom-values |
Beta Was this translation helpful? Give feedback.
-
So the Combobox cannot be used for an Autocomplete. What should i use? |
Beta Was this translation helpful? Give feedback.
-
One useful scenario for ComboBox is to use for search queries, where user will see query suggestions, but user doesn't have to choose from the suggestions.
However, my test suggests ComboBox requires the user to select from the dropdown list otherwise the
onChange
won't be triggered when the user pressesenter
. Maybe there is something I'm missing or this case is not supported yet.Any help would be appreciated.
Beta Was this translation helpful? Give feedback.
All reactions