Skip to content

Commit 176a9b3

Browse files
committed
style: improve a11y with contrast and aria-hidden
1 parent e1a4544 commit 176a9b3

File tree

2 files changed

+28
-23
lines changed

2 files changed

+28
-23
lines changed

example/src/gatsby-plugin-theme-ui/components.js

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,32 @@ import code from '../components/code'
66
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
77
import { faLink } from '@fortawesome/free-solid-svg-icons'
88

9+
const Anchor = ({ id }) => (
10+
<a
11+
aria-hidden
12+
href={`#${id}`}
13+
sx={{
14+
position: 'absolute',
15+
transform: 'translateX(-100%)',
16+
mt: '-2px',
17+
color: 'primary',
18+
textDecoration: 'none',
19+
':focus .anchor-icon': {
20+
visibility: 'visible'
21+
}
22+
}}
23+
>
24+
<FontAwesomeIcon
25+
icon={faLink}
26+
className='anchor-icon'
27+
sx={{
28+
visibility: 'hidden',
29+
fontSize: 1
30+
}}
31+
/>
32+
</a>
33+
)
34+
935
const heading = (Tag) => (props) => {
1036
if (!props.id) return <Tag {...props} />
1137
return (
@@ -17,28 +43,7 @@ const heading = (Tag) => (props) => {
1743
}
1844
}}
1945
>
20-
<a
21-
href={`#${props.id}`}
22-
sx={{
23-
position: 'absolute',
24-
transform: 'translateX(-100%)',
25-
mt: '-2px',
26-
color: 'primary',
27-
textDecoration: 'none',
28-
':focus .anchor-icon': {
29-
visibility: 'visible'
30-
}
31-
}}
32-
>
33-
<FontAwesomeIcon
34-
icon={faLink}
35-
className='anchor-icon'
36-
sx={{
37-
visibility: 'hidden',
38-
fontSize: 1
39-
}}
40-
/>
41-
</a>
46+
<Anchor {...props} />
4247
{props.children}
4348
</Tag>
4449
)

example/src/gatsby-plugin-theme-ui/theme.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const theme = {
1010
colors: {
1111
text: 'hsl(165, 20%, 20%)',
1212
background: 'hsl(190, 10%, 98%)',
13-
primary: 'hsl(165, 60%, 30%)',
13+
primary: 'hsl(165, 60%, 25%)',
1414
secondary: 'hsl(125, 80%, 35%)',
1515
highlight: 'hsl(114, 40%, 90%)',
1616
muted: 'hsl(165, 20%, 94%)',

0 commit comments

Comments
 (0)