Skip to content

Commit a90cfdd

Browse files
committed
docs(community): highlight active video nav link (aria-current)
1 parent 11024aa commit a90cfdd

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

src/components/Navigation/index.tsx

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,41 @@
1616

1717
import React, { type ReactNode } from 'react';
1818
import Link from '@docusaurus/Link';
19+
import { useLocation } from '@docusaurus/router';
20+
import useBaseUrl from '@docusaurus/useBaseUrl';
1921
import styles from './styles.module.css';
2022

21-
function Navigation({ links }) {
23+
interface NavLink {
24+
label: string;
25+
href: string;
26+
}
27+
28+
interface NavigationProps {
29+
links: NavLink[];
30+
}
31+
32+
function Navigation({ links }: NavigationProps) {
33+
const location = useLocation();
34+
2235
return (
2336
<nav className="container">
2437
<ul className={styles.nav}>
25-
{links.map((link, i) => (
26-
<li key={i} className={styles.links}>
27-
<Link href={link.href}>{link.label}</Link>
28-
</li>
29-
))}
38+
{links.map((link, i) => {
39+
const baseHref = useBaseUrl(link.href);
40+
const isActive = location.pathname === baseHref ||
41+
location.pathname.startsWith(baseHref + '/');
42+
43+
return (
44+
<li key={i} className={`${styles.links} ${isActive ? styles.active : ''}`}>
45+
<Link
46+
href={link.href}
47+
aria-current={isActive ? 'page' : undefined}
48+
>
49+
{link.label}
50+
</Link>
51+
</li>
52+
);
53+
})}
3054
</ul>
3155
</nav>
3256
);

src/components/Navigation/styles.module.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@
44
gap: 2rem;
55
justify-content: center;
66
}
7+
8+
.active a {
9+
font-weight: 700;
10+
text-decoration: underline;
11+
}

0 commit comments

Comments
 (0)