Problem/Motivation
When a keyboard user operates a "place block" button on the block layout page (admin/structure/block) a modal dialog presents the available blocks, but the keyboard focus does not move to the dialog content. Focus remains on the place-block button.
This is a different behaviour to the dialogs in Views UI, which move focus to the first focusable item in the dialog's main content.
A demo recording of this problem is on YouTube, from the Drupal Usability Meeting - 15 May 2018, starting around 31m.
Some additional consequences:
- Pressing ESC is expected to dismiss modal dialogs. However this doesn't work until focus has entered the dialog. So a sighted keyboard user can open a dialog, then see that it's not what they want, but it can't be dismissed by the normal behaviour.
- Screen reader users may not be immediately aware that the dialog has opened - it would be announced when entering the dialogue (i.e. when focus moves to a child element inside the dialog). Focus remains on a place-block button, which apparently did nothing.
The problem is somewhat mitigated by the fact that pressing tab will move focus to the "add custom block" link, which is the first visible focusable control in the dialog content. Screen readers announce the dialog at this point, and the ESC behaviour comes into play.
The current working draft of the W3C WAI-ARIA Authoring Practices describes the expected behaviour:
When a modal dialog opens focus goes to the first focusable item in the dialog.
Dialogs which are affected
- "place block" dialog on admin/structure/block
- "Modal Form" in the
form_api_examplemodule, from the contrib Examples for Developers MediaLibraryWidget (add media button opens a dialog)(fixed in #3035316: ‘Add media’ in MediaLibraryWidget should be a button, not a link, see #17)ajax_testmodule. "Button 1 (modal)" example.
Dialogs which are NOT affected
- Dialogs in Views UI. (Haven't tried them all, but tried a variety from dialogs from all sections)
- "This workflow applies to" dialog from Content Moderation module.
ajax_testmodule, all instances of "link" which open a dialog, atajax-test/dialogoff_canvas_testmodule, all instances at/off-canvas-test-links
Proposed resolution
When the dialog is opened, move focus programatically to the first control in the dialog content (the add custom block link).
Remaining tasks
Fix it - are we programatically focussing the wrong element?
User interface changes
- No visible inteface changes.
- Corrects the keyboard behaviour of a modal dialog, to match the behaviour of dialogs elsewhere in Drupal's admin interface.
API changes
None expected.
Data model changes
None expected.
Issue fork drupal-2805219
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 2805219-some-dialogs-do
changes, plain diff MR !5689
Comments
Comment #2
mgiffordThanks for finding this!
Comment #7
andrewmacpherson commentedA demo recording of this problem is on YouTube, from the Drupal Usability Meeting - 15 May 2018, starting around 31m.
Comment #8
andrewmacpherson commentedSome other dialogs fail to gain focus too. I saw it with the MediaLibraryWidget dialogs in #2988431: [Meta] Accessibility plan for Media Library Widget.
This could do with a review of all the places we use them, to see if that can tell us what the difference is. Maybe we need to document how to make the focus move correctly.
Bumping it to major, it's rather a big WTF for keyboard and/or screen reader users.
Comment #9
andrewmacpherson commentedupdate summary, starting to track how many dialogs this affects.
Comment #10
andrewmacpherson commentedOrganizing a list of dialogs which are affected vs. not affected. We may find a clue by comparing the implementations in each module.
Comment #11
andrewmacpherson commentedThere are a couple of test modules which can be used for manual testing too.
I found one instance of a dialog there which doesn't get focus when opened. It's the example called "Button 1 (modal)", provided by the
ajax_testmodule, at theajax-test/dialogpage.(I'm not counting the "Button 2 (non-modal) since no-one actually agrees what the expected behaviour of non-modal dialogs are. They were removed from the WAI-ARIA Authoring Practices 1.1 at some earlier draft.)
Comment #12
andrewmacpherson commentedAdding a couple of possibly related issues about the dialog tests, which @Lendude told me about on Slack. I haven't had time to read these yet.
One is to do with resizing dialogs, and timing issues for the test framework. I expect that one is a red herring here.
Comment #13
andrewmacpherson commentedI've been testing today with Firefox 65 and Chrome 72 on Linux, so this isn't confined to one browser.
Comment #14
andrewmacpherson commentedFound another dialog affected by this bug, in the contrib examples project
Comment #15
andrewmacpherson commentedI brought this to the attention of the media initiative, and asked for it to be treated as a must-have, because MediaLibraryWIdget is the first time we've used dialogs for a content editor task, distinct from a site builder task.
Comment #16
andrewmacpherson commentedComment #17
seanbJust found out what the problem was for the media library. By default, jQuery UI dialog moves the focus to the first tabbable element in the dialog, which is good.
In
core/misc/ajax.jshowever, we have code to move the focus to the element that triggered an AJAX request.So, in order to fix this problem, elements triggering a dialog need to set the data attribute
data-disable-refocustotrue.We could also change
core/misc/ajax.jsto skip refocus when a dialog is opened, but there is a good chance this could break implementations already working around this problem. For now I've at least added the data attribute to the patch changing the media library open button in #3035316: ‘Add media’ in MediaLibraryWidget should be a button, not a link. We should probably continue the discussion here to see if there is a generic way to fix this without breaking existing implementations.Comment #18
tim.plunkettFixing tag
Comment #20
wim leers@seanB What's next here? In #3035316-20: ‘Add media’ in MediaLibraryWidget should be a button, not a link you already applied what you learned here. I guess you're just letting people know what the accessibility fix is that Media did and the Block module should do the same?
If so, why is this issue listed in #2988431: [Meta] Accessibility plan for Media Library Widget?
Comment #21
seanbI think it was listed in #2988431: [Meta] Accessibility plan for Media Library Widget before I solved #3035316: ‘Add media’ in MediaLibraryWidget should be a button, not a link. This is definitely no longer a media library blocker.
Shared what I learned so other people can fix it when they run into it.
Comment #22
wim leers👍
Removing tag and updated meta issue: #2988431-45: [Meta] Accessibility plan for Media Library Widget.
Comment #24
mark_fullmer(from #21, above)
Testing on 8.9.0-dev, it appears that this IS still an issue that manifests when the Media Library is used in conjunction with Layout Builder, suggesting that the fix in #17 is not comprehensive, at least in the context of use with Layout Builder & the settings tray.
Steps to reproduce, from a generic installation
1. Create a block type with a field that uses the Media Library widget
2. Create a content type that uses Layout Builder
3. Create a node of that type and add an inline block of the type with the Media Library widget.
4. Click the "Add media" button.
5. Press the Tab key. The focus is still on the Layout Builder settings tray, not the Media Library dialog.
6. Press the ESC key. The Media Library dialog does not close, as it would if it were focused.
Scenario where the focus *does* work
1. Create a block type with a field that uses the Media Library widget
2. Use the Block UI to create a block of this type.
4. Click the "Add media" button.
5. Press the Tab key. The focus is on the Media Library dialog.
6. Press the ESC key. The Media Library dialog does close.
Presumed problem
The settings tray actions for Layout Builder to create blocks are triggered by a link with data-dialog attributes, but no way to disable refocs, which has the same underlying problem as the Media Library itself solved with #3035316: ‘Add media’ in MediaLibraryWidget should be a button, not a link.
Comment #34
yash.rode commentedComment #35
narendrarChanges in `ajax.js` looks good to me. I Left a comment on MR for other change for explaination.
Comment #36
yash.rode commentedAddressed @narendraR's feedback.
Comment #37
narendrarTested manually and changes looks good to me. Marking as RTBC.
Comment #41
lauriiiThe dialog focus handling was made more solid in #3397785: Dialog focus is returned to dialog instead of first tabbable element on dialog AJAX update which reduces the chances of disruption here. In combination with this, it should be possible for modules to remove most of their custom focus handling for dialogs.
gCommitted 7bd749f and pushed to 11.x. Also cherry-picked to 10.2.x. Thanks!