Skip to content

Commit 0f3f251

Browse files
fix(nav): restore native anchor link behavior
1 parent 557f491 commit 0f3f251

File tree

2 files changed

+2
-22
lines changed

2 files changed

+2
-22
lines changed

src/components/header.tsx

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,10 @@
1-
import { type MouseEvent, useCallback } from "react";
21
import { Box, Container, Flex, NavLink } from "theme-ui";
32

43
import { Logo } from "./logo";
54

65
type LinkComponent = React.FC<{ href: string; children: React.ReactNode }>;
76

87
const MenuLink: LinkComponent = ({ href, children }) => {
9-
const goToSection = useCallback(
10-
(e: MouseEvent) => {
11-
e.preventDefault();
12-
13-
const destinationEl: HTMLElement | null =
14-
window.document.querySelector(href);
15-
16-
if (!destinationEl) {
17-
return;
18-
}
19-
20-
window.scrollTo({
21-
top: destinationEl.offsetTop,
22-
behavior: "smooth",
23-
});
24-
},
25-
[href],
26-
);
27-
288
return (
299
<NavLink
3010
sx={{
@@ -39,7 +19,6 @@ const MenuLink: LinkComponent = ({ href, children }) => {
3919
}}
4020
mt={["secondary", 0]}
4121
ml={[0, "secondary"]}
42-
onClick={goToSection}
4322
href={href}
4423
>
4524
{children}
@@ -119,7 +98,7 @@ export const Header = () => (
11998
position: "absolute",
12099
top: 0,
121100
left: 0,
122-
zIndex: 1,
101+
zIndex: 10,
123102

124103
width: "100%",
125104
}}

src/pages/_app.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const App = ({ Component, pageProps }: AppProps) => (
1111
styles={css`
1212
html {
1313
font-size: 62.5%;
14+
scroll-behavior: smooth;
1415
}
1516
body {
1617
font-size: 2rem;

0 commit comments

Comments
 (0)