Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add skip link to Svelte and SvelteKit sites #245

Merged
merged 4 commits into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions packages/site-kit/src/lib/components/SkipLink.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<script>
export let href;
</script>

<a {href}>Skip to main content</a>

<style>
a {
background: white;
color: var(--text);
border: 2px solid black;
padding: 8px;
position: absolute;
inset-block-start: 0;
inset-inline-start: 0;
transform: translateY(-100%);
z-index: 101; /* 1 more than the nav z-index */
}

a:focus {
transform: translateY(0%);
}
</style>
1 change: 1 addition & 0 deletions packages/site-kit/src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export { default as PreloadingIndicator } from './components/PreloadingIndicator
export { default as Nav } from './components/Nav.svelte';
export { default as NavItem } from './components/NavItem.svelte';
export { default as Section } from './components/Section.svelte';
export { default as SkipLink } from './components/SkipLink.svelte';
5 changes: 3 additions & 2 deletions sites/kit.svelte.dev/src/routes/__layout.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script>
import '@sveltejs/site-kit/base.css';
import { page, navigating } from '$app/stores';
import { Icon, Icons, Nav, NavItem, PreloadingIndicator } from '@sveltejs/site-kit';
import { Icon, Icons, Nav, NavItem, PreloadingIndicator, SkipLink } from '@sveltejs/site-kit';
</script>

<Icons />
Expand All @@ -10,6 +10,7 @@
<PreloadingIndicator />
{/if}

<SkipLink href="#main" />
<Nav {page} logo="/images/svelte-kit-horizontal.svg">
<svelte:fragment slot="nav-center">
<NavItem href="/docs">Docs</NavItem>
Expand All @@ -32,7 +33,7 @@
</svelte:fragment>
</Nav>

<main>
<main id="main">
<slot />
</main>

Expand Down
5 changes: 3 additions & 2 deletions sites/svelte.dev/src/routes/__layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import '@sveltejs/site-kit/base.css';
import { setContext } from 'svelte';
import { page, navigating, session } from '$app/stores';
import { Icon, Icons, Nav, NavItem } from '@sveltejs/site-kit';
import { Icon, Icons, Nav, NavItem, SkipLink } from '@sveltejs/site-kit';
import PreloadingIndicator from '$lib/components/PreloadingIndicator.svelte';

setContext('app', {
Expand Down Expand Up @@ -37,6 +37,7 @@
{/if}

{#if $page.url.pathname !== '/repl/embed'}
<SkipLink href="#main" />
<Nav {page} logo="/svelte-logo-horizontal.svg">
<svelte:fragment slot="nav-center">
<NavItem href="/tutorial">Tutorial</NavItem>
Expand All @@ -63,7 +64,7 @@
</Nav>
{/if}

<main>
<main id="main">
<slot />
</main>

Expand Down