From 5718dab4de7d7eec461f68da546b647ec7ff9e01 Mon Sep 17 00:00:00 2001 From: Thibaud Colas Date: Mon, 10 Jan 2022 13:06:31 +0000 Subject: [PATCH] Support right-click and middle-click interactions with sidebar links --- .../src/components/Sidebar/menu/LinkMenuItem.tsx | 16 +++++++++++++++- .../Sidebar/modules/CustomBranding.tsx | 12 +++++++++++- .../Sidebar/modules/WagtailBranding.tsx | 12 +++++++++++- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/client/src/components/Sidebar/menu/LinkMenuItem.tsx b/client/src/components/Sidebar/menu/LinkMenuItem.tsx index 415265d982..159d2006f5 100644 --- a/client/src/components/Sidebar/menu/LinkMenuItem.tsx +++ b/client/src/components/Sidebar/menu/LinkMenuItem.tsx @@ -11,6 +11,16 @@ export const LinkMenuItem: React.FunctionComponent 2; const onClick = (e: React.MouseEvent) => { + // Do not capture click events with modifier keys or non-main buttons. + if ( + e.ctrlKey || + e.shiftKey || + e.metaKey || + (e.button && e.button !== 0) + ) { + return; + } + e.preventDefault(); navigate(item.url).then(() => { @@ -67,7 +77,11 @@ export const LinkMenuItem: React.FunctionComponent - + {item.iconName && } {item.label}
diff --git a/client/src/components/Sidebar/modules/CustomBranding.tsx b/client/src/components/Sidebar/modules/CustomBranding.tsx index ffffc1b9c1..5f816d6376 100644 --- a/client/src/components/Sidebar/modules/CustomBranding.tsx +++ b/client/src/components/Sidebar/modules/CustomBranding.tsx @@ -12,6 +12,16 @@ interface CustomBrandingProps { const CustomBranding: React.FunctionComponent = ({ homeUrl, html, strings, navigate }) => { const onClick = (e: React.MouseEvent) => { + // Do not capture click events with modifier keys or non-main buttons. + if ( + e.ctrlKey || + e.shiftKey || + e.metaKey || + (e.button && e.button !== 0) + ) { + return; + } + e.preventDefault(); navigate(homeUrl); }; @@ -19,7 +29,7 @@ const CustomBranding: React.FunctionComponent = ({ homeUrl, return ( = ({ homeUr const onClick = (e: React.MouseEvent) => { + // Do not capture click events with modifier keys or non-main buttons. + if ( + e.ctrlKey || + e.shiftKey || + e.metaKey || + (e.button && e.button !== 0) + ) { + return; + } + e.preventDefault(); navigate(homeUrl); }; @@ -60,7 +70,7 @@ const WagtailBranding: React.FunctionComponent = ({ homeUr return (