Skip to content

[Monaco editor]: Fix accessibility focus trap issue#107292

Merged
alisonelizabeth merged 30 commits intoelastic:masterfrom
sebelga:code-editor-a11y
Aug 12, 2021
Merged

[Monaco editor]: Fix accessibility focus trap issue#107292
alisonelizabeth merged 30 commits intoelastic:masterfrom
sebelga:code-editor-a11y

Conversation

@sebelga
Copy link
Copy Markdown
Contributor

@sebelga sebelga commented Jul 30, 2021

fixes #72677

This PR fixes an accessibility issue with the <CodeEditor /> component from the kibana_react plugin where a user would not be able to exit the editor with a keyboard.

Hitting the ESC key will now display an overlay to the user that allows him to navigate to the next element on the page.

How to test

  • Navigate to the index pattern management app
  • Click "Add field"
  • Start navigating with the keyboard using the "TAB" key
  • Enable "Set value" with the SPACE key
  • TAB to access the script editor
  • An overlay should appear to indicate to hit "ENTER" to start writing
  • Hit ENTER
  • Write emi ---> you should have the suggestion menu open
  • Hit the "ESC" key. The suggestion menu should close
  • Hit the "ESC" again ---> you should now see the overlay back
  • Hit TAB to go to the next item (the link below the editor)

Note on implementation

I decided to mock the MonacoEditor component in order to be able to not test implementation detail of the <CodeEditor /> and call methods on the component directly. This allows us to have an <textarea /> rendered in our test and interact with it.

editor_a11y

@sebelga sebelga requested review from a team as code owners July 30, 2021 15:11
@sebelga sebelga added bug Fixes for quality problems that affect the customer experience Project:Accessibility release_note:fix v7.14.1 v7.15.0 v8.0.0 labels Aug 2, 2021
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/kibana-accessibility (Project:Accessibility)

@sebelga sebelga requested review from myasonik and timroes August 2, 2021 10:56
@sebelga sebelga added the Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more t// label Aug 2, 2021
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/kibana-stack-management (Team:Stack Management)

sebelga and others added 2 commits August 2, 2021 12:58
@sebelga
Copy link
Copy Markdown
Contributor Author

sebelga commented Aug 2, 2021

@elasticmachine merge upstream

@timroes timroes self-requested a review August 10, 2021 13:50
Copy link
Copy Markdown
Contributor

@timroes timroes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed the wording for readOnly mode:

screenshot-20210810-154802

There is unfortunately another bug left. When the editor can be scrolled out of view the tooltip is potentially attached out of view too, as you can see (or rather not see) in the following screenshot:

screenshot-20210810-155129

To reproduce that go to Discover when having doc_table:legacy turned off in your advanced setting and open a document and go to the JSON tab.

Since this was one of the initial problems, that we wanted the tooltip to solve, @cchaos do you have any idea how to fix that with the tooltip?

Copy link
Copy Markdown
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we can fully handle the situation where the editor is so long that it's height is greater than it's container. We are currently relying on the browser's innate functionality to ensure that it is visible within the scroll container, which is a win. But neither the overlay nor the tooltip solution seem to handle this scenario well. I'm ok with this behavior as it also is one that's only seen when using keyboard + mouse (a rare-er scenario).

But I do agree with @timroes that we should get rid of the overlay background entirely. There's no need to obscure the text. In fact, it just forces the user to have to interact with the code editor in order to read it which is not ideal.

Question: When I'm in edit mode, and hit tab, it takes me out of the editor. Is this supposed to happen?


Also I'd love for @myasonik to have the final pass at this before he leaves us 😢

Comment on lines +204 to +236
<div>
<EuiText>
<p>
{isReadOnly ? (
<FormattedMessage
id="kibana-react.kibanaCodeEditor.startEditingReadOnly"
defaultMessage="Press Enter to start interacting with the code."
/>
) : (
<FormattedMessage
id="kibana-react.kibanaCodeEditor.startEditing"
defaultMessage="Press Enter to start editing."
/>
)}
</p>
</EuiText>

<EuiText>
<p>
{isReadOnly ? (
<FormattedMessage
id="kibana-react.kibanaCodeEditor.stopEditingReadOnly"
defaultMessage="Press Escape to stop interacting with the code."
/>
) : (
<FormattedMessage
id="kibana-react.kibanaCodeEditor.stopEditing"
defaultMessage="Press Escape to stop editing."
/>
)}
</p>
</EuiText>
</div>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The EuiTooltip already has text styles applied to it so this can be simplified to:

Suggested change
<div>
<EuiText>
<p>
{isReadOnly ? (
<FormattedMessage
id="kibana-react.kibanaCodeEditor.startEditingReadOnly"
defaultMessage="Press Enter to start interacting with the code."
/>
) : (
<FormattedMessage
id="kibana-react.kibanaCodeEditor.startEditing"
defaultMessage="Press Enter to start editing."
/>
)}
</p>
</EuiText>
<EuiText>
<p>
{isReadOnly ? (
<FormattedMessage
id="kibana-react.kibanaCodeEditor.stopEditingReadOnly"
defaultMessage="Press Escape to stop interacting with the code."
/>
) : (
<FormattedMessage
id="kibana-react.kibanaCodeEditor.stopEditing"
defaultMessage="Press Escape to stop editing."
/>
)}
</p>
</EuiText>
</div>
<>
<p>
{isReadOnly ? (
<FormattedMessage
id="kibana-react.kibanaCodeEditor.startEditingReadOnly"
defaultMessage="Press Enter to start interacting with the code."
/>
) : (
<FormattedMessage
id="kibana-react.kibanaCodeEditor.startEditing"
defaultMessage="Press Enter to start editing."
/>
)}
</p>
<p>
{isReadOnly ? (
<FormattedMessage
id="kibana-react.kibanaCodeEditor.stopEditingReadOnly"
defaultMessage="Press Escape to stop interacting with the code."
/>
) : (
<FormattedMessage
id="kibana-react.kibanaCodeEditor.stopEditing"
defaultMessage="Press Escape to stop editing."
/>
)}
</p>
</>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And it looks like according to the writing guidelines the key references should be exactly whats on the keyboard, plus capitalization and bold. So it should render as:

Press Esc to stop editing.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cchaos Could you refer me to the exact part of the writing guidelines? I am not finding it anywhere in https://elastic.github.io/eui/#/guidelines/writing

I am mainly asking because I wonder what that means for "Enter" above? I mean the key does not state "Enter" on most keyboard, but has a symbol on it, are we trying to use that symbol in that case too?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I had meant to link to the doc I got them from (had to ask a UX writer): https://wiki.elastic.co/display/DOC/On+text+highlighting

@timroes
Copy link
Copy Markdown
Contributor

timroes commented Aug 11, 2021

Question: When I'm in edit mode, and hit tab, it takes me out of the editor. Is this supposed to happen?

This should only happen in readOnly editors, and there it's expected behavior since there is no actual user input, so I'd say that Tab should bring you out of the editor there. I can't reproduce this for editors that are not read-only. If you're experience it there, it's an issue we'd need to look into.

@timroes timroes dismissed their stale review August 11, 2021 08:29

No longer valid

@sebelga
Copy link
Copy Markdown
Contributor Author

sebelga commented Aug 11, 2021

When I'm in edit mode, and hit tab, it takes me out of the editor. Is this supposed to happen?

I just tested and I can't reproduce it either in edit mode.

@cchaos @myasonik I think all the change request have been addressed, can you have another look? Thanks!

@cchaos
Copy link
Copy Markdown
Contributor

cchaos commented Aug 11, 2021

This should only happen in readOnly editors

Thanks, yeah! I forgot that the one in Discover is readOnly. 🤦

Copy link
Copy Markdown
Contributor

@myasonik myasonik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Code review and tested in VoiceOver. A great fix for a broad feature!

@cjcenizal
Copy link
Copy Markdown
Contributor

@cchaos Do you have time to review and update your request for changes? We're trying to get this in today. Thanks!

@cchaos
Copy link
Copy Markdown
Contributor

cchaos commented Aug 11, 2021

@cjcenizal I was waiting for the changes to the rendered format of the keys displayed in the tooltip: #107292 (comment)

@cjcenizal
Copy link
Copy Markdown
Contributor

OK thanks, I'll let @timroes handle that -- he is taking this PR up now that Seb is on PTO.

@timroes timroes requested a review from cchaos August 12, 2021 08:31
@kibanamachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
kibanaReact 312.1KB 318.7KB +6.6KB

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Copy Markdown
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! LGTM!

@alisonelizabeth alisonelizabeth merged commit 338f7c5 into elastic:master Aug 12, 2021
alisonelizabeth pushed a commit to alisonelizabeth/kibana that referenced this pull request Aug 12, 2021
alisonelizabeth pushed a commit to alisonelizabeth/kibana that referenced this pull request Aug 12, 2021
# Conflicts:
#	src/plugins/kibana_react/public/code_editor/__snapshots__/code_editor.test.tsx.snap
#	src/plugins/kibana_react/public/code_editor/code_editor.tsx
#	x-pack/plugins/canvas/public/components/expression_input/__stories__/__snapshots__/expression_input.stories.storyshot
timroes pushed a commit that referenced this pull request Aug 13, 2021
…108386)

* [Monaco editor]: Fix accessibility focus trap issue (#107292)

# Conflicts:
#	src/plugins/kibana_react/public/code_editor/__snapshots__/code_editor.test.tsx.snap
#	src/plugins/kibana_react/public/code_editor/code_editor.tsx
#	x-pack/plugins/canvas/public/components/expression_input/__stories__/__snapshots__/expression_input.stories.storyshot

* update canvas snapshot

Co-authored-by: Sébastien Loix <sabee77@gmail.com>
@sebelga sebelga deleted the code-editor-a11y branch August 20, 2021 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Fixes for quality problems that affect the customer experience Project:Accessibility release_note:fix Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more t// v7.14.1 v7.15.0 v8.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(Accessibility) Monaco code editor is a focus trap

9 participants