From be2c9e779f5faf511046425ddd62db01248a9c78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Thu, 19 May 2022 16:57:47 +0200 Subject: [PATCH 1/2] Don't open the regular browser or our context menu on right-click MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/components/views/messages/MessageActionBar.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/views/messages/MessageActionBar.tsx b/src/components/views/messages/MessageActionBar.tsx index 0effb252888..f1c86940651 100644 --- a/src/components/views/messages/MessageActionBar.tsx +++ b/src/components/views/messages/MessageActionBar.tsx @@ -97,7 +97,10 @@ const OptionsButton: React.FC = ({ { + onClick={(e: React.MouseEvent) => { + // Don't open the regular browser or our context menu on right-click + e.preventDefault(); + e.stopPropagation(); openMenu(); // when the context menu is opened directly, e.g. via mouse click, the onFocus handler which tracks // the element that is currently focused is skipped. So we want to call onFocus manually to keep the From cb41570ce7cc1bd3f35eb8dab92c23f08718c479 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Thu, 19 May 2022 17:19:22 +0200 Subject: [PATCH 2/2] Move `onClick` out of inline JSX MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- .../views/messages/MessageActionBar.tsx | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/components/views/messages/MessageActionBar.tsx b/src/components/views/messages/MessageActionBar.tsx index f1c86940651..bd2ce4c9040 100644 --- a/src/components/views/messages/MessageActionBar.tsx +++ b/src/components/views/messages/MessageActionBar.tsx @@ -76,6 +76,17 @@ const OptionsButton: React.FC = ({ onFocusChange(menuDisplayed); }, [onFocusChange, menuDisplayed]); + const onOptionsClick = (e: React.MouseEvent): void => { + // Don't open the regular browser or our context menu on right-click + e.preventDefault(); + e.stopPropagation(); + openMenu(); + // when the context menu is opened directly, e.g. via mouse click, the onFocus handler which tracks + // the element that is currently focused is skipped. So we want to call onFocus manually to keep the + // position in the page even when someone is clicking around. + onFocus(); + }; + let contextMenu: ReactElement | null; if (menuDisplayed) { const tile = getTile && getTile(); @@ -97,16 +108,7 @@ const OptionsButton: React.FC = ({ { - // Don't open the regular browser or our context menu on right-click - e.preventDefault(); - e.stopPropagation(); - openMenu(); - // when the context menu is opened directly, e.g. via mouse click, the onFocus handler which tracks - // the element that is currently focused is skipped. So we want to call onFocus manually to keep the - // position in the page even when someone is clicking around. - onFocus(); - }} + onClick={onOptionsClick} isExpanded={menuDisplayed} inputRef={ref} onFocus={onFocus}