Skip to content

Commit d48ce10

Browse files
committed
Indicate what page is active on sidebar
Highlights what page is currently active on sidebar. Fixes #62
1 parent 4eb44ae commit d48ce10

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/ui/components/Sidebar.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { FC } from "react";
2-
import { Link } from "react-router-dom";
2+
import { NavLink } from "react-router-dom";
33
import { Nav } from "react-bootstrap";
44

55
const links = [
@@ -18,14 +18,15 @@ const Sidebar: FC = () => {
1818
return (
1919
<Nav className="sidebar d-block rounded position-fixed m-2 light-bg">
2020
{links.map((link, index) => (
21-
<Nav.Link
21+
<NavLink
2222
key={index}
23-
as={Link}
2423
to={link.to}
25-
className="sidebar__link p-4 secondary-fg"
24+
className={({ isActive }) =>
25+
`sidebar__link p-4 d-block secondary-fg text-decoration-none ${isActive ? "active" : ""}`
26+
}
2627
>
2728
{link.text}
28-
</Nav.Link>
29+
</NavLink>
2930
))}
3031
</Nav>
3132
);

src/ui/index.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ body, html {
4343
background-color: var(--colour-primary-medium);
4444
}
4545

46+
.sidebar__link.active {
47+
background-color: var(--colour-primary);
48+
color: var(--colour-primary-light);
49+
}
50+
4651
.main-content {
4752
width: calc(100% - 15rem);
4853
height: calc(100% - 4.7rem);

0 commit comments

Comments
 (0)