You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
IDE — Enable keyboard navigation, move alternativeText to individual files and chat (#890)
* moved alt text to individual tabs and chat
* allow tab switch before animation completes
* add useTabs hook
* simplified useTabs hook
* implement useTabs hook in IDE
* fix tests
* remove alt text from IDE usage
* fix my bug
* fix failing test suite
* update docs
* add changeset
* typo
* minor fixes
* replace usage of Idx with Index
* update changeset
* rename variables
* replace i with index
Enabled keyboard navigation in the `IDE` component and made the contents navigable by screen readers.
6
+
7
+
⚠️ Breaking changes
8
+
9
+
The `alternativeText` prop on the `IDE` component has been removed in favour of more granular descriptive text.
10
+
11
+
<tablewidth="100%">
12
+
<tr>
13
+
<th> Before</th>
14
+
</tr>
15
+
<tr>
16
+
<tdvalign="top">
17
+
18
+
```tsx
19
+
<IDEalternativeText="A user asks how to concatenate arrays in JavaScript, Copilot demonstrates using the concat method, and the user confirms it worked.">
20
+
<IDE.Chat />
21
+
</IDE>
22
+
```
23
+
24
+
</td>
25
+
</tr>
26
+
<tr>
27
+
<th> After</th>
28
+
</tr>
29
+
<tr>
30
+
<tdvalign="top">
31
+
32
+
```tsx
33
+
<IDE>
34
+
<IDE.ChatalternativeText="A user asks how to concatenate arrays in JavaScript, Copilot demonstrates using the concat method, and the user confirms it worked." />
35
+
</IDE>
36
+
```
37
+
38
+
</td>
39
+
</tr>
40
+
</table>
41
+
42
+
<tablewidth="100%">
43
+
<tr>
44
+
<th> Before</th>
45
+
</tr>
46
+
<tr>
47
+
<tdvalign="top">
48
+
49
+
```tsx
50
+
<IDEalternativeText="TypeScript sentiment analysis function with D3.js visualization.">
51
+
<IDE.Editor
52
+
files={[
53
+
{
54
+
name: 'index.js',
55
+
},
56
+
]}
57
+
/>
58
+
</IDE>
59
+
```
60
+
61
+
</td>
62
+
</tr>
63
+
<tr>
64
+
<th> After</th>
65
+
</tr>
66
+
<tr>
67
+
<tdvalign="top">
68
+
69
+
```tsx
70
+
<IDE>
71
+
<IDE.Editor
72
+
files={[
73
+
{
74
+
name: 'index.js',
75
+
alternativeText: 'TypeScript sentiment analysis function with D3.js visualization.',
76
+
// ...
77
+
},
78
+
]}
79
+
/>
80
+
</IDE>
81
+
```
82
+
83
+
</td>
84
+
</tr>
85
+
</table>
86
+
87
+
🔗 [See the documentation for example usage, and more information on accessibility in the `IDE` component](https://primer.style/brand/components/IDE#accessibility)
Copy file name to clipboardExpand all lines: apps/docs/content/components/IDE.mdx
+42-27Lines changed: 42 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,15 +34,14 @@ See Storybook for examples of `IDE` using `highlight.js` syntax highlighter.
34
34
</Note>
35
35
36
36
```jsx live
37
-
<IDE
38
-
alternativeText="An interactive development environment displaying two code files: 'index.js' and 'parse_expenses.py'. The 'index.js' file contains JavaScript code for a function that fetches data and draws a scatterplot. The 'parse_expenses.py' file contains Python code for a function that parses expense data."
39
-
height={500}
40
-
>
37
+
<IDE height={500}>
41
38
<IDE.Editor
42
39
showReplayButton={false}
43
40
files={[
44
41
{
45
42
name:'index.js',
43
+
alternativeText:
44
+
'TypeScript sentiment analysis function with D3.js visualization.',
46
45
code:`import { fetch } from "fetch-h2";
47
46
48
47
async function isPositive(text: string): Promise<boolean> {
@@ -60,8 +59,10 @@ async function isPositive(text: string): Promise<boolean> {
60
59
},
61
60
{
62
61
name:'parse_expenses.py',
62
+
alternativeText:
63
+
'Python function that converts financial transaction strings into structured data, parsing dates, amounts, and currencies while skipping comments',
63
64
code:`import datetime
64
-
65
+
65
66
def parse_expenses(expenses_string):
66
67
Ignore lines starting with #.
67
68
Parse the date using datetime.
@@ -90,14 +91,14 @@ return expenses`,
90
91
Line-by-line animations can be enabled using pre-formatted prop values. A replay button is enabled by default.
91
92
92
93
```jsx live
93
-
<IDE
94
-
alternativeText="An interactive development environment displaying one code file: 'index.js'. The 'index.js' file contains JavaScript code for a function that fetches data and draws a scatterplot. Each line animates into view line-by-line."
95
-
height={500}
96
-
>
94
+
<IDE height={500}>
97
95
<IDE.Editor
98
96
files={[
99
97
{
100
98
name:'index.js',
99
+
alternativeText:
100
+
'TypeScript sentiment analysis function with D3.js visualization.',
101
+
101
102
code:`import { fetch } from "fetch-h2";
102
103
103
104
async function isPositive(text: string): Promise<boolean> {
@@ -125,16 +126,16 @@ async function isPositive(text: string): Promise<boolean> {
125
126
Simulate GitHub Copilot suggestions using the `suggestedLineStart` property.
126
127
127
128
```jsx live
128
-
<IDE
129
-
alternativeText="An interactive development environment displaying one code file: 'index.js'. The 'index.js' file contains JavaScript code for a function that fetches data and draws a scatterplot. Line 6 onwards contains a GitHub Copilot auto suggestion."
130
-
height={500}
131
-
>
129
+
<IDE height={500}>
132
130
<IDE.Editor
133
131
files={[
134
132
{
135
133
name:'index.js',
136
134
// Line number at which the suggestion will apply
137
135
suggestedLineStart:6,
136
+
alternativeText:
137
+
'TypeScript sentiment analysis function with D3.js visualization. Copilot suggests completing the scatterplot with SVG creation and circle attributes.',
138
+
138
139
code:`import { fetch } from "fetch-h2";
139
140
140
141
async function isPositive(text: string): Promise<boolean> {
@@ -172,11 +173,9 @@ See Storybook for a comprehensive example of the Chat feature, inclusive of synt
172
173
</Note>
173
174
174
175
```jsx live
175
-
<IDE
176
-
alternativeText="A chat interface showing a conversation between a user named 'monalisa' and an assistant named 'GitHub Copilot'. Monalisa asks 'How do I concatenate two arrays in JavaScript"
177
-
height={700}
178
-
>
176
+
<IDE height={700}>
179
177
<IDE.Chat
178
+
alternativeText="A user asks how to concatenate arrays in JavaScript, Copilot demonstrates using the concat method, and the user confirms it worked."
180
179
script={[
181
180
{
182
181
role:'user',
@@ -223,6 +222,8 @@ A `glass` variant is available to simplify placement of the `IDE` on background
223
222
files={[
224
223
{
225
224
name:'index.js',
225
+
alternativeText:
226
+
'TypeScript sentiment analysis function with D3.js visualization.',
226
227
code:`import { fetch } from "fetch-h2";
227
228
228
229
async function isPositive(text: string): Promise<boolean> {
@@ -240,8 +241,11 @@ async function isPositive(text: string): Promise<boolean> {
240
241
},
241
242
{
242
243
name:'parse_expenses.py',
244
+
alternativeText:
245
+
'Python function description and docstring showing how to parse financial transactions with example date, amount, and currency formats.',
246
+
243
247
code:`import datetime
244
-
248
+
245
249
def parse_expenses(expenses_string):
246
250
Ignore lines starting with #.
247
251
Parse the date using datetime.
@@ -257,15 +261,25 @@ Example expenses_string:
257
261
</Box>
258
262
```
259
263
264
+
## Accessibility
265
+
266
+
The full contents of `IDE.Chat` and `IDE.Editor` are intentionally not made available to users of assistive technologies. Summaries of the content — which must be provided using the `alternativeText` prop — are made available instead.
267
+
268
+
When writing `alternativeText`, consider the following:
269
+
270
+
- The `IDE.Chat` script should be summarized in a way that conveys the essential information of the conversation.
271
+
- The `IDE.Editor` code should be summarized in a way that conveys the essential information of the code snippet, specifically noting any suggestions made by Copilot.
272
+
273
+
In both cases, the goal is to provide a meaningful summary of the content that will allow users of assistive technologies to understand the purpose and scope of the conversation or code snippet, without needing to understand the full content.
274
+
260
275
## Component props
261
276
262
277
### IDE <Label>Required</Label>
263
278
264
-
| name | type | default | required | description |
0 commit comments