For context, <NavTreeItem>
is a material-ui <TreeItem>
and <OpenDialogButton>
is a material-ui <Button>
.
I have a component like this (simplified):
function pushLink() {
// ...
}
function openDialog(event) {
event.stopPropagation();
// ...
}
<NavTreeItem onClick={pushLink}>
<OpenDialogButton onClick={openDialog} />
...
{dialogIsOpen && <Dialog />}
</NavTreeItem>
Let's say neither openDialog()
nor pushLink()
has been executed yet. If I click <OpenDialogButton>
to open the dialog, it runs openDialog()
which executes event.stopPropagation()
so that the event doesn't bubble up to the tree item and executes pushLink()
- just as expected. When <Dialog>
is committed to the DOM, it is not nested within the <NavTreeItem>
- just as expected. So far, only openDialog()
has been executed.
But when I click on the <Dialog>
element (or its backdrop), it executes pushLink()
- undesirable behavior. It almost seems as if the click event is bubbling up to the <NavTreeItem>
element - even though the <Dialog>
element is not nested within it in the DOM. Why is this happening? How do I make it so that this doesn't occur?