Skip to content

Commit

Permalink
Merge b79a346 into 44a3dc9
Browse files Browse the repository at this point in the history
  • Loading branch information
francinelucca authored Sep 18, 2024
2 parents 44a3dc9 + b79a346 commit 8bbf3f2
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/react/src/Dialog/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -419,14 +419,15 @@ const _Dialog = React.forwardRef<HTMLDivElement, React.PropsWithChildren<DialogP
footerButton.ref = autoFocusedFooterButtonRef
}
}
const [lastMouseDownIsBackdrop, setLastMouseDownIsBackdrop] = useState<boolean>(false)
const defaultedProps = {...props, title, subtitle, role, dialogLabelId, dialogDescriptionId}
const onBackdropClick = useCallback(
(e: SyntheticEvent) => {
if (e.target === e.currentTarget) {
if (e.target === e.currentTarget && lastMouseDownIsBackdrop) {
onClose('escape')
}
},
[onClose],
[onClose, lastMouseDownIsBackdrop],
)

const dialogRef = useRef<HTMLDivElement>(null)
Expand Down Expand Up @@ -479,7 +480,14 @@ const _Dialog = React.forwardRef<HTMLDivElement, React.PropsWithChildren<DialogP
return (
<>
<Portal>
<Backdrop ref={backdropRef} {...positionDataAttributes} onClick={onBackdropClick}>
<Backdrop
ref={backdropRef}
{...positionDataAttributes}
onClick={onBackdropClick}
onMouseDown={e => {
setLastMouseDownIsBackdrop(e.target === e.currentTarget)
}}
>
<StyledDialog
width={width}
height={height}
Expand Down

0 comments on commit 8bbf3f2

Please sign in to comment.