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

onClose gets called on Dialog even when open state is changed programmatically #3488

Open
Dremora opened this issue Feb 19, 2024 · 0 comments

Comments

@Dremora
Copy link
Sponsor

Dremora commented Feb 19, 2024

Current behavior

onClose event gets triggered whenever open state passed to useDialogStore is changed programmatically. This makes it impossible to distinguish between user-initiated close events (e.g. hitting Esc key or clicking outside the dialog) and programmatic changes to the dialog state, and, as a result, implement certain patterns, such as displaying a warning on dialog hide.

Note that this behaviour is not observed when using open prop passed directly to the Dialog component, only when using custom dialog store. Existing example on displaying a warning on dialog hide is written using open prop and thus works.

Steps to reproduce the bug

  1. Open https://stackblitz.com/edit/lzpywb?file=dialog%2Fstyle.css,dialog%2Findex.tsx&theme=dark
  2. Open a dialog
  3. Try closing a dialog

Expected behavior

Dialog should close, onClose callback should only be called once.

Workaround

There is a number of workarounds, e.g.

I have a custom Dialog component built around Ariakit's. This essentially means that I have to have 2 implementations depending on whether I use animations or not.

Possible solutions

No response

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

No branches or pull requests

2 participants