Skip to content

Commit

Permalink
Improve permalink a11y (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffrich authored Apr 24, 2021
1 parent f6967c9 commit 766775d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 16 deletions.
13 changes: 13 additions & 0 deletions packages/site-kit/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -566,3 +566,16 @@ input[type='checkbox']::after {
input[type='checkbox']:checked::after {
left: calc(100% - 1em + 2px);
}

/* visually hidden, but accessible to assistive tech */
.visually-hidden {
border: 0;
clip: rect(0 0 0 0);
height: auto;
margin: 0;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
white-space: nowrap;
}
20 changes: 7 additions & 13 deletions packages/site-kit/components/Docs.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { onMount } from 'svelte';
import GuideContents from './GuideContents.svelte'; // TODO rename
import Icon from './Icon.svelte';
import Permalink from './Permalink.svelte';
import { getFragment } from '../utils/navigation';
import '../code.css';
Expand Down Expand Up @@ -77,11 +78,8 @@
<section data-id={section.slug}>
<h2>
<span class="offset-anchor" id={section.slug}></span>

<!-- svelte-ignore a11y-missing-content -->
<a href="{dir}#{section.slug}" class="anchor" aria-hidden></a>

{@html section.title}
<Permalink href="{dir}#{section.slug}" />
<small>
<a href="https://github.com/{owner}/{project}/edit/master{path}/{dir}/{section.file}" title="{edit_title}">
<Icon name='edit' />
Expand Down Expand Up @@ -260,13 +258,14 @@
background-size: 1em 1em;
width: 1.4em;
height: 1em;
top: 0;
left: -1.3em;
opacity: 0;
transition: opacity 0.2s;
border: none !important; /* TODO get rid of linkify */
}
@media (min-width: 768px) {
.content :global(.anchor:focus),
.content :global(h2):hover :global(.anchor),
.content :global(h3):hover :global(.anchor),
.content :global(h4):hover :global(.anchor),
Expand All @@ -275,9 +274,8 @@
opacity: 1;
}
.content :global(h5) :global(.anchor),
.content :global(h6) :global(.anchor) {
top: 0.25em;
.content :global(h2) :global(.anchor) {
top: 0.75em;
}
}
Expand Down Expand Up @@ -391,10 +389,6 @@
cursor: pointer;
}
/* no linkify on these */
small a { all: unset }
small a:before { all: unset }
section :global(blockquote) {
/* color: #ff3e00; */
color: rgba(0,0,0,0.7);
Expand Down Expand Up @@ -428,4 +422,4 @@
/* background: none !important; */
background: rgba(255,62,0,0.1) !important;
}
</style>
</style>
7 changes: 7 additions & 0 deletions packages/site-kit/components/Permalink.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script>
export let href;
</script>

<a {href} class="anchor">
<span class="visually-hidden">permalink</span>
</a>
3 changes: 2 additions & 1 deletion packages/site-kit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ export { default as Docs } from './components/Docs.svelte';
export { default as Hero } from './components/Hero.svelte';
export { default as Icon } from './components/Icon.svelte';
export { default as Icons } from './components/Icons.svelte';
export { default as Permalink } from './components/Permalink.svelte';
export { default as PreloadingIndicator } from './components/PreloadingIndicator.svelte';
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 PreloadingIndicator } from './components/PreloadingIndicator.svelte';
6 changes: 4 additions & 2 deletions sites/kit.svelte.dev/src/routes/faq/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
</script>

<script>
import { Permalink } from "@sveltejs/site-kit";
export let faqs;
</script>

Expand All @@ -26,8 +28,8 @@
<article class="faq">
<h2>
<a id={faq.slug} class="offset-anchor" />
<a class="anchor" sapper:prefetch href="faq#{faq.slug}" title={faq.title}>&nbsp;</a>
{faq.title}
<Permalink href="faq#{faq.slug}" />
</h2>
{@html faq.content}
</article>
Expand Down Expand Up @@ -77,7 +79,6 @@
left: -1.3em;
opacity: 0;
transition: opacity 0.2s;
border: none !important; /* TODO get rid of linkify */
}
.faqs :global(h2 > .anchor),
Expand All @@ -86,6 +87,7 @@
}
@media (min-width: 768px) {
.content :global(.anchor:focus),
.faqs :global(h2):hover :global(.anchor),
.faqs :global(h3):hover :global(.anchor),
.faqs :global(h4):hover :global(.anchor),
Expand Down

0 comments on commit 766775d

Please sign in to comment.