mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Navigation: Correctly highlight a SectionNavItem
if it has children that are active (#76860)
correctly highlight a sectionnavitem if it has children that are active
This commit is contained in:
parent
a0476741f2
commit
f5758e9f4b
@ -6,6 +6,8 @@ import { selectors } from '@grafana/e2e-selectors';
|
||||
import { reportInteraction } from '@grafana/runtime';
|
||||
import { useStyles2, Icon } from '@grafana/ui';
|
||||
|
||||
import { getActiveItem, hasChildMatch } from '../MegaMenu/utils';
|
||||
|
||||
export interface Props {
|
||||
item: NavModelItem;
|
||||
isSectionRoot?: boolean;
|
||||
@ -19,13 +21,14 @@ export function SectionNavItem({ item, isSectionRoot = false, level = 0 }: Props
|
||||
const styles = useStyles2(getStyles);
|
||||
|
||||
const children = item.children?.filter((x) => !x.hideFromTabs);
|
||||
const activeItem = item.children && getActiveItem(item.children, location.pathname);
|
||||
|
||||
// If first root child is a section skip the bottom margin (as sections have top margin already)
|
||||
const noRootMargin = isSectionRoot && Boolean(item.children![0].children?.length);
|
||||
|
||||
const linkClass = cx({
|
||||
[styles.link]: true,
|
||||
[styles.activeStyle]: item.active,
|
||||
[styles.activeStyle]: item.active || (level === MAX_DEPTH && hasChildMatch(item, activeItem)),
|
||||
[styles.isSection]: level < MAX_DEPTH && (Boolean(children?.length) || item.isSection),
|
||||
[styles.isSectionRoot]: isSectionRoot,
|
||||
[styles.noRootMargin]: noRootMargin,
|
||||
|
Loading…
Reference in New Issue
Block a user