Skip to content
This repository was archived by the owner on May 5, 2020. It is now read-only.

Commit bf4617b

Browse files
committed
Added JS to focus navigation after clicking skip link
1 parent 5c8529b commit bf4617b

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

components/SkipLink.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,23 @@ class SkipLink extends Component {
88
const { to, text } = this.props
99

1010
return (
11-
<a href={to} className="skipLink hide p-1 bgDarker-1">{ text }</a>
11+
<a href={to} className="skipLink hide p-1 bgDarker-1" onClick={this.setFocus}>{ text }</a>
1212
)
1313
}
1414

15+
setFocus() {
16+
// Functionality from: https://www.bignerdranch.com/blog/web-accessibility-skip-navigation-links/
17+
18+
// Cannot figure out why this won't work. Get error that 'cannot read property props of null'. Hardcoding instead, for now.
19+
// const target = document.getElementById(this.props.to.split('#')[0])
20+
const target = document.getElementById('nav')
21+
target.setAttribute('tabindex', -1)
22+
target.addEventListener('blur', function() {
23+
target.removeAttribute('tabindex')
24+
})
25+
target.focus()
26+
}
27+
1528
}
1629

1730
SkipLink.propTypes = {

0 commit comments

Comments
 (0)