Replies: 28 comments 53 replies
-
I agree that we need more programmatic control over anything that opens/closes or toggles state. In the meantime, here's the workaround I used for the same scenario. Add the button in, but visibly hide it.
then use a reference to trigger a click when you need it.
I've also been using this method to keep the It's not ideal, but it works. |
Beta Was this translation helpful? Give feedback.
-
I was able to get this working using something similar to @Aaronius's approach. Here's an approximation of it:
|
Beta Was this translation helpful? Give feedback.
-
+1 to this. I almost fixed it with this:
|
Beta Was this translation helpful? Give feedback.
-
This is a mega hack, but I managed to get this working by floating the Combobox.Button on top of the Input and setting it to be invisible. <div className="relative w-full">
<Combobox.Input />
<div className="absolute top-0 w-full">
<Combobox.Button className="w-full h-12"> </Combobox.Button>
</div>
</div> |
Beta Was this translation helpful? Give feedback.
-
I think this should be the behaviour by default, at least when the combobox is empty. If you go to the official example https://headlessui.dev/react/combobox and remove the default value (+ fix the display value formula), the behaviour for the first click has a bad UX |
Beta Was this translation helpful? Give feedback.
-
How about adding |
Beta Was this translation helpful? Give feedback.
-
What about exposing the HeadlessUI is an amazing library, and I really like the idea of the library not dictating design patterns, and this thread kinda shows a way that it does the opposite |
Beta Was this translation helpful? Give feedback.
-
We can use
This will open combobox drawer when input is focused and it wont close dropdown when user types a space |
Beta Was this translation helpful? Give feedback.
-
Just a couple of things to keep in mind for keyboard users:
|
Beta Was this translation helpful? Give feedback.
-
I strongly agree that exposing a TLDR:
|
Beta Was this translation helpful? Give feedback.
-
Running into this as well. What would it take to get this property added? |
Beta Was this translation helpful? Give feedback.
-
Agreed - would be a lovely feature. |
Beta Was this translation helpful? Give feedback.
-
this work for me instead onFocus use onClick onClick={(e:any) => { |
Beta Was this translation helpful? Give feedback.
-
I would recommend putting this tailwind class on your button rather than changing it to a div. Nesting interactive elements is probably a bad accessibility idea but at least we are not lying to the user saying its a div when in reality its a interactive button.
|
Beta Was this translation helpful? Give feedback.
-
Any updates on that? Is that even on headless ui's roadmap? |
Beta Was this translation helpful? Give feedback.
-
Any chance we could get this function natively? |
Beta Was this translation helpful? Give feedback.
-
Thanks for the suggestions above. They really helped. However, I have one situation can not be fixed by these workarounds. I have remove ("x") buttons in the search suggestion dropdown list. If I click the button, the list is closed. But I only want to remove one item, and keep the dropdown list open. https://headlessui.com/react/combobox#showing-hiding-the-combobox
I was wrong. The sample code is a little bit misleading. Although it is still using |
Beta Was this translation helpful? Give feedback.
-
any news? |
Beta Was this translation helpful? Give feedback.
-
bump. please add focus events |
Beta Was this translation helpful? Give feedback.
-
Bumping again, working on a project that requires this right now and it would be really helpful if this can be kindly prioritised 🙏 |
Beta Was this translation helpful? Give feedback.
-
We want this boys, Please some hero to open PR :P |
Beta Was this translation helpful? Give feedback.
-
I got this working in Vue 3 (and TypeScript) thanks to #1236 (comment) Added <ComboboxInput
class="w-full border-none py-2 pl-3 pr-10 text-sm leading-5 text-gray-900 focus:ring-0"
:displayValue="(person:any) => person.name"
@change="query = $event.target.value"
@focus="handleInputFocus"
/> /**
* A hack for showing the dropdown when the user clicks on the input.
* @see https://github.com/tailwindlabs/headlessui/discussions/1236#discussioncomment-4902695
*/
const handleInputFocus = (e: Event) => {
const target = e.target as HTMLElement;
const button = target?.nextSibling as HTMLButtonElement;
button?.click();
} [Edit: the interaction here isn't great. Works fine the first time I click on the input, but when I select an element the dropdown list closes, but the focus is still on the input. If I click on it again I'm expecting the list to open...but instead nothing happens. This is weird and not a solution.] |
Beta Was this translation helpful? Give feedback.
-
Better than
|
Beta Was this translation helpful? Give feedback.
-
Agreed this should be added. The PR was unfortunately closed and I haven't seen any other discussion. Following the suggestion of wrapping the input with the button, any option you select keeps the option box open (due to refocusing) and I can't seem to find a solid workaround. |
Beta Was this translation helpful? Give feedback.
-
Hey all! This feature has been implemented and you can use the This is currently available in the insiders build:
|
Beta Was this translation helpful? Give feedback.
-
Just in case anyone is still running into this and doesn't want to use the <Combobox.Input
onChange={(event) => setQuery(event.target.value)}
displayValue={(c: Column) => c?.name}
onClick={() => {
if (!open) {
buttonRef.current?.click()
}
}}
onFocus={() => {
buttonRef.current?.click()
}}
/> And for the button: const buttonRef = useRef<HTMLButtonElement>(null)
<Combobox.Button
ref={buttonRef}
> |
Beta Was this translation helpful? Give feedback.
-
When will the new prop immediate move from the @insiders to the stable version? |
Beta Was this translation helpful? Give feedback.
-
Hi, Any idea when this will be available on stable/production build? |
Beta Was this translation helpful? Give feedback.
-
The documentation alludes to the combobox as useful as an autocomplete or command palette, but I think many users also would like to use it as a searchable version of the
Listbox
(see: #626), where the primary use case is to make it easy to narrow down selections before picking one. Or, seeing the options might help the user decide what to type. However, I've run into some issues usingCombobox
in this way - when focusing the input, you have to either start typing or use one of the command keypresses like ⬆️ /⬇️ to get theCombobox.Options
to display. This isn't super intuitive for me, as if I'm expecting a dropdown of options I don't expect to have to start typing first.I've tried a couple of workarounds:
Combobox.Input
inside of theCombobox.Button
, but this runs into an issue described in Combobox.Button wrapper Combobox.Input auto close when I typing space #1209, where if the user types a space then the dropdown closes.Combobox.Input
to help with that, but I haven't been able to crack it. There's some issue where if the control blurs before theonChange
fires, it'll never fire at all. 🤷 it's a bit hacky either way.So, my point is, it would be very convenient addition to the interface to have an option for
Combobox
to open immediately when theCombobox.Input
is focused.Beta Was this translation helpful? Give feedback.
All reactions