Skip to content

Commit 33126c8

Browse files
Michail Yasonikcchaosthompsongl
authored
Deprecating EuiKeyboardAccessible (#4135)
Co-authored-by: Caroline Horn <[email protected]> Co-authored-by: Greg Thompson <[email protected]>
1 parent 0a1e9c2 commit 33126c8

17 files changed

+831
-594
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## [`master`](https://github.com/elastic/eui/tree/master)
22

3+
- Deprecated `EuiKeyboardAccessible` ([4135]https://github.com/elastic/eui/pull/4135)
4+
- Refactored `EuiStep`, `EuiHorizontalSteps`, and `EuiCodeEditor` for better accessibility ([4135]https://github.com/elastic/eui/pull/4135)
35
- Added `minWidth` prop to `EuiButton` ([4056](https://github.com/elastic/eui/pull/4056))
46
- Added `isSelected` prop to easily turn `EuiButton`, `EuiButtonEmpty`, and `EuiButtonIcon` into toggle buttons ([4056](https://github.com/elastic/eui/pull/4056))
57
- Updated `EuiButtonGroup` props and render for better accessibility ([4056](https://github.com/elastic/eui/pull/4056))

src-docs/src/views/accessibility/accessibility_example.js

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { renderToHtml } from '../../services';
55
import { GuideSectionTypes } from '../../components';
66

77
import {
8+
EuiBadge,
9+
EuiSpacer,
810
EuiCallOut,
911
EuiCode,
1012
EuiLink,
@@ -65,12 +67,38 @@ export const AccessibilityExample = {
6567
},
6668
],
6769
text: (
68-
<p>
69-
You can make interactive elements keyboard-accessible with the{' '}
70-
<strong>EuiKeyboardAccessible</strong> component. This is necessary
71-
for non-button elements and <EuiCode>a</EuiCode> tags without{' '}
72-
<EuiCode>href</EuiCode> attributes.
73-
</p>
70+
<>
71+
<EuiBadge
72+
color="danger"
73+
href="https://github.com/elastic/eui/issues/1469"
74+
target="_blank"
75+
iconSide="right"
76+
iconType="popout">
77+
Set for deprecation. See details.
78+
</EuiBadge>
79+
80+
<EuiSpacer />
81+
82+
<EuiCallOut
83+
color="warning"
84+
iconType="accessibility"
85+
title="Deprecated because it often causes problems for screen reader users">
86+
<p>
87+
Though this component solved some problems for keyboard-only users
88+
it also frequently introduced problems for screen reader users. As
89+
such, we don&apos;t recommend it&apos;s continued use.
90+
</p>
91+
</EuiCallOut>
92+
93+
<EuiSpacer />
94+
95+
<p>
96+
You can make interactive elements keyboard-accessible with the{' '}
97+
<strong>EuiKeyboardAccessible</strong> component. This is necessary
98+
for non-button elements and <EuiCode>a</EuiCode> tags without{' '}
99+
<EuiCode>href</EuiCode> attributes.
100+
</p>
101+
</>
74102
),
75103
props: { EuiKeyboardAccessible },
76104
snippet: keyboardAccessibleSnippet,

src-docs/src/views/steps/steps_horizontal.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,4 @@ const horizontalSteps = [
2424
},
2525
];
2626

27-
export default () => (
28-
<div>
29-
<EuiStepsHorizontal steps={horizontalSteps} />
30-
</div>
31-
);
27+
export default () => <EuiStepsHorizontal steps={horizontalSteps} />;

src/components/code_editor/__snapshots__/code_editor.test.tsx.snap

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`EuiCodeEditor behavior hint element should be disabled when the ui ace box gains focus 1`] = `
4-
<div
4+
<button
55
class="euiCodeEditorKeyboardHint"
66
data-test-subj="codeEditorHint"
77
id="htmlId"
8-
role="button"
9-
tabindex="0"
108
>
119
<p
1210
class="euiText"
@@ -18,16 +16,14 @@ exports[`EuiCodeEditor behavior hint element should be disabled when the ui ace
1816
>
1917
When you're done, press Escape to stop editing.
2018
</p>
21-
</div>
19+
</button>
2220
`;
2321

2422
exports[`EuiCodeEditor behavior hint element should be enabled when the ui ace box loses focus 1`] = `
25-
<div
23+
<button
2624
class="euiCodeEditorKeyboardHint"
2725
data-test-subj="codeEditorHint"
2826
id="htmlId"
29-
role="button"
30-
tabindex="0"
3127
>
3228
<p
3329
class="euiText"
@@ -39,16 +35,14 @@ exports[`EuiCodeEditor behavior hint element should be enabled when the ui ace b
3935
>
4036
When you're done, press Escape to stop editing.
4137
</p>
42-
</div>
38+
</button>
4339
`;
4440

4541
exports[`EuiCodeEditor behavior hint element should be tabable 1`] = `
46-
<div
42+
<button
4743
class="euiCodeEditorKeyboardHint"
4844
data-test-subj="codeEditorHint"
4945
id="htmlId"
50-
role="button"
51-
tabindex="0"
5246
>
5347
<p
5448
class="euiText"
@@ -60,20 +54,18 @@ exports[`EuiCodeEditor behavior hint element should be tabable 1`] = `
6054
>
6155
When you're done, press Escape to stop editing.
6256
</p>
63-
</div>
57+
</button>
6458
`;
6559

6660
exports[`EuiCodeEditor is rendered 1`] = `
6761
<div
6862
class="euiCodeEditorWrapper"
6963
data-test-subj="test subject string"
7064
>
71-
<div
65+
<button
7266
class="euiCodeEditorKeyboardHint"
7367
data-test-subj="codeEditorHint"
7468
id="htmlId"
75-
role="button"
76-
tabindex="0"
7769
>
7870
<p
7971
class="euiText"
@@ -85,7 +77,7 @@ exports[`EuiCodeEditor is rendered 1`] = `
8577
>
8678
When you're done, press Escape to stop editing.
8779
</p>
88-
</div>
80+
</button>
8981
<div
9082
class=" ace_editor ace-tm testClass1 testClass2"
9183
id="htmlId"
@@ -184,12 +176,10 @@ exports[`EuiCodeEditor props aria attributes allows setting aria-describedby on
184176
class="euiCodeEditorWrapper"
185177
data-test-subj="codeEditorContainer"
186178
>
187-
<div
179+
<button
188180
class="euiCodeEditorKeyboardHint"
189181
data-test-subj="codeEditorHint"
190182
id="htmlId"
191-
role="button"
192-
tabindex="0"
193183
>
194184
<p
195185
class="euiText"
@@ -201,7 +191,7 @@ exports[`EuiCodeEditor props aria attributes allows setting aria-describedby on
201191
>
202192
When you're done, press Escape to stop editing.
203193
</p>
204-
</div>
194+
</button>
205195
<div
206196
class=" ace_editor ace-tm"
207197
id="htmlId"
@@ -300,12 +290,10 @@ exports[`EuiCodeEditor props aria attributes allows setting aria-labelledby on t
300290
class="euiCodeEditorWrapper"
301291
data-test-subj="codeEditorContainer"
302292
>
303-
<div
293+
<button
304294
class="euiCodeEditorKeyboardHint"
305295
data-test-subj="codeEditorHint"
306296
id="htmlId"
307-
role="button"
308-
tabindex="0"
309297
>
310298
<p
311299
class="euiText"
@@ -317,7 +305,7 @@ exports[`EuiCodeEditor props aria attributes allows setting aria-labelledby on t
317305
>
318306
When you're done, press Escape to stop editing.
319307
</p>
320-
</div>
308+
</button>
321309
<div
322310
class=" ace_editor ace-tm"
323311
id="htmlId"
@@ -416,12 +404,10 @@ exports[`EuiCodeEditor props isReadOnly renders alternate hint text 1`] = `
416404
class="euiCodeEditorWrapper"
417405
data-test-subj="codeEditorContainer"
418406
>
419-
<div
407+
<button
420408
class="euiCodeEditorKeyboardHint"
421409
data-test-subj="codeEditorHint"
422410
id="htmlId"
423-
role="button"
424-
tabindex="0"
425411
>
426412
<p
427413
class="euiText"
@@ -433,7 +419,7 @@ exports[`EuiCodeEditor props isReadOnly renders alternate hint text 1`] = `
433419
>
434420
When you're done, press Escape to stop interacting with the code.
435421
</p>
436-
</div>
422+
</button>
437423
<div
438424
class=" ace_editor ace-tm"
439425
id="htmlId"
@@ -532,12 +518,10 @@ exports[`EuiCodeEditor props theme renders terminal theme 1`] = `
532518
class="euiCodeEditorWrapper"
533519
data-test-subj="codeEditorContainer"
534520
>
535-
<div
521+
<button
536522
class="euiCodeEditorKeyboardHint"
537523
data-test-subj="codeEditorHint"
538524
id="htmlId"
539-
role="button"
540-
tabindex="0"
541525
>
542526
<p
543527
class="euiText"
@@ -549,7 +533,7 @@ exports[`EuiCodeEditor props theme renders terminal theme 1`] = `
549533
>
550534
When you're done, press Escape to stop editing.
551535
</p>
552-
</div>
536+
</button>
553537
<div
554538
class=" ace_editor ace-tm"
555539
id="htmlId"

src/components/code_editor/_code_editor.scss

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,16 @@
1515
.euiCodeEditorKeyboardHint {
1616
position: absolute;
1717
top: 0;
18-
bottom: 0;
19-
right: 0;
2018
left: 0;
2119
background: transparentize($euiColorGhost, .3);
2220
display: flex;
2321
flex-direction: column;
2422
justify-content: center;
2523
align-items: center;
26-
text-align: center;
2724
opacity: 0;
2825
cursor: pointer;
26+
height: 100%;
27+
width: 100%;
2928

3029
&:focus {
3130
opacity: 1;

src/components/code_editor/code_editor.tsx

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* under the License.
1818
*/
1919

20-
import React, { Component, AriaAttributes, KeyboardEventHandler } from 'react';
20+
import React, { Component, AriaAttributes } from 'react';
2121
import classNames from 'classnames';
2222
import AceEditor, { IAceEditorProps } from 'react-ace';
2323

@@ -92,7 +92,7 @@ export class EuiCodeEditor extends Component<
9292

9393
idGenerator = htmlIdGenerator();
9494
aceEditor: AceEditor | null = null;
95-
editorHint: HTMLDivElement | null = null;
95+
editorHint: HTMLButtonElement | null = null;
9696

9797
aceEditorRef = (aceEditor: AceEditor | null) => {
9898
if (aceEditor) {
@@ -154,13 +154,6 @@ export class EuiCodeEditor extends Component<
154154
}
155155
};
156156

157-
onKeyDownHint: KeyboardEventHandler<HTMLDivElement> = (event) => {
158-
if (event.key === keys.ENTER) {
159-
event.preventDefault();
160-
this.startEditing();
161-
}
162-
};
163-
164157
startEditing = () => {
165158
this.setState({
166159
isHintActive: false,
@@ -256,18 +249,14 @@ export class EuiCodeEditor extends Component<
256249
filteredCursorStart = cursorStart;
257250
}
258251

259-
// Don't use EuiKeyboardAccessible here because it doesn't play nicely with onKeyDown.
260252
const prompt = (
261-
<div
253+
<button
262254
className={promptClasses}
263255
id={this.idGenerator('codeEditor')}
264256
ref={(hint) => {
265257
this.editorHint = hint;
266258
}}
267-
tabIndex={0}
268-
role="button"
269259
onClick={this.startEditing}
270-
onKeyDown={this.onKeyDownHint}
271260
data-test-subj="codeEditorHint">
272261
<p className="euiText">
273262
{isReadOnly ? (
@@ -296,7 +285,7 @@ export class EuiCodeEditor extends Component<
296285
/>
297286
)}
298287
</p>
299-
</div>
288+
</button>
300289
);
301290

302291
return (

0 commit comments

Comments
 (0)