Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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:
- Preferably, use a
<button>
element for the the "Place block" buttons on the Block Layout UI. - 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.
Comment | File | Size | Author |
---|---|---|---|
#14 | block_admin_a11y-2805227-14.patch | 1.93 KB | GaëlG |
#12 | block_admin_a11y-2805227-11.patch | 1.93 KB | GaëlG |
#9 | 2805227-interdiff.diff | 735 bytes | GaëlG |
#9 | block_admin_a11y-2805227-9.patch | 1.94 KB | GaëlG |
#5 | place-block-ui.png | 107.97 KB | Prashant.c |
Comments
Comment #2
mgifford+1 - ARIA is powerful, but not as good as old HTML5.
Some links to back that up:
https://www.paciellogroup.com/blog/2011/04/html5-accessibility-chops-jus...
http://www.karlgroves.com/2013/05/14/links-are-not-buttons-neither-are-d...
Comment #3
andrewmacpherson CreditAttribution: andrewmacpherson as a volunteer and at Annertech commentedHmm, 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 theblock.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.Comment #4
Everett Zufelt CreditAttribution: Everett Zufelt at Myplanet commentedI 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.
Comment #5
Prashant.cSubmitting 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.
Comment #6
BarisW CreditAttribution: BarisW at LimoenGroen commentedComment #7
GaëlGI'll try to review this as part of DC Dublin friday sprint.
Comment #8
GaëlGThe initial post says that space key activation is required. I'll try to work on it now.
Comment #9
GaëlGI 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
Comment #10
GaëlGComment #11
andrewmacpherson CreditAttribution: andrewmacpherson as a volunteer and at Annertech commentedThanks GaëlG.
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."
Comment #12
GaëlGHere's a new patch, I just updated the comment as asked.
Comment #13
andrewmacpherson CreditAttribution: andrewmacpherson as a volunteer and at Annertech commentedI 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.
Comment #14
GaëlGHere's an updated patch. I confirm it still works on my Chromium.
Comment #15
kostask CreditAttribution: kostask at Point Blank commentedandrewmacpherson 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?
Comment #16
kostask CreditAttribution: kostask at Point Blank commentedresetting the tags I removed by mistake
Comment #17
mgiffordSorry, but why have we given up on
<button>
and reverted torole="button"
?HTML5 is better supported.
Comment #18
tim.plunkettAFAIK button elements do not support href.
Comment #19
droplet CreditAttribution: droplet commentedNot a fans to add similar JS code everywhere. Let's make it globally
Comment #20
mgifford@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.
Comment #21
tim.plunkettThese specific links are in BlockListBuilder, around line 211.
The two key parts there are
'#type' => 'link'
andComment #24
andrewmacpherson CreditAttribution: andrewmacpherson as a volunteer and at Annertech commentedRe: #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
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.
Comment #25
andrewmacpherson CreditAttribution: andrewmacpherson as a volunteer and at Annertech commentedThis 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.
Comment #37
mgiffordTagging https://www.w3.org/WAI/WCAG21/Understanding/name-role-value.html