Skip to content

Commit 7a9bc56

Browse files
Fixing navbar hover and active page state
1 parent 0279ed2 commit 7a9bc56

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.next
22
node_modules
33
.env
4+
.DS_Store
45

components/Nav.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import Image from 'next/image';
44
import Container from './Container';
55
import styles from '../styles/Nav.module.scss';
66
import { linksNav } from '../utils/links';
7+
import { useRouter } from 'next/router';
78

89
export default function Nav() {
10+
const router = useRouter();
911
const [active, setActive] = useState(false);
1012
const headerRef = useRef();
1113
const containerRef = useRef();
@@ -62,7 +64,12 @@ export default function Nav() {
6264
return (
6365
<li className={styles.nav__item} key={id}>
6466
<Link href={href}>
65-
<a className={styles.nav__link} title={text}>
67+
<a
68+
className={`${styles.nav__link} ${
69+
router.pathname == href ? `${styles.current}` : ''
70+
}`}
71+
title={text}
72+
>
6673
{text}
6774
</a>
6875
</Link>

styles/Nav.module.scss

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,22 @@
116116
line-height: 2.5;
117117
font-weight: 400;
118118
display: block;
119+
@include transition(all 0.3s ease);
120+
121+
&:hover,
122+
&.current {
123+
font-weight: 600;
124+
}
125+
126+
&:before {
127+
display: block;
128+
content: attr(title);
129+
font-weight: bold;
130+
height: 1px;
131+
color: transparent;
132+
overflow: hidden;
133+
visibility: hidden;
134+
}
119135

120136
@include large-desktop {
121137
font-size: 1.5rem;
@@ -143,7 +159,7 @@
143159
width: 25px;
144160
height: 2px;
145161
margin: 5px auto;
146-
transition: all 0.3s ease-in-out;
162+
@include transition(opacity 0.3s ease);
147163
background-color: $white;
148164
}
149165

0 commit comments

Comments
 (0)