-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Enterprise Search] Added a shouldShowActiveForSubroutes option #83338
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,15 +63,17 @@ export const SideNav: React.FC<SideNavProps> = ({ product, children }) => { | |
|
||
interface SideNavLinkProps { | ||
to: string; | ||
shouldShowActiveForSubroutes?: boolean; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After rereading a few times this var name is really growing on me! It's very clear what it means and I was able to figure it out without having to ask for a screenshot (which I almost did at first haha) 💯 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Haha. I wanted to, but it was late in the day and and I was trying to get out the door so I thought I'd roll the dice 🎲 |
||
isExternal?: boolean; | ||
className?: string; | ||
isRoot?: boolean; | ||
subNav?: React.ReactNode; | ||
} | ||
|
||
export const SideNavLink: React.FC<SideNavLinkProps> = ({ | ||
isExternal, | ||
to, | ||
shouldShowActiveForSubroutes = false, | ||
isExternal, | ||
children, | ||
className, | ||
isRoot, | ||
|
@@ -82,7 +84,10 @@ export const SideNavLink: React.FC<SideNavLinkProps> = ({ | |
|
||
const { pathname } = useLocation(); | ||
const currentPath = stripTrailingSlash(pathname); | ||
const isActive = currentPath === to || (isRoot && currentPath === ''); | ||
const isActive = | ||
currentPath === to || | ||
(shouldShowActiveForSubroutes && currentPath.startsWith(to)) || | ||
(isRoot && currentPath === ''); | ||
|
||
const classes = classNames('enterpriseSearchNavLinks__item', className, { | ||
'enterpriseSearchNavLinks__item--isActive': !isExternal && isActive, // eslint-disable-line @typescript-eslint/naming-convention | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[not a blocker] What are your thoughts on wrapping these two new tests in a
describe('shouldShowActiveForSubroutes' () => {
block for organization and swapping the order (testing the positive first and then confirming the negative)? no worries if not, it's super minorThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I'll update this. I have to merge master anyway.