Skip to content
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

Fix second level parent (no link / same link as child) #120

Merged
merged 4 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 15 additions & 28 deletions src/components/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,30 @@ import { NavIcon } from './NavIcon'
import styles from './Navigation.module.css'

function ItemLink({
className,
item,
pathname,
onLinkClick,
className,
parent,
pathname,
}: {
className?: string
item: NavigationItem
pathname: string
onLinkClick?: React.MouseEventHandler<HTMLAnchorElement>
className?: string
parent?: NavigationItem
pathname: string
}) {
const isSelected =
parent && item.href === parent.href
? // This is for sub item with same link as parent (For example: Cypress of Test Runner)
pathname === parent.href
: // Rest of items
item.href && pathname.includes(item.href)

return (
<Link
href={item.href || '#'}
onClick={item.href ? onLinkClick : undefined}
className={clsx(
styles.item,
className,
item.href && pathname.includes(item.href) && styles.selected,
)}
className={clsx(styles.item, className, isSelected && styles.selected)}
>
<NavIcon
icon={item.icon}
Expand Down Expand Up @@ -116,29 +121,11 @@ export function Navigation({
>
<ItemLink
item={subItem}
parent={item}
pathname={pathname}
onLinkClick={onLinkClick}
/>
</Disclosure.Button>
{subItem.links && (
<Disclosure.Panel as="ul">
{subItem.links.map((tertiary) => (
<li key={tertiary.title}>
<Disclosure.Button
className={`${styles.button} ${styles.tertiary}`}
>
<Link
href={tertiary.href}
onClick={onLinkClick}
className={clsx(styles.item)}
>
{tertiary.title}
</Link>
</Disclosure.Button>
</li>
))}
</Disclosure.Panel>
)}
Comment on lines -123 to -141
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have tertiary level navigation, so removed it because I haven't tested my changes for tertiary level. We can revisit if we need tertiary navigation or more robust fix.

</li>
))}
</Disclosure.Panel>
Expand Down
9 changes: 4 additions & 5 deletions src/lib/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ export type NavigationItem = {
title: string
}


export const navigation: NavigationItem[] = [
export const navigation: NavigationItem[] = [
{
title: 'Intro to time travel',
href: '/time-travel-intro',
Expand Down Expand Up @@ -149,7 +148,7 @@ export const navigation: NavigationItem[] = [
{ title: 'Overview', href: '/test-runners/overview', icon: 'overview' },
{
title: 'Cypress.io',
href: '',
href: '/test-runners/cypress-io',
icon: 'cypress',
links: [
{
Expand Down Expand Up @@ -191,7 +190,7 @@ export const navigation: NavigationItem[] = [
},
{
title: 'Playwright',
href: '',
href: '/test-runners/playwright/record-your-first-replay',
icon: 'playwright',
links: [
{
Expand All @@ -202,7 +201,7 @@ export const navigation: NavigationItem[] = [
{
title: 'Debugging tests',
href: '/test-runners/playwright/debugging-tests',
icon: 'debuggingtests'
icon: 'debuggingtests',
},
{
title: 'GitHub actions',
Expand Down