-
|
Hi there, I'm looking to create a combobox input that will be immediately focused on render and display a list of options underneath. In other words, I'd like to combine the functionality of The way it works now, however, is not the way that I expected. The input focuses immediately on render (apparently respecting the Here's a sandbox example of the behavior I'm talking about. Note that you have to refresh the browser frame in order to see the behavior - the input is auto-focused, but the options do not render until a change in the input. This is counterintuitive to me, and I'm sure there's a hack that would get me the outcome I'm looking for, but I was curious if it was intended behavior or merited the creation of an issue. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
This sounds like a timing issue between the initial focus and the Combobox's open interaction.
A small workaround is to trigger focus after mount rather than relying on const inputRef = useRef<HTMLInputElement | null>(null)
useEffect(() => {
requestAnimationFrame(() => {
inputRef.current?.focus()
})
}, [])
<Combobox immediate>
<ComboboxInput ref={inputRef} />
<ComboboxOptions>
{/* options */}
</ComboboxOptions>
</Combobox>If that opens the list correctly, it would confirm this is mostly an ordering issue: mount-time autofocus happens before the Combobox can treat it like an immediate focus-open interaction. For UX, I would also check whether the options should open with the full list before any query is typed. If yes, this seems reasonable as either a docs note or an issue, because |
Beta Was this translation helpful? Give feedback.
-
|
@yudin-s thanks for the reply. After a lot more messing around, I'm now almost certain this behavior is related to the double-rendering that happens in That could be something to note in documentation (some kind of warning that certain edge cases might come up in development that aren't anything to worry about in prod) but I bet not, so I'm closing the discussion for now. |
Beta Was this translation helpful? Give feedback.
@yudin-s thanks for the reply. After a lot more messing around, I'm now almost certain this behavior is related to the double-rendering that happens in
React.StrictModeduring development. In production builds, everything works intuitively.That could be something to note in documentation (some kind of warning that certain edge cases might come up in development that aren't anything to worry about in prod) but I bet not, so I'm closing the discussion for now.