Skip to content

Commit c3fe034

Browse files
authored
Website - CodeBlock a11y improvements docs (#2896)
1 parent bbefe2f commit c3fe034

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

website/docs/components/code-block/partials/code/component-api.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ This component uses [prism.js](https://prismjs.com/) under the hood.
1111
<C.Property @name="<[CB].Description>" @type="yielded component">
1212
`ContentBlock::Description` yielded as contextual component (see below).
1313
</C.Property>
14+
<C.Property @name="ariaLabel" @type="string">
15+
Accepts a localized string. The `ariaLabel` value is applied to the code block pre element.
16+
</C.Property>
17+
<C.Property @name="ariaLabelledBy" @type="string">
18+
Accepts a localized string. The `ariaLabelledBy` value is applied to the code block pre element.
19+
</C.Property>
20+
<C.Property @name="ariaDescribedBy" @type="string">
21+
Accepts a localized string. The `ariaDescribedBy` value is applied to the code block pre element.
22+
</C.Property>
1423
<C.Property @name="value" @type="string" @required={{true}}>
1524
The text/code content for the `CodeBlock`. The component encodes this argument before displaying it.
1625
</C.Property>

website/docs/components/code-block/partials/code/how-to-use.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## How to use this component
22

3+
To use this component, you must either include the yielded `Title` component, provide an `@ariaLabel`, or specify an `@ariaLabelledBy`.
4+
35
The basic invocation requires a `@value` argument. The component encodes this argument before displaying it.
46

57
!!! Info
@@ -10,6 +12,7 @@ If the `\n` escape sequence is used in the `@value` string in Handlebars, it wil
1012

1113
```handlebars
1214
<Hds::CodeBlock
15+
@ariaLabel="basic usage"
1316
@value="aws ec2 --region us-west-1 accept-vpc-peering-connection"
1417
/>
1518
```
@@ -70,6 +73,7 @@ The `language` argument sets the syntax highlighting used. We only support the f
7073

7174
```handlebars
7275
<Hds::CodeBlock
76+
@ariaLabel="language"
7377
@language="go"
7478
@value="package main
7579
import fmt
@@ -85,6 +89,7 @@ Set `hasCopyButton` to `true` to display a button for users to copy `CodeBlock`
8589

8690
```handlebars
8791
<Hds::CodeBlock
92+
@ariaLabel="copy button"
8893
@language="javascript"
8994
@hasCopyButton={{true}}
9095
@copyButtonText="Copy javascript code"
@@ -99,6 +104,7 @@ Line numbers are displayed by default. Set `hasLineNumbers` to `false` to hide t
99104

100105
```handlebars
101106
<Hds::CodeBlock
107+
@ariaLabel="line numbers"
102108
@language="javascript"
103109
@hasLineNumbers={{false}}
104110
@value="let codeLang=`JavaScript`;
@@ -118,6 +124,7 @@ By default, long lines of code will overflow the `CodeBlock` container requiring
118124

119125
```handlebars
120126
<Hds::CodeBlock
127+
@ariaLabel="line wrapping"
121128
@language="javascript"
122129
@hasLineWrapping={{true}}
123130
@value="console.log(`I am JavaScript code`, `Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam`);"
@@ -130,6 +137,7 @@ Highlight either individual code lines or a range of code lines. (Examples: `2,
130137

131138
```handlebars
132139
<Hds::CodeBlock
140+
@ariaLabel="line highlighting"
133141
@language="javascript"
134142
@highlightLines={{"2, 4"}}
135143
@value="import Application from `@ember/application`;

website/docs/components/code-editor/partials/code/component-api.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ This component uses [CodeMirror 6](https://codemirror.net/) under the hood.
2020
<C.Property @name="ariaLabelledBy" @type="string">
2121
Accepts a localized string. The `ariaLabelledBy` value is applied to the code editor input element.
2222
</C.Property>
23+
<C.Property @name="ariaDescribedBy" @type="string">
24+
Accepts a localized string. The `ariaDescribedBy` value is applied to the code editor input element.
25+
</C.Property>
2326
<C.Property @name="hasCopyButton" @type="boolean" @default="false">
2427
Used to control whether a copy button for copying the code/text content will be displayed.
2528
</C.Property>

0 commit comments

Comments
 (0)