forked from marcysutton/js-a11y-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add router skip link interaction and test
TODO: figure out how to live code this from scratch and keep in source control
- Loading branch information
Marcy Sutton
committed
Jul 29, 2019
1 parent
b5f2332
commit 4f4cd63
Showing
14 changed files
with
132 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
/// <reference types="Cypress" /> | ||
describe("Accessibility checks", () => { | ||
beforeEach(() => { | ||
}) | ||
it("Has no detectable a11y violations on load", () => { | ||
cy.visit("http://localhost:8000") | ||
cy.injectAxe() | ||
cy.wait(500) | ||
}) | ||
it("Has no detectable a11y violations on load", () => { | ||
cy.checkA11y() | ||
}) | ||
it("Handles focus on route change via click", () => { | ||
cy.visit("http://localhost:8000") | ||
cy.focused() | ||
.should("not.have.class", "routeSkipLink") | ||
|
||
cy.get('#page-navigation').find('a').eq(0).click() | ||
|
||
cy.focused() | ||
.should("have.class", "routeSkipLink") | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
exports.onRouteUpdate = ({ location, prevLocation }) => { | ||
if (prevLocation !== null) { | ||
const skipLink = document.querySelector('.routeSkipLink') | ||
if (skipLink) { | ||
skipLink.focus() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React from "react" | ||
import { css } from "@emotion/core" | ||
|
||
const styles = css` | ||
.routeSkipHeading { | ||
position: relative; | ||
} | ||
.routeSkipLink { | ||
display: inline-block; | ||
margin-left: -0.75em; | ||
opacity: 0; | ||
position: absolute; | ||
text-decoration: none; | ||
} | ||
.routeSkipLink:before { | ||
content: '⇽'; | ||
display: block; | ||
} | ||
.routeSkipLink:focus, | ||
.routeSkipLink:hover { | ||
opacity: 1; | ||
} | ||
` | ||
const RouteHeading = ({level = 1, targetID, children}) => { | ||
const Heading = `h${level}`; | ||
return ( | ||
<Heading css={styles} className="routeSkipHeading"> | ||
<a href={`#${targetID}`} | ||
id="skip-main" | ||
className="routeSkipLink" | ||
aria-label={`back to ${targetID}`} | ||
title={`Skip to ${targetID}`}> | ||
</a> | ||
{children} | ||
</Heading> | ||
) | ||
} | ||
export default RouteHeading |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters