Skip to content

Commit 8c5c5b5

Browse files
authored
Merge pull request #81 from dmarcey/users/dmarcey/a11y
Fixing a few accessibility issues in theme and docs package
2 parents 104046d + a693e28 commit 8c5c5b5

File tree

6 files changed

+39
-40
lines changed

6 files changed

+39
-40
lines changed

docs/content/components/caption.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ The caption component can be used to append a caption to images used in document
88

99
```jsx live
1010
<Flex alignItems="center" flexDirection="column">
11-
<img src="https://s3.us-west-2.amazonaws.com/photos.puppyspot.com/breeds/245/card/500000291_medium.jpg" />
11+
<img alt="" src="https://s3.us-west-2.amazonaws.com/photos.puppyspot.com/breeds/245/card/500000291_medium.jpg" />
1212
<Caption>A beautiful husky puppy.</Caption>
1313
</Flex>
1414
```
15+
16+
_Note: Be sure to provide enough detail in your caption so users with assistive technology have adequate context. An empty alt tag `alt=""` should be used on the `img` in cases where the caption describes the image, thus making the image decorative in purpose.

docs/content/components/do-dont.mdx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,37 @@ The `Do` and `Dont` components are used for providing good and bad examples with
1111
To use these components in your MDX files, import them like so:
1212

1313
```js
14-
import {DoDont, Do, Dont} from '@primer/gatsby-theme-doctocat'
14+
import {DoDontContainer, Do, Dont} from '@primer/gatsby-theme-doctocat'
1515
```
1616

1717
### Side-by-side
1818

19-
To create a side-by-side Do/Don't example, wrap the `Do` and `Dont` components with the `DoDont` component:
19+
To create a side-by-side Do/Don't example, wrap the `Do` and `Dont` components with the `DoDontContainer` component:
2020

2121
```jsx live
22-
<DoDont>
22+
<DoDontContainer>
2323
<Do src="https://user-images.githubusercontent.com/586552/63106528-06de5100-bf51-11e9-8a5e-98583ed74874.png">
2424
Use brief and direct communication
2525
</Do>
2626
<Dont src="https://user-images.githubusercontent.com/586552/63106527-06de5100-bf51-11e9-858c-72de6a5c728a.png">
2727
Don't use wordy and redundant copy
2828
</Dont>
29-
</DoDont>
29+
</DoDontContainer>
3030
```
3131
32-
_Note: Caption text should describe the image and be able to stand on its own._
32+
_Note: Caption text should describe the image and be able to stand on its own. The `alt` prop should be used if a more detailed description of the image is needed._
3333
3434
### Stacked
3535
36-
The `DoDont` component also accepts a `stacked` prop to create stacked Do/Don't examples:
36+
The `DoDontContainer` component also accepts a `stacked` prop to create stacked Do/Don't examples:
3737

3838
```jsx live
39-
<DoDont stacked>
39+
<DoDontContainer stacked>
4040
<Do src="https://user-images.githubusercontent.com/586552/63046880-46e5fb00-bea1-11e9-836d-be1b1c7d963f.png">
4141
Use a container class to give the text a max-width
4242
</Do>
4343
<Dont src="https://user-images.githubusercontent.com/586552/63046881-46e5fb00-bea1-11e9-87ee-80dbeb0bea1c.png">
4444
Don't let the text span the entire width of the window
4545
</Dont>
46-
</DoDont>
46+
</DoDontContainer>
4747
```

theme/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export {default as Caption} from './src/components/caption'
22
export {default as Container} from './src/components/container'
33
export {default as Contributors} from './src/components/contributors'
4-
export {Do, DoDont, Dont} from './src/components/do-dont'
4+
export {Do, DoDontContainer, Dont} from './src/components/do-dont'
55
export {default as Frame} from './src/components/frame'
66
export {default as Head} from './src/components/head'
77
export {default as Header} from './src/components/header'

theme/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@primer/gatsby-theme-doctocat",
3-
"version": "0.16.1",
3+
"version": "0.16.2",
44
"main": "index.js",
55
"license": "MIT",
66
"scripts": {

theme/src/components/do-dont.js

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {Check, X} from '@primer/octicons-react'
33
import React from 'react'
44
import Caption from './caption'
55

6-
export function DoDont({stacked, children}) {
6+
export function DoDontContainer({stacked, children}) {
77
return (
88
<Grid
99
gridTemplateColumns={['1fr', null, stacked ? '1fr' : '1fr 1fr']}
@@ -15,50 +15,40 @@ export function DoDont({stacked, children}) {
1515
)
1616
}
1717

18-
DoDont.defaultProps = {
18+
DoDontContainer.defaultProps = {
1919
stacked: false,
2020
}
2121

22-
export function Do({src, children}) {
23-
return (
24-
<Flex flexDirection="column">
25-
<Flex alignSelf="start" flexDirection="row" alignItems="center" mb="2">
26-
<CircleOcticon
27-
icon={Check}
28-
size={16}
29-
bg="green.5"
30-
color="white"
31-
mr="2"
32-
p="1"
33-
/>
34-
<Text fontWeight="bold" color="gray.9" ml="1">
35-
Do
36-
</Text>
37-
</Flex>
38-
<img src={src} width="100%" alt="" />
39-
<Caption mb={0}>{children}</Caption>
40-
</Flex>
41-
)
22+
export function Do(props) {
23+
return <DoDontBase {...props} text="Do" icon={Check} iconBg="green.5" />
4224
}
4325

44-
export function Dont({src, children}) {
26+
export function Dont(props) {
27+
return <DoDontBase {...props} text="Don't" icon={X} iconBg="red.5" />
28+
}
29+
30+
function DoDontBase({src, alt, children, text, icon, iconBg}) {
4531
return (
4632
<Flex flexDirection="column">
4733
<Flex alignSelf="start" flexDirection="row" alignItems="center" mb="2">
4834
<CircleOcticon
49-
icon={X}
35+
icon={icon}
5036
size={16}
51-
bg="red.5"
37+
bg={iconBg}
5238
color="white"
5339
mr="2"
5440
p="1"
5541
/>
5642
<Text fontWeight="bold" color="gray.9" ml="1">
57-
Don't
43+
{text}
5844
</Text>
5945
</Flex>
60-
<img src={src} width="100%" alt="" />
46+
<img src={src} alt={alt} width="100%" />
6147
<Caption mb={0}>{children}</Caption>
6248
</Flex>
6349
)
6450
}
51+
52+
DoDontBase.defaultProps = {
53+
alt: "",
54+
}

theme/src/components/heading.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,18 @@ const StyledHeading = styled(Heading)`
2222

2323
function MarkdownHeading({children, ...props}) {
2424
const slugger = new GithubSlugger()
25-
const id = children ? slugger.slug(textContent(children)) : ''
25+
const text = children ? textContent(children) : ''
26+
const id = text ? slugger.slug(text) : ''
2627

2728
return (
2829
<StyledHeading id={id} {...props}>
29-
<Link href={`#${id}`} p={2} ml={-32} color="gray.8">
30+
<Link
31+
href={`#${id}`}
32+
p={2}
33+
ml={-32}
34+
color="gray.8"
35+
aria-label={`${text} permalink`}
36+
>
3037
<StyledOcticon
3138
className="octicon-link"
3239
icon={LinkIcon}

0 commit comments

Comments
 (0)