Skip to content

Commit

Permalink
[Enterprise Search] Add nested sub navigation to SideNavLinks (#77685)
Browse files Browse the repository at this point in the history
* Add subNav prop to SideNavLinks

- for nested navigation

* [Probably extra] Tweak CSS to allow for recursive subnesting

- while attempting to expand the hitbox area of nested links as much as possible

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
Constance and elasticmachine authored Sep 17, 2020
1 parent bd6b389 commit 9d1ba4d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,15 @@ $euiSizeML: $euiSize * 1.25; // 20px - between medium and large ¯\_(ツ)_/¯
}
}
}

&__subNav {
padding-left: $euiSizeML;

// Extends the click area of links more to the left, so that second tiers
// of subnavigation links still have the same hitbox as first tier links
.enterpriseSearchNavLinks__item {
margin-left: -$euiSizeML;
padding-left: $euiSizeXXL;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,20 @@ describe('SideNavLink', () => {
expect(wrapper.find('.testing')).toHaveLength(1);
expect(wrapper.find('[data-test-subj="testing"]')).toHaveLength(1);
});

it('renders nested subnavigation', () => {
const subNav = (
<SideNavLink to="/elsewhere" data-test-subj="subNav">
Another link!
</SideNavLink>
);
const wrapper = shallow(
<SideNavLink to="/" subNav={subNav}>
Link
</SideNavLink>
);

expect(wrapper.find('.enterpriseSearchNavLinks__subNav')).toHaveLength(1);
expect(wrapper.find('[data-test-subj="subNav"]')).toHaveLength(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ interface ISideNavLinkProps {
isExternal?: boolean;
className?: string;
isRoot?: boolean;
subNav?: React.ReactNode;
}

export const SideNavLink: React.FC<ISideNavLinkProps> = ({
Expand All @@ -74,6 +75,7 @@ export const SideNavLink: React.FC<ISideNavLinkProps> = ({
children,
className,
isRoot,
subNav,
...rest
}) => {
const { closeNavigation } = useContext(NavContext) as INavContext;
Expand Down Expand Up @@ -103,6 +105,7 @@ export const SideNavLink: React.FC<ISideNavLinkProps> = ({
{children}
</EuiLink>
)}
{subNav && <ul className="enterpriseSearchNavLinks__subNav">{subNav}</ul>}
</li>
);
};

0 comments on commit 9d1ba4d

Please sign in to comment.