diff --git a/src/components/Header.astro b/src/components/Header.astro index 5b597266fb..9b494d34cf 100644 --- a/src/components/Header.astro +++ b/src/components/Header.astro @@ -189,7 +189,38 @@ const isActive = (path: string) => { }); } - toggleNav(); + function handleSkipToContent() { + const skipLink = document.getElementById("skip-to-content"); + if (!skipLink) return; + skipLink.addEventListener("click", e => { + if ( + e.defaultPrevented || + e.metaKey || + e.ctrlKey || + e.shiftKey || + e.button !== 0 + ) + return; + e.preventDefault(); + const target = document.getElementById("main-content"); + if (target) { + target.setAttribute("tabindex", "-1"); + target.addEventListener( + "blur", + () => target.removeAttribute("tabindex"), + { + once: true, + } + ); + target.focus(); + target.scrollIntoView({ behavior: "smooth" }); + } + }); + } + toggleNav(); document.addEventListener("astro:after-swap", toggleNav); + + handleSkipToContent(); + document.addEventListener("astro:after-swap", handleSkipToContent); diff --git a/src/pages/404.astro b/src/pages/404.astro index b533a2aec9..9cd0c2986a 100644 --- a/src/pages/404.astro +++ b/src/pages/404.astro @@ -16,7 +16,7 @@ const t = useTranslations(locale);

404

diff --git a/src/pages/index.astro b/src/pages/index.astro index 49a3bf74ed..3c1e5f619e 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -31,7 +31,7 @@ const homePath = getRelativeLocaleUrl(locale, ""); id="main-content" data-layout="index" data-home-path={homePath} - class="app-layout" + class="app-layout my-1" >

diff --git a/src/styles/global.css b/src/styles/global.css index 262e0a1471..f4396bd891 100644 --- a/src/styles/global.css +++ b/src/styles/global.css @@ -12,7 +12,8 @@ scrollbar-color: var(--color-muted) transparent; } a, - button { + button, + #main-content { @apply outline-accent outline-offset-1 focus-visible:no-underline focus-visible:outline-2 focus-visible:outline-dashed; } button:not(:disabled),