Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] Add label for ace editor (#62588) #62743

Merged
merged 2 commits into from
Apr 9, 2020
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/

import React, { memo, useRef, useEffect, useState } from 'react';
import { i18n } from '@kbn/i18n';
import { EuiScreenReaderOnly } from '@elastic/eui';
import { Editor as AceEditor } from 'brace';

import { initializeEditor } from './init_editor';
Expand All @@ -31,6 +33,8 @@ const createEditorShim = (aceEditor: AceEditor) => {
};
};

const EDITOR_INPUT_ID = 'SearchProfilerTextArea';

export const Editor = memo(({ licenseEnabled, initialValue, onEditorReady }: Props) => {
const containerRef = useRef<HTMLDivElement>(null as any);
const editorInstanceRef = useRef<AceEditor>(null as any);
Expand All @@ -43,10 +47,25 @@ export const Editor = memo(({ licenseEnabled, initialValue, onEditorReady }: Pro
const divEl = containerRef.current;
editorInstanceRef.current = initializeEditor({ el: divEl, licenseEnabled });
editorInstanceRef.current.setValue(initialValue, 1);
const textarea = divEl.querySelector<HTMLTextAreaElement>('textarea');
if (textarea) {
textarea.setAttribute('id', EDITOR_INPUT_ID);
}
setTextArea(licenseEnabled ? containerRef.current!.querySelector('textarea') : null);

onEditorReady(createEditorShim(editorInstanceRef.current));
}, [initialValue, onEditorReady, licenseEnabled]);

return <div data-test-subj="searchProfilerEditor" ref={containerRef} />;
return (
<>
<EuiScreenReaderOnly>
<label htmlFor={EDITOR_INPUT_ID}>
{i18n.translate('xpack.searchProfiler.editorElementLabel', {
defaultMessage: 'Dev Tools Search Profiler editor',
})}
</label>
</EuiScreenReaderOnly>
<div data-test-subj="searchProfilerEditor" ref={containerRef} />
</>
);
});