-
Notifications
You must be signed in to change notification settings - Fork 535
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
V2 does not work when stacked over Overlay
s or other components using useOnClickOutside
#2857
Comments
Hi! This issue has been marked as stale because it has been open with no activity for 180 days. You can comment on the issue or remove the stale label to keep it open. If you do nothing, this issue will be closed in 7 days. |
Hi! This issue has been marked as stale because it has been open with no activity for 180 days. You can comment on the issue or remove the stale label to keep it open. If you do nothing, this issue will be closed in 7 days. |
🙃 |
Hi! This issue has been marked as stale because it has been open with no activity for 180 days. You can comment on the issue or remove the stale label to keep it open. If you do nothing, this issue will be closed in 7 days. |
@keithamus is there a chance https://github.com/github/primer/issues/2531 would solve this? |
Yes. We wouldn’t use onclickoutside but rather the native dialog functionality (which would need to be polyfilled but it’s something we can scope into that epic) |
Thanks! Adding this as a piece of "Corresponding Work" to https://github.com/github/primer/issues/2531 for future consideration. |
Description
The new draft
Dialog
component does not useuseOnClickOutside
under the hood, because it has its own backdrop element that it could handle clicks on if necessary. This makes sense, but unfortunately breaks the dialog when stacked overOverlay
,AnchoredOverlay
, or similar.This is because when a component under the dialog has registered a click-outside handler using
useOnClickOutside
, a click in theDialog
is seen as a click outside of the overlay.useOnClickOutside
automatically handles this for stacked overlays by maintaining a global registry, but becauseDialog
does not calluseOnClickOutside
, it does not get registered to that global registry.The workaround here is non-obvious but simple: call
useOnClickOutside
insideDialog
, even though the handler will be a no-op. ThecontainerRef
passed touseOnClickOutside
must include the backdrop element so that there are never any clicks outside registered. This will cause all clicks to be registered as inside theDialog
, stopping them from propagating.Steps to reproduce
I couldn't get CodeSandbox working with the latest version of Primer, so here's a full demo as code instead:
Version
v35.19.0
Browser
Chrome
The text was updated successfully, but these errors were encountered: