Grafana-ui: Allow context menu items to be open in new tab (#30141)

This commit is contained in:
Andrej Ocenas 2021-01-14 14:18:41 +01:00 committed by GitHub
parent 65b0365aeb
commit 9bb516e4e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -120,7 +120,14 @@ const MenuItemComponent: React.FC<MenuItemProps> = React.memo(({ url, icon, labe
target={target}
className={cx(className, styles.link)}
onClick={e => {
// We can have both url and onClick and we want to allow user to open the link in new tab/window
const isSpecialKeyPressed = e.ctrlKey || e.metaKey || e.shiftKey;
if (isSpecialKeyPressed && url) {
return;
}
if (onClick) {
e.preventDefault();
onClick(e);
}
}}