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

Dialog closes on first open even when clicked inside the panel #2535

Closed
leolorenzoluis opened this issue Jun 12, 2023 · 20 comments
Closed

Dialog closes on first open even when clicked inside the panel #2535

leolorenzoluis opened this issue Jun 12, 2023 · 20 comments

Comments

@leolorenzoluis
Copy link

leolorenzoluis commented Jun 12, 2023

What package within Headless UI are you using?

@headlessui/react

What version of that package are you using?

1.17.15

What browser are you using?

Chrome and Safari

Describe your issue

Dialog bug does not occur in 1.7.2 but with 1.7.15 it closes the dialog. When I put a breakpoint what's causing the modal closure... the useClickOutside is getting triggered the first time, so not sure if any succeeding updates between versions broke something.

@catdoglt
Copy link

Facing the same issue, had to downgrade the previous version. How did you find out that useClickOutside is getting triggered? Where is that hook, I cant even find it

@howard86
Copy link

I've got the same issue and downgrading to 1.7.11 seems to fix

@RobinMalfait
Copy link
Member

Hey, thank you for this bug report! 🙏

Unfortunately, I have to close this as a reproduction was not provided. Trying to create a reproduction ourselves from the information in an issue drastically increases the amount of time it takes for us to provide a solution and if we have do that for every issue it’s impossible for us to keep up.

If this is still an issue for you, please open a new issue but include a proper reproduction GitHub repository or CodeSandbox where you already have everything all set up so we can clone it and immediately see the issue without configuring everything by hand.

Sorry, not trying to be dismissive and definitely want to fix the issue if there is one, but we have to be strict about this one or there's no way we could keep up with the number of questions we get and the quality of the library would suffer as a result. Hope that's understandable!

@leolorenzoluis
Copy link
Author

leolorenzoluis commented Jun 13, 2023

Lol, it hasn’t even been 24 hours and yet you already closed the issue. Basically no chance to edit the issue as a first timer to report an issue before closing. 😵‍💫 this feels like a very toxic culture 🙈

@adamwathan
Copy link
Member

@leolorenzoluis Hey! Sorry for any surprises here, we try to be very clear in the issue template about what is required when opening an issue, and we explain that issues that don't provide all of the necessary information will be closed:

image

That's the only way we've found it's possible to effectively manage busy projects like this with a small team. More than happy to help but need to set the bar for detail at a certain level or things would get out of control here.

@lukasvice
Copy link

I also have this problem and have created a reproduction.

I have two examples: One that works and one where you can test the bug by opening the dialog for the first time and clicking inside, it closes.

I have found 3 things that need to be met to reproduce this behavior:

  1. Version 1.7.15+
  2. The Dialog must be opened with a JSX condition and not with the open prop
  3. (And this is the weird part:) No Dialog.Title

Working: https://codesandbox.io/s/dialog-working-6wxrfc?file=/src/App.tsx
Bug: https://codesandbox.io/s/dialog-closing-on-first-click-vx4ftt

Could you reopen this issue?

@jorgebastida
Copy link

jorgebastida commented Aug 16, 2023

I have this same issue with 1.7.15. Any click inside or outside the Dialog.Panel closes it. Adding a Dialog.Title fixes the issue.

In my case, contrary to @lukasvice 2nd condition, my Dialog is opened with the open prop.

Thank you very much for the hint @lukasvice about the Dialog.Title you saved my day!

@adamwathan Please reconsider reopening this issue.

@daiveedb
Copy link

I had the same issue with 1.7.17 . Any click inside or outside the Dialog.Panel closes it. Adding a Dialog.Title fixes the issue.

@IanPhilips
Copy link

IanPhilips commented Sep 27, 2023

Seeing this issue as well with any version above 1.7.11 on mobile safari. Adding a Dialog.Title doesn't fix it in my case, this could be because I'm using Transition divs.

@Emiliano-Bucci
Copy link

@adamwathan The issue is still present here!

@adamwathan
Copy link
Member

@Emiliano-Bucci Yep it's been fixed just need to tag a release 👍

#2800 (comment)

@optislav
Copy link

optislav commented Dec 4, 2023

Still present

@nick-tw
Copy link

nick-tw commented Apr 1, 2024

Issue is still present.

@adamwathan
Copy link
Member

Please open a new issue with a reproduction if you're still running into this problem 👍

@abhishekmulik
Copy link

I am on version v-1.7.18 and the issue is still present. Irrespective where you click inside or outside the Dialog.Panel it closes.

@jeremy0x
Copy link

jeremy0x commented Apr 7, 2024

As @leolorenzoluis pointed out, the useClickOutside function is triggered initially. Here’s a simple solution to this problem:

  1. Prevent the dialog from closing when clicked outside. You can make the onClose event do nothing and instead:
<Dialog open={isOpen} onClose={() => {}}>

If you want the dialog to close when you click outside it, proceed with the next steps:

  1. Add an overlay to your dialog using <Dialog.Overlay />.

  2. Close the dialog when the overlay is clicked by adding an onClick event handler to the Dialog.Overlay:

<Dialog.Overlay onClick={() => closeModal()} />
  • Here’s how you can define the closeModal function:
const closeModal = () => {
  setIsOpen(false);
};

Hope that helps!

@alexis-jonuro
Copy link

still present. I have to downgrade to "1.7.11"

@halilhanbadem
Copy link

The problem still continues. I had to downgrade to solve the problem (1.7.11). To summarize the problem, click anywhere inside the panel and you will see that the panel is closed. This is not normal behavior. The normal thing is that it closes on any area clicked outside.

@abhishekmulik
Copy link

One of the issue could be the component that is opening the Dialog or it's parent is getting re-rendered this was the issue I faced and eventually my Dialog got closed whenever I clicked inside the Panel

@Aravinda93
Copy link

@lukasvice @leolorenzoluis

I am facing similar issue when I access DialogPanel2.vue via DialogPanel1.vue then it for some reason automatically closes the DialogPanel1.vue.

Issue recreation: Codesandbox
Issue posting: #3199

Can you please once have a look and provide some suggestions or workarounds?

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