-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathSkipLinks.tsx
63 lines (57 loc) · 1.33 KB
/
SkipLinks.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/** @jsxImportSource @emotion/react */
import { type AnchorHTMLAttributes, Fragment, useCallback } from 'react'
import { useMediaQuery } from '../lib/media'
function SkipLink(props: AnchorHTMLAttributes<HTMLAnchorElement>) {
return (
<a
css={{
display: 'block',
position: 'fixed',
top: '-100rem',
left: 0,
right: 0,
padding: '1rem',
background: 'var(--app-bg)',
color: 'var(--text-heading)',
border: '3px solid var(--link)',
zIndex: 2,
':focus': {
top: 0,
},
}}
{...props}
/>
)
}
export function SkipLinks() {
const mq = useMediaQuery()
const skip = useCallback(
() => () => {
const skipTarget = document.getElementById('skip-link-navigation-btn')
skipTarget?.focus()
},
[]
)
return (
<Fragment>
<SkipLink
href="#skip-link-navigation"
css={mq({
display: ['none', null, 'block'],
})}
>
Skip to Page Navigation
</SkipLink>
<SkipLink
href="#skip-link-navigation-btn"
css={mq({
display: ['block', null, 'none'],
})}
onClick={skip}
>
Skip to Page Navigation
</SkipLink>
<SkipLink href="#skip-link-content">Skip to Content</SkipLink>
</Fragment>
)
}