mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Sidemenu: Use <a> instead of <Link> when target is present (#38987)
This commit is contained in:
@@ -5,6 +5,7 @@ import { IconName, Link } from '@grafana/ui';
|
|||||||
import { css } from '@emotion/css';
|
import { css } from '@emotion/css';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
|
headerTarget?: HTMLAnchorElement['target'];
|
||||||
headerText: string;
|
headerText: string;
|
||||||
headerUrl?: string;
|
headerUrl?: string;
|
||||||
items?: NavModelItem[];
|
items?: NavModelItem[];
|
||||||
@@ -14,6 +15,7 @@ interface Props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const SideMenuDropDown = ({
|
const SideMenuDropDown = ({
|
||||||
|
headerTarget,
|
||||||
headerText,
|
headerText,
|
||||||
headerUrl,
|
headerUrl,
|
||||||
items = [],
|
items = [],
|
||||||
@@ -22,15 +24,23 @@ const SideMenuDropDown = ({
|
|||||||
subtitleText,
|
subtitleText,
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
const headerContent = <span className="sidemenu-item-text">{headerText}</span>;
|
const headerContent = <span className="sidemenu-item-text">{headerText}</span>;
|
||||||
const header = headerUrl ? (
|
let header = (
|
||||||
<Link href={headerUrl} onClick={onHeaderClick} className="side-menu-header-link">
|
|
||||||
{headerContent}
|
|
||||||
</Link>
|
|
||||||
) : (
|
|
||||||
<button onClick={onHeaderClick} className="side-menu-header-link">
|
<button onClick={onHeaderClick} className="side-menu-header-link">
|
||||||
{headerContent}
|
{headerContent}
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
|
if (headerUrl) {
|
||||||
|
header =
|
||||||
|
!headerTarget && headerUrl.startsWith('/') ? (
|
||||||
|
<Link href={headerUrl} onClick={onHeaderClick} className="side-menu-header-link">
|
||||||
|
{headerContent}
|
||||||
|
</Link>
|
||||||
|
) : (
|
||||||
|
<a href={headerUrl} target={headerTarget} onClick={onHeaderClick} className="side-menu-header-link">
|
||||||
|
{headerContent}
|
||||||
|
</a>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const menuClass = css`
|
const menuClass = css`
|
||||||
flex-direction: ${reverseDirection ? 'column-reverse' : 'column'};
|
flex-direction: ${reverseDirection ? 'column-reverse' : 'column'};
|
||||||
|
|||||||
@@ -25,27 +25,37 @@ const SideMenuItem = ({
|
|||||||
target,
|
target,
|
||||||
url,
|
url,
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
const anchor = url ? (
|
let element = (
|
||||||
<Link
|
|
||||||
className="sidemenu-link"
|
|
||||||
href={url}
|
|
||||||
target={target}
|
|
||||||
aria-label={label}
|
|
||||||
onClick={onClick}
|
|
||||||
aria-haspopup="true"
|
|
||||||
>
|
|
||||||
<span className="icon-circle sidemenu-icon">{children}</span>
|
|
||||||
</Link>
|
|
||||||
) : (
|
|
||||||
<button className="sidemenu-link" onClick={onClick} aria-label={label}>
|
<button className="sidemenu-link" onClick={onClick} aria-label={label}>
|
||||||
<span className="icon-circle sidemenu-icon">{children}</span>
|
<span className="icon-circle sidemenu-icon">{children}</span>
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (url) {
|
||||||
|
element =
|
||||||
|
!target && url.startsWith('/') ? (
|
||||||
|
<Link
|
||||||
|
className="sidemenu-link"
|
||||||
|
href={url}
|
||||||
|
target={target}
|
||||||
|
aria-label={label}
|
||||||
|
onClick={onClick}
|
||||||
|
aria-haspopup="true"
|
||||||
|
>
|
||||||
|
<span className="icon-circle sidemenu-icon">{children}</span>
|
||||||
|
</Link>
|
||||||
|
) : (
|
||||||
|
<a href={url} target={target} className="sidemenu-link" onClick={onClick} aria-label={label}>
|
||||||
|
<span className="icon-circle sidemenu-icon">{children}</span>
|
||||||
|
</a>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cx('sidemenu-item', 'dropdown', { dropup: reverseMenuDirection })}>
|
<div className={cx('sidemenu-item', 'dropdown', { dropup: reverseMenuDirection })}>
|
||||||
{anchor}
|
{element}
|
||||||
<SideMenuDropDown
|
<SideMenuDropDown
|
||||||
|
headerTarget={target}
|
||||||
headerText={label}
|
headerText={label}
|
||||||
headerUrl={url}
|
headerUrl={url}
|
||||||
items={menuItems}
|
items={menuItems}
|
||||||
|
|||||||
Reference in New Issue
Block a user