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

Improve keyboard navigation around exercise component #652

Merged
merged 7 commits into from
Jan 31, 2022

Conversation

gadenbuie
Copy link
Member

@gadenbuie gadenbuie commented Jan 31, 2022

Currently, the exercise component traps keyboard focus when a user enters the code editor. The goal of this PR is to alleviate this problem by allowing users to press Esc to turn off the use of the Tab key for indent and outdent behavior. We also add an outline to the editor element when in this mode to visually indicate that focus has been "given back" to the container. Note that indent/outdent via Ctrl + ]/[ will still work in this mode.

Additionally, I replaced the use of anchor elements with class btn in the exercise toolbar with <button> elements. This automatically allows those buttons to receive keyboard focus as well.

Finally, a small change was needed in the autocomplete logic to ensure that the Tab events aren't trapped when they're intended to move focus out of the exercise element. In this process, a small bug with the autocompletion on empty code was revealed: we no longer will try to return autocomplete suggestions on an empty line.

For #636

Here's a screen recording showing the new behavior. I added a red focus outline to make it more obvious which object has focus.

  1. Tabbing in the tutorial moves through the exercise buttons — Start Over, Run Code — and then into the exercise editor.
  2. Here, Tab inserts an indent when pressed at the start of the line and Shift + Tab inserts an outdent.
  3. When code has been written on the line, Tab opens autocomplete.
  4. Pressing Esc disables indent/outdent via Tab, allowing the user to move focus to the next or previous element.
  5. Users can also trigger the button behavior using the keyboard for both Start Over and Run Code.
learnr-exercise-tab-behavior.mp4

@gadenbuie gadenbuie marked this pull request as draft January 31, 2022 15:39
@gadenbuie gadenbuie marked this pull request as ready for review January 31, 2022 16:19
@gadenbuie gadenbuie merged commit b99922b into main Jan 31, 2022
@gadenbuie gadenbuie deleted the a11y/keyboard-navigation-exercise branch January 31, 2022 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants