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

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_test module, all instances of "link" which open a dialog, at ajax-test/dialog
  • off_canvas_test module, 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

Command icon 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:

Comments

andrewmacpherson created an issue. See original summary.

mgifford’s picture

Issue tags: +keyboard focus

Thanks for finding this!

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

andrewmacpherson’s picture

A demo recording of this problem is on YouTube, from the Drupal Usability Meeting - 15 May 2018, starting around 31m.

andrewmacpherson’s picture

Priority: Normal » Major

Some 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.

andrewmacpherson’s picture

Title: Keyboard focus should move inside the place-block dialog when opened. » Some dialogs do not receive focus when opened
Issue summary: View changes
Issue tags: -Accessibility +accessibility

update summary, starting to track how many dialogs this affects.

andrewmacpherson’s picture

Issue summary: View changes

Organizing a list of dialogs which are affected vs. not affected. We may find a clue by comparing the implementations in each module.

andrewmacpherson’s picture

Issue summary: View changes

There 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_test module, at the ajax-test/dialog page.

(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.)

andrewmacpherson’s picture

Adding 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.

andrewmacpherson’s picture

I've been testing today with Firefox 65 and Chrome 72 on Linux, so this isn't confined to one browser.

andrewmacpherson’s picture

Issue summary: View changes

Found another dialog affected by this bug, in the contrib examples project

andrewmacpherson’s picture

Issue tags: +Media Initiative

I 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.

andrewmacpherson’s picture

Issue summary: View changes
seanb’s picture

Just 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.js however, we have code to move the focus to the element that triggered an AJAX request.

    // If the focus hasn't be changed by the ajax commands, try to refocus the
    // triggering element or one of its parents if that element does not exist
    // anymore.
    if (
      !focusChanged &&
      this.element &&
      !$(this.element).data('disable-refocus')
    ) {
      ...
    }

So, in order to fix this problem, elements triggering a dialog need to set the data attribute data-disable-refocus to true.

We could also change core/misc/ajax.js to 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.

tim.plunkett’s picture

Issue tags: -accessibility (duplicate tag) +Accessibility

Fixing tag

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

wim leers’s picture

@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?

seanb’s picture

Issue summary: View changes

I 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.

wim leers’s picture

Issue tags: -Media Initiative

👍

Removing tag and updated meta issue: #2988431-45: [Meta] Accessibility plan for Media Library Widget.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

mark_fullmer’s picture

This is definitely no longer a media library blocker.

(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.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

yash.rode made their first commit to this issue’s fork.

yash.rode’s picture

Status: Active » Needs review
narendrar’s picture

Status: Needs review » Needs work

Changes in `ajax.js` looks good to me. I Left a comment on MR for other change for explaination.

yash.rode’s picture

Status: Needs work » Needs review

Addressed @narendraR's feedback.

narendrar’s picture

Status: Needs review » Reviewed & tested by the community

Tested manually and changes looks good to me. Marking as RTBC.

  • lauriii committed 7bd749f1 on 11.x
    Issue #2805219 by yash.rode, andrewmacpherson, seanB, narendraR: Some...

  • lauriii committed 5b39ed89 on 10.2.x
    Issue #2805219 by yash.rode, andrewmacpherson, seanB, narendraR: Some...
lauriii’s picture

Version: 11.x-dev » 10.2.x-dev
Status: Reviewed & tested by the community » Fixed

The 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!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.