Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## [`master`](https://github.com/elastic/eui/tree/master)

- Convert `EuiIcon` to TypeScript ([#1355](https://github.com/elastic/eui/pull/1355))
- Add support for `aria-label`, `aria-labelledby` and `aria-describedby` to `EuiCodeEditor` ([#1354](https://github.com/elastic/eui/pull/1354))

## [`5.5.1`](https://github.com/elastic/eui/tree/v5.5.1)

Expand Down
1 change: 1 addition & 0 deletions src-docs/src/views/code_editor/code_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default class extends Component {
enableLiveAutocompletion: true,
}}
onBlur={() => { console.log('blur'); }} // eslint-disable-line no-console
aria-label="Code Editor"
/>
);
}
Expand Down
1 change: 1 addition & 0 deletions src-docs/src/views/code_editor/custom_mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default class extends Component {
return (
<EuiCodeEditor
mode={new MyCustomAceMode()}
aria-label="Custom mode code editor"
theme="github"
width="100%"
value={this.state.value}
Expand Down
1 change: 1 addition & 0 deletions src-docs/src/views/code_editor/read_only.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default class extends Component {
value={this.state.value}
setOptions={{ fontSize: '14px' }}
isReadOnly
arial-label="Read only code editor"
/>
);
}
Expand Down
233 changes: 233 additions & 0 deletions src/components/code_editor/__snapshots__/code_editor.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,239 @@ exports[`EuiCodeEditor is rendered 1`] = `
style="width: 500px; height: 500px;"
>
<textarea
aria-label="aria-label"
autocapitalize="off"
autocorrect="off"
class="ace_text-input"
spellcheck="false"
style="opacity: 0;"
tabindex="-1"
wrap="off"
/>
<div
aria-hidden="true"
class="ace_gutter"
>
<div
class="ace_layer ace_gutter-layer ace_folding-enabled"
/>
<div
class="ace_gutter-active-line"
/>
</div>
<div
class="ace_scroller"
>
<div
class="ace_content"
>
<div
class="ace_layer ace_print-margin-layer"
>
<div
class="ace_print-margin"
style="left: 4px; visibility: visible;"
/>
</div>
<div
class="ace_layer ace_marker-layer"
/>
<div
class="ace_layer ace_text-layer"
style="padding: 0px 4px;"
/>
<div
class="ace_layer ace_marker-layer"
/>
<div
class="ace_layer ace_cursor-layer ace_hidden-cursors"
>
<div
class="ace_cursor"
/>
</div>
</div>
</div>
<div
class="ace_scrollbar ace_scrollbar-v"
style="display: none; width: 20px;"
>
<div
class="ace_scrollbar-inner"
style="width: 20px;"
/>
</div>
<div
class="ace_scrollbar ace_scrollbar-h"
style="display: none; height: 20px;"
>
<div
class="ace_scrollbar-inner"
style="height: 20px;"
/>
</div>
<div
style="height: auto; width: auto; top: 0px; left: 0px; visibility: hidden; position: absolute; white-space: pre; overflow: hidden;"
>
<div
style="height: auto; width: auto; top: 0px; left: 0px; visibility: hidden; position: absolute; white-space: pre; overflow: visible;"
/>
<div
style="height: auto; width: auto; top: 0px; left: 0px; visibility: hidden; position: absolute; white-space: pre; overflow: visible;"
>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
</div>
</div>
</div>
</div>
`;

exports[`EuiCodeEditor props aria attributes allows setting aria-describedby on textbox 1`] = `
<div
class="euiCodeEditorWrapper"
data-test-subj="codeEditorContainer"
>
<div
class="euiCodeEditorKeyboardHint"
data-test-subj="codeEditorHint"
id="42"
role="button"
tabindex="0"
>
<p
class="euiText"
>
Press Enter to start editing.
</p>
<p
class="euiText"
>
When you’re done, press Escape to stop editing.
</p>
</div>
<div
class=" ace_editor ace-tm"
id="brace-editor"
style="width: 500px; height: 500px;"
>
<textarea
aria-describedby="describedbyid"
autocapitalize="off"
autocorrect="off"
class="ace_text-input"
spellcheck="false"
style="opacity: 0;"
tabindex="-1"
wrap="off"
/>
<div
aria-hidden="true"
class="ace_gutter"
>
<div
class="ace_layer ace_gutter-layer ace_folding-enabled"
/>
<div
class="ace_gutter-active-line"
/>
</div>
<div
class="ace_scroller"
>
<div
class="ace_content"
>
<div
class="ace_layer ace_print-margin-layer"
>
<div
class="ace_print-margin"
style="left: 4px; visibility: visible;"
/>
</div>
<div
class="ace_layer ace_marker-layer"
/>
<div
class="ace_layer ace_text-layer"
style="padding: 0px 4px;"
/>
<div
class="ace_layer ace_marker-layer"
/>
<div
class="ace_layer ace_cursor-layer ace_hidden-cursors"
>
<div
class="ace_cursor"
/>
</div>
</div>
</div>
<div
class="ace_scrollbar ace_scrollbar-v"
style="display: none; width: 20px;"
>
<div
class="ace_scrollbar-inner"
style="width: 20px;"
/>
</div>
<div
class="ace_scrollbar ace_scrollbar-h"
style="display: none; height: 20px;"
>
<div
class="ace_scrollbar-inner"
style="height: 20px;"
/>
</div>
<div
style="height: auto; width: auto; top: 0px; left: 0px; visibility: hidden; position: absolute; white-space: pre; overflow: hidden;"
>
<div
style="height: auto; width: auto; top: 0px; left: 0px; visibility: hidden; position: absolute; white-space: pre; overflow: visible;"
/>
<div
style="height: auto; width: auto; top: 0px; left: 0px; visibility: hidden; position: absolute; white-space: pre; overflow: visible;"
>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
</div>
</div>
</div>
</div>
`;

exports[`EuiCodeEditor props aria attributes allows setting aria-labelledby on textbox 1`] = `
<div
class="euiCodeEditorWrapper"
data-test-subj="codeEditorContainer"
>
<div
class="euiCodeEditorKeyboardHint"
data-test-subj="codeEditorHint"
id="42"
role="button"
tabindex="0"
>
<p
class="euiText"
>
Press Enter to start editing.
</p>
<p
class="euiText"
>
When you’re done, press Escape to stop editing.
</p>
</div>
<div
class=" ace_editor ace-tm"
id="brace-editor"
style="width: 500px; height: 500px;"
>
<textarea
aria-labelledby="labelledbyid"
autocapitalize="off"
autocorrect="off"
class="ace_text-input"
Expand Down
16 changes: 14 additions & 2 deletions src/components/code_editor/code_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ import AceEditor from 'react-ace';

import { htmlIdGenerator, keyCodes } from '../../services';

function setOrRemoveAttribute(element, attributeName, value) {
if (value === null || value === undefined) {
element.removeAttribute(attributeName);
} else {
element.setAttribute(attributeName, value);
}
}

export class EuiCodeEditor extends Component {

state = {
Expand All @@ -17,8 +25,12 @@ export class EuiCodeEditor extends Component {
aceEditorRef = (aceEditor) => {
if (aceEditor) {
this.aceEditor = aceEditor;
aceEditor.editor.textInput.getElement().tabIndex = -1;
aceEditor.editor.textInput.getElement().addEventListener('keydown', this.onKeydownAce);
const textbox = aceEditor.editor.textInput.getElement();
textbox.tabIndex = -1;
textbox.addEventListener('keydown', this.onKeydownAce);
setOrRemoveAttribute(textbox, 'aria-label', this.props['aria-label']);
setOrRemoveAttribute(textbox, 'aria-labelledby', this.props['aria-labelledby']);
setOrRemoveAttribute(textbox, 'aria-describedby', this.props['aria-describedby']);
}
};

Expand Down
12 changes: 12 additions & 0 deletions src/components/code_editor/code_editor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ describe('EuiCodeEditor', () => {
expect(takeMountedSnapshot(component)).toMatchSnapshot();
});
});

describe('aria attributes', () => {
test('allows setting aria-labelledby on textbox', () => {
const component = mount(<EuiCodeEditor aria-labelledby="labelledbyid"/>);
expect(takeMountedSnapshot(component)).toMatchSnapshot();
});

test('allows setting aria-describedby on textbox', () => {
const component = mount(<EuiCodeEditor aria-describedby="describedbyid"/>);
expect(takeMountedSnapshot(component)).toMatchSnapshot();
});
});
});

describe('behavior', () => {
Expand Down