Skip to content

Commit ef690f4

Browse files
Fix second level parent (no link / same link as child)
1 parent 81a602d commit ef690f4

File tree

2 files changed

+19
-33
lines changed

2 files changed

+19
-33
lines changed

src/components/Navigation.tsx

+15-28
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,30 @@ import { NavIcon } from './NavIcon'
1010
import styles from './Navigation.module.css'
1111

1212
function ItemLink({
13+
className,
1314
item,
14-
pathname,
1515
onLinkClick,
16-
className,
16+
parent,
17+
pathname,
1718
}: {
19+
className?: string
1820
item: NavigationItem
19-
pathname: string
2021
onLinkClick?: React.MouseEventHandler<HTMLAnchorElement>
21-
className?: string
22+
parent?: NavigationItem
23+
pathname: string
2224
}) {
25+
const isSelected =
26+
parent && item.href === parent.href
27+
? // This is for sub item with same link as parent (For example: Cypress of Test Runner)
28+
pathname === parent.href
29+
: // Rest of items
30+
item.href && pathname.includes(item.href)
31+
2332
return (
2433
<Link
2534
href={item.href || '#'}
2635
onClick={item.href ? onLinkClick : undefined}
27-
className={clsx(
28-
styles.item,
29-
className,
30-
item.href && pathname.includes(item.href) && styles.selected,
31-
)}
36+
className={clsx(styles.item, className, isSelected && styles.selected)}
3237
>
3338
<NavIcon
3439
icon={item.icon}
@@ -116,29 +121,11 @@ export function Navigation({
116121
>
117122
<ItemLink
118123
item={subItem}
124+
parent={item}
119125
pathname={pathname}
120126
onLinkClick={onLinkClick}
121127
/>
122128
</Disclosure.Button>
123-
{subItem.links && (
124-
<Disclosure.Panel as="ul">
125-
{subItem.links.map((tertiary) => (
126-
<li key={tertiary.title}>
127-
<Disclosure.Button
128-
className={`${styles.button} ${styles.tertiary}`}
129-
>
130-
<Link
131-
href={tertiary.href}
132-
onClick={onLinkClick}
133-
className={clsx(styles.item)}
134-
>
135-
{tertiary.title}
136-
</Link>
137-
</Disclosure.Button>
138-
</li>
139-
))}
140-
</Disclosure.Panel>
141-
)}
142129
</li>
143130
))}
144131
</Disclosure.Panel>

src/lib/navigation.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ export type NavigationItem = {
88
title: string
99
}
1010

11-
12-
export const navigation: NavigationItem[] = [
11+
export const navigation: NavigationItem[] = [
1312
{
1413
title: 'Intro to time travel',
1514
href: '/time-travel-intro',
@@ -149,7 +148,7 @@ export const navigation: NavigationItem[] = [
149148
{ title: 'Overview', href: '/test-runners/overview', icon: 'overview' },
150149
{
151150
title: 'Cypress.io',
152-
href: '',
151+
href: '/test-runners/cypress-io',
153152
icon: 'cypress',
154153
links: [
155154
{
@@ -191,7 +190,7 @@ export const navigation: NavigationItem[] = [
191190
},
192191
{
193192
title: 'Playwright',
194-
href: '',
193+
href: '/test-runners/playwright/record-your-first-replay',
195194
icon: 'playwright',
196195
links: [
197196
{
@@ -202,7 +201,7 @@ export const navigation: NavigationItem[] = [
202201
{
203202
title: 'Debugging tests',
204203
href: '/test-runners/playwright/debugging-tests',
205-
icon: 'debuggingtests'
204+
icon: 'debuggingtests',
206205
},
207206
{
208207
title: 'GitHub actions',

0 commit comments

Comments
 (0)