Skip to content

Commit

Permalink
Merge pull request #2811 from owid/fix-grapher-dismiss-modal
Browse files Browse the repository at this point in the history
fix(modal): don't dismiss when clicking on an interactive element
  • Loading branch information
sophiamersmann authored Oct 24, 2023
2 parents 90b6cef + 46ebf4c commit d2f5378
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/@ourworldindata/grapher/src/modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ export class Modal extends React.Component<{
}

@action.bound onDocumentClick(e: MouseEvent): void {
// check if the click was outside of the modal
const tagName = (e.target as HTMLElement).tagName
const isTargetInteractive = ["A", "BUTTON", "INPUT"].includes(tagName)
if (
this.contentRef?.current &&
!this.contentRef.current.contains(e.target as Node) &&
// clicking on an interactive element should not dismiss the modal
// (this is especially important for the suggested chart review tool)
!isTargetInteractive &&
// check that the target is still mounted to the document; we also get click events on nodes that have since been removed by React
document.contains(e.target as Node)
)
Expand Down

0 comments on commit d2f5378

Please sign in to comment.