Problem/Motivation

The "place block" buttons on the Block Layout UI (admin/structure/block) are made with HTML anchor tags.

These are announced as a "link" by most screen readers, suggesting that the user will be directed to a new page. The actual behaviour is better described as a "button", to suggest that something will happen on the current page.

Proposed resolution

Either:

  1. Preferably, use a <button> element for the the "Place block" buttons on the Block Layout UI.
  2. If this is difficult, adding role="button" to the existing anchor tag will suffice, but we would also need to ensure it is activated by enter OR the spacebar key, as a <button> would be. (Anchor elements are normally only activated by the enter key.)

Remaining tasks

Write a patch.

User interface changes

  • No visual changes intended.
  • Improve the semantics conveyed to assistive technology.
  • .

API changes

None expected.

Data model changes

None expected.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

andrewmacpherson created an issue. See original summary.

mgifford’s picture

andrewmacpherson’s picture

Hmm, life's never easy.

The place-block buttons come from core/modules/block/src/BlockListBuilder.php, and are treated as Form API link elements. The #url property is used to build an ajax dialog request for the block.admin_library route, so changing to a HTML button isn't a simple change.

Interestingly, when Javascript is disabled in the browser, "place block" does indeed act as a link, directing the user to the block library as a standalone page.

It's the same story for the buttons inside the dialog. When JS is disabled, they are links which direct to the block configuration form as a standalone page. So with JS disabled, the user visits 2 separate pages instead of getting each step inside a dialog.

When JS is enabled, and the dialogs come into play, "button" is a more appropriate semantic.

The ARIA role=button approach may be the better option. We could have a JS behaviour which adds the role and a keypress handler for the spacebar.

Everett Zufelt’s picture

I assume that it would be relatively simple to add the role=button attribute? I assume that if this is already an anchor that it would be suitable in all other ways from an accessibility perspective, but some quick testing could confirm.

- Can receive focus
- Visually displays focus
- In an appropriate tab order / flow.
- Can be activated by keyboard.

Prashant.c’s picture

Status: Active » Needs review
FileSize
1.23 KB
107.97 KB

Submitting patch for the same adding role="button" attribute to place block links.

- It is receiving focus on appropriate tab order / flow.
- Visually displaying focus
- Working on enter key.

BarisW’s picture

Issue tags: +Novice, +Dublin2016
GaëlG’s picture

I'll try to review this as part of DC Dublin friday sprint.

GaëlG’s picture

Status: Needs review » Needs work
  1. Can receive focus : OK
  2. Visually displays focus : OK
  3. In an appropriate tab order / flow : OK
  4. Can be activated by enter key : OK
  5. Can be activated by space key : FAIL

The initial post says that space key activation is required. I'll try to work on it now.

GaëlG’s picture

I added a JS behavior to handle the spacebar. Patch attached.

I sat next to Andrew during the sprint and we discussed about a wider issue: it might be good for accessibility if every link with role=button would respond to the spacebar key press, not just the "Place block" one. I found at least one other "pseudo-button" in core: the "Manage" link in the admin toolbar menu. Might be another issue though.

Edit: wider issue created: #2809347: All links using the "button" role should respond to spacebar, not only to enter key

GaëlG’s picture

Status: Needs work » Needs review
andrewmacpherson’s picture

Thanks GaëlG.

+ /**
+ * Allows user to activate the "Place block" link through focus
+ * + spacebar key.
+ * This is an accessibility improvement, as per #2805227.
+ */

I think we can improve this comment. I suggest:

"Allow user to activate Place Block link with spacebar key. This is the expected behavior of an element with the button role."

GaëlG’s picture

Here's a new patch, I just updated the comment as asked.

andrewmacpherson’s picture

Status: Needs review » Needs work

I tested this with @GaëlG and the behaviour worked in Chrome, but not in Firefox.

There is a problem with keyCode in jQuery on Gecko, according to https://stackoverflow.com/questions/12172646/event-keycode-vs-event-which

Using event.which == 32 worked as expected on Firefox.

GaëlG’s picture

Status: Needs work » Needs review
FileSize
1.93 KB

Here's an updated patch. I confirm it still works on my Chromium.

kostask’s picture

Issue tags: -Accessibility, -Novice, -Dublin2016

andrewmacpherson I can't get safari, nor firefox (on a mac) to focus the link using the tab button. How did you manage to get firefox to focus it?

kostask’s picture

Issue tags: +Accessibility, +Novice, +Dublin2016

resetting the tags I removed by mistake

mgifford’s picture

Sorry, but why have we given up on <button> and reverted to role="button"?

HTML5 is better supported.

tim.plunkett’s picture

AFAIK button elements do not support href.

droplet’s picture

Not a fans to add similar JS code everywhere. Let's make it globally

mgifford’s picture

Title: Use real HTML buttons for Place Block in Block layout UI. » Make sure Place Block buttons identify as buttons in Block layout UI.
Issue summary: View changes
Issue tags: +aria

@tim.plunkett - I just re-read the issue description and have modified the title. The problem is with the identification to screen readers which can be fixed with aria.

There are many instances where aria is used rather than plain old HTML, when HTML would be more accessible for everyone. This doesn't seem to be one of those instances.

@droplet - How do we do this? Where are these links (which act as buttons) being built? Not sure how to change it globally.

tim.plunkett’s picture

These specific links are in BlockListBuilder, around line 211.

      $form['region-' . $region]['title'] = array(
        '#theme_wrappers' => array(
          'container' => array(
            '#attributes' => array('class' => 'region-title__action'),
          )
        ),
        '#prefix' => $title,
        '#type' => 'link',
        '#title' => $this->t('Place block <span class="visually-hidden">in the %region region</span>', ['%region' => $title]),
        '#url' => Url::fromRoute('block.admin_library', ['theme' => $this->getThemeName()], ['query' => ['region' => $region]]),
        '#wrapper_attributes' => array(
          'colspan' => 5,
        ),
        '#attributes' => [
          'class' => ['use-ajax', 'button', 'button--small'],
          'data-dialog-type' => 'modal',
          'data-dialog-options' => Json::encode([
            'width' => 700,
          ]),
        ],
      );

The two key parts there are '#type' => 'link' and

'#attributes' => [
   'class' => ['use-ajax', 'button', 'button--small'],

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.

andrewmacpherson’s picture

Issue tags: -Novice

Re: #15

This is likely down to the system-wide macOS setting of "full keyboard access" which controls whether TAB can move focus to a link. I believe the default behaviour is that TAB does not move focus to links. See Mac accessibility shortcuts - Firefox and Safari both respect this setting. I was most likely testing with Firefox on Linux.

Re: #17

Sorry, but why have we given up on and reverted to role="button"?

Because when JS is turned off, these do indeed act as links, and they use a href to load a new page, instead of a dialog.

If we want them to work with JS turned off, then <button> won't work. A href is needed.

The patch in #14 adds the button role via PHP, which has no way of knowing whether JS is turned on.
But with JS turned off, an <a role="button" href> won't have the expected spacebar behaviour.

Removing the novice tag, as we don't have a clear direction on this one yet.

andrewmacpherson’s picture

This issue overlaps with #2809347: All links using the "button" role should respond to spacebar, not only to enter key - we could postpone this, and explore a solution there. It applies to other parts of the admin UI too, e.g. Views.

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.

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.

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.

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.

mgifford’s picture