Skip to content

Commit e0e51c8

Browse files
committed
update and implement SkipLink
refactor to button for onClick handler; next.js link not currently moving element focus after following an internal hash link vercel/next.js#49386
1 parent e093121 commit e0e51c8

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

src/components/SkipLink.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
import React from "react"
1+
import { useTranslation } from "next-i18next"
22
import { Box } from "@chakra-ui/react"
33

4-
import { BaseLink } from "../components/Link"
4+
import { MAIN_CONTENT_ID } from "@/lib/constants"
55

6-
import Translation from "./Translation"
6+
import { Button } from "./Buttons"
77

8-
export interface IProps {
9-
hrefId: string
10-
}
8+
export const SkipLink = () => {
9+
const { t } = useTranslation("common")
1110

12-
export const SkipLink: React.FC<IProps> = ({ hrefId }) => {
11+
const handleNavigate = () => {
12+
document?.getElementById(MAIN_CONTENT_ID)?.focus()
13+
}
1314
return (
1415
<Box bg="primary.base">
15-
<BaseLink
16-
href={hrefId}
16+
<Button
17+
h="8"
18+
onClick={handleNavigate}
1719
lineHeight="taller"
1820
position="absolute"
1921
top="-12"
@@ -23,8 +25,8 @@ export const SkipLink: React.FC<IProps> = ({ hrefId }) => {
2325
_hover={{ textDecoration: "none" }}
2426
_focus={{ position: "static" }}
2527
>
26-
<Translation id="skip-to-main-content" />
27-
</BaseLink>
28+
{t("skip-to-main-content")}
29+
</Button>
2830
</Box>
2931
)
3032
}

src/layouts/RootLayout.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { Root } from "@/lib/interfaces"
99
import FeedbackWidget from "@/components/FeedbackWidget"
1010
import Footer from "@/components/Footer"
1111
import Nav from "@/components/Nav"
12+
import { SkipLink } from "@/components/SkipLink"
1213
import TranslationBanner from "@/components/TranslationBanner"
1314
import TranslationBannerLegal from "@/components/TranslationBannerLegal"
1415

@@ -45,6 +46,8 @@ export const RootLayout = ({
4546

4647
return (
4748
<Container mx="auto" maxW={oldTheme.variables.maxPageWidth}>
49+
<SkipLink />
50+
4851
<Nav path={asPath} />
4952

5053
<TranslationBanner

tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@
8989
"./src/components/SideNavMobile.tsx",
9090
"./src/components/SimpleTable.tsx",
9191
"./src/components/Simulator",
92-
"./src/components/SkipLink.tsx",
9392
"./src/components/Slider/Slider.stories.tsx",
9493
"./src/components/Slider/index.tsx",
9594
"./src/components/StablecoinAccordion/AccordionCustomItem.tsx",

0 commit comments

Comments
 (0)