New Panel Header: Fix when clicking submenu item the parent menu item onClick get's triggered (#65691)

This commit is contained in:
Alexa V 2023-03-31 16:35:34 +02:00 committed by GitHub
parent 04336d53a9
commit c03bf7d8ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 3 deletions

View File

@ -2658,7 +2658,7 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "12"],
[0, 0, 0, "Unexpected any. Specify a different type.", "13"],
[0, 0, 0, "Unexpected any. Specify a different type.", "14"],
[0, 0, 0, "Unexpected any. Specify a different type.", "15"]
[0, 0, 0, "Do not use any type assertions.", "15"]
],
"public/app/features/dashboard/utils/panelMerge.ts:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"],

View File

@ -25,7 +25,7 @@ export const PanelHeaderMenuItem = (props: Props & PanelMenuItem) => {
ref={setRef}
data-testid={selectors.components.Panels.Panel.menuItems(props.text)}
>
<a onClick={props.onClick} href={props.href}>
<a onClick={props.onClick} href={props.href} role="menuitem">
{icon && <Icon name={icon} className={styles.menuIconClassName} />}
<span className="dropdown-item-text" aria-label={selectors.components.Panels.Panel.headerItems(props.text)}>
{props.text}

View File

@ -180,7 +180,15 @@ export function getPanelMenu(
type: 'submenu',
text: t('panel.header-menu.inspect', `Inspect`),
iconClassName: 'info-circle',
onClick: (e: React.MouseEvent<any>) => onInspectPanel(),
onClick: (e: React.MouseEvent<HTMLElement>) => {
const currentTarget = e.currentTarget;
const target = e.target as HTMLElement;
const closestMenuItem = target.closest('[role="menuitem"]');
if (target === currentTarget || closestMenuItem === currentTarget) {
onInspectPanel();
}
},
shortcut: 'i',
subMenu: inspectMenu,
});