Desktop: Accessibility: Restore keyboard focus when closing a dialog #10817
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This pull request improves how the
Dialog
component handles focus by closing the dialog with the.close()
method before removing it from the DOM. This causes the browser to restore keyboard focus to the item focused before the dialog was opened.Previously, closing a dialog reset focus to the first focusable element on the page.
See also:
Relevant WCAG success criterion
This change is related to success criterion 2.4.3 (Level A). See failure condition 85, example 2.
Remaining issue
Note
Update: A workaround has been implemented for
input
elements. However, the issue is still present in the Rich Text Editor.On some platforms (observed on Ubuntu 24.04 and MacOS), if an input is granted focus after closing a dialog, it isn't editable until unfocused, then refocused. In particular, if I:
Then nothing happens. Adding additional styling to highlight the
:focus
ed element reveals that the title input does have focus (but doesn't seem to respond to keyboard events). If I then press shift-tab, then tab, the title input is editable.I can reproduce a similar issue in the Rich Text editor, but not in the Markdown editor.
Testing
This pull request includes an automated test that verifies:
Existing automated tests verify that:
Dialog.tsx
.Dialog.tsx
.The following manual testing has been done on MacOS:
Test
.ing
.Testing
.