Skip to content
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

ComboBox immediately closes on second open when the anchor has a negative gap #3556

Open
mart-jansink opened this issue Nov 14, 2024 · 0 comments

Comments

@mart-jansink
Copy link

What package within Headless UI are you using?

For example: @headlessui/react

What version of that package are you using?

v2.2.0 (latest)

What browser are you using?

Chrome, Safari (Firefox is OK)

Reproduction URL

https://codesandbox.io/p/devbox/blissful-river-22k848?workspaceId=df463712-8b83-4944-ae78-6529fa90b318

Describe your issue

This ComboBox immediately opens when the input is focused upon, by clicking on it. Then close it by clicking somewhere outside the options. Now clicking the input again causes the box to open just for a moment, before automatically closing again.

With a zero or positive gap value for the anchor prop this doesn't happen. The difference is the list of elements returned by event.composedPath() at

if (event.composed && event.composedPath().includes(container as EventTarget)) {
return
}
With a negative gap this set just consists of [body, html, document, Window].

Setting the initialClickTarget.current back to null in

(event) => {
return handleOutsideClick(event, () => {
return window.document.activeElement instanceof HTMLIFrameElement
? window.document.activeElement
: null
})
},
appears to be a fix, but I can't tell if this has any unforeseen consequences.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant