Skip to content

Commit

Permalink
feat(a11y): Add skip link pattern.
Browse files Browse the repository at this point in the history
Add a skip link pattern so keyboard users can tab to content, search results, the footer, etc. more
efficiently.

Closes #123.
  • Loading branch information
kendrick committed Jun 20, 2017
1 parent cc86c2a commit 12f3383
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 14 deletions.
3 changes: 2 additions & 1 deletion rocketbelt/base/_base.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import 'animation/animation',
@import 'a11y/a11y',
'animation/animation',
'color/color',
'grid/grid',
'layout/layout',
Expand Down
5 changes: 5 additions & 0 deletions rocketbelt/base/a11y/_a11y-skip-links.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ul.skip.list-reset
li
a.button-sm.button-secondary(href='#content') Skip to Main Content
li
a.button-sm.button-secondary(href='#footer') Skip to Footer
19 changes: 19 additions & 0 deletions rocketbelt/base/a11y/_a11y.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.skip {
a {
@extend %visually-hidden;
@extend %focusable;

min-width: 0;
text-transform: none;
opacity: 0;
transition: opacity 100ms;

&:focus,
&:active {
// Don't forget to add top/left positioning properties for your use case!
position: absolute;
padding: 0.125rem;
opacity: 1;
}
}
}
26 changes: 14 additions & 12 deletions rocketbelt/tools/placeholders/_visually-hidden.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,20 @@
border: 0;
white-space: nowrap;
clip-path: inset(50%);
}


// Genius idea from H5BP. See https://github.com/h5bp/html5-boilerplate/blob/024b8a05ee9acf99393469c0622e55a694542493/src/css/main.css#L147
&.focusable:active,
&.focusable:focus {
position: static;
overflow: visible;
clip: auto;
margin: 0;
width: auto;
height: auto;
white-space: inherit;
clip-path: none;
// Genius idea from H5BP. See https://github.com/h5bp/html5-boilerplate/blob/024b8a05ee9acf99393469c0622e55a694542493/src/css/main.css#L147
%focusable {
&:active,
&:focus {
position: static;
overflow: visible;
clip: auto;
margin: 0;
width: auto;
height: auto;
white-space: inherit;
clip-path: none;
}

}
1 change: 1 addition & 0 deletions templates/_layout.pug
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ html(lang='en')
script(src='https://code.jquery.com/jquery-2.2.4.min.js')

body.grid-fluid
include /base/a11y/_a11y-skip-links.pug
#docs-wrapper.row
nav#docs-leftnav.nav.col.xs-12.md-3.xl-2
a.rb-header.grid-fluid(href='/')
Expand Down
2 changes: 1 addition & 1 deletion templates/_mixins.pug
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ mixin buildNav(navObject, rootHref)
if shortName !== 'img'
li.category(ref=shortName)
if _.find(item.children, function (i) { return ( i.name && i.name.indexOf('index.') > -1 ) })
a(href=newRootHref + '/' + item.name.replace('jade', 'html')) #{name.replace('.jade', '')}
a(href=newRootHref + '/' + item.name.replace('jade', 'html')) #{name.replace('.jade', '').replace('A11y', 'Accessibility')}
else
input.category-toggle(id=name, type='checkbox', name=name)
label.category-label(for=name) #{name}
Expand Down
15 changes: 15 additions & 0 deletions templates/base/a11y/index.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
extends /_layout.pug

block vars
- var title = 'Accessibility'

block content
article.grid-article
h1 Accessibility
| Rocketbelt strives to be accessible out of the box.

h2 Skip Links
| Main content or items in a page's footer may require dozens or hundreds Tab presses to interact with if a user is navigating via keyboard. Skip links make this interaction much less tedious by using an on-page href. The link is visually hidden unless it is focused via keyboard.

+exampleCodeOnly
include _a11y-skip-links.pug
9 changes: 9 additions & 0 deletions templates/scss/_a11y.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.skip {
a {
&:focus,
&:active {
top: 0.5rem;
left: 12rem;
}
}
}
1 change: 1 addition & 0 deletions templates/scss/site.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@import 'vendor/vendor',
'../../rocketbelt/tools/tools',
'a11y',
'color',
'grid',
'icons',
Expand Down

0 comments on commit 12f3383

Please sign in to comment.