From f93f39f9201aa55b03bff150da37778687224691 Mon Sep 17 00:00:00 2001 From: Mingze Xiao Date: Fri, 2 Oct 2020 17:04:12 -0700 Subject: [PATCH 1/3] fix(highlight): Remove selection when clicking anywhere outside of popup --- src/components/Popups/PopupHighlight.tsx | 6 +++++- src/components/Popups/PopupHighlightError.tsx | 12 +++++++++++- src/highlight/HighlightAnnotations.tsx | 16 +++++++++++++--- src/highlight/HighlightContainer.tsx | 2 ++ 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/components/Popups/PopupHighlight.tsx b/src/components/Popups/PopupHighlight.tsx index 26160a0c7..8f1a7d2fb 100644 --- a/src/components/Popups/PopupHighlight.tsx +++ b/src/components/Popups/PopupHighlight.tsx @@ -4,11 +4,13 @@ import noop from 'lodash/noop'; import { FormattedMessage } from 'react-intl'; import messages from './messages'; import PopupBase from './PopupBase'; +import useOutsideEvent from '../../common/useOutsideEvent'; import { Options } from './Popper'; import { Shape } from '../../@types/model'; import './PopupHighlight.scss'; export type Props = { + onCancel?: () => void; onClick?: (event: React.MouseEvent) => void; shape: Shape; }; @@ -43,7 +45,7 @@ const options: Partial = { placement: 'bottom', }; -export default function PopupHighlight({ onClick = noop, shape }: Props): JSX.Element { +export default function PopupHighlight({ onCancel = noop, onClick = noop, shape }: Props): JSX.Element { const buttonRef = React.useRef(null); const { height, width, x, y } = shape; @@ -62,6 +64,8 @@ export default function PopupHighlight({ onClick = noop, shape }: Props): JSX.El onClick(event); }; + useOutsideEvent('mousedown', buttonRef, onCancel); + return (