How to properly handle event propagation between nested Dialog components? #3401
Unanswered
kevinwolfcr
asked this question in
Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The Problem
I'm facing a challenging situation with event propagation when using nested Dialog components and I'd appreciate any insights from the community.
I have a component structure where I'm using a Dialog (let's call it "ParentDialog") that contains a trigger button which opens another Dialog (let's call it "ChildDialog"). The issue I'm experiencing is that when I open the ChildDialog and then click anywhere within its content, those clicks are somehow also triggering the ParentDialog actions.
Here's a simplified version of my component structure:
Initially, I wasn't using
e.stopPropagation()
on the AlertDialogTrigger button, which caused both dialogs to open simultaneously when clicking the button. Addinge.stopPropagation()
fixed that immediate issue - now the button click only opens the AlertDialog.However, once the AlertDialog is open, clicking anywhere inside it (buttons, text, etc.) also triggers the parent Dialog to open. It's as if events within the portal-rendered AlertDialog are still propagating to the parent component.
What I've tried
I've tried adding
stopPropagation()
to various elements within the AlertDialog, but this doesn't seem to solve the issue with clicks inside the dialog content.The only solution I've found is to completely restructure my components to place the AlertDialog outside the DOM hierarchy of the parent Dialog's trigger:
While this works, it feels like a workaround rather than the proper way to handle this situation.
Questions
I'd really appreciate any guidance from those who have experience with this kind of component interaction. Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions