Problem/Motivation
The widget template (templates/asw-widget.html.twig) has some accessibility problems.
1. Interactive element is a link instead of a button
The "Open Accessibility Menu" trigger is an <a href="#"> with role="button":
<a href="#" target="_blank" class="asw-menu-btn" title="{{ 'Open Accessibility Menu'|t }}" role="button" aria-expanded="false">
- A
<button type="button">is the correct element here. The link does not navigate anywhere. - Links with
role="button"do not respond to the Space key (only Enter). Native buttons handle both. target="_blank"on a#link has no effect.
2. Image without alt attribute
<img src="{{ widget_icon }}" width="30px" height="30px">
The <img> has no alt attribute (WCAG 1.1.1). Since the icon is inside an interactive element with a title, it is decorative and should have alt="". Also, width="30px" and height="30px" are not valid HTML. These attributes take plain numbers without a unit.
Steps to reproduce
- Place the "Progressive Accessibility Block" in any region
- View the page and inspect the widget HTML
- Try to activate the button using the Space key. It does not work (only Enter does, because it is a link). The WAI-ARIA APG Button Pattern requires both Enter and Space to activate a button. Native
<button>elements handle this automatically. - Run WAVE (wave.webaim.org). It flags "Linked image missing alternative text"
Proposed resolution
Replace the <a> with a native <button type="button">, add alt="" to the image, and fix the width/height values. CSS for .asw-menu-btn may need minor adjustments to reset default button styles.
Issue fork progressive_accessibility_widget-3584414
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
Comment #3
scontzen commentedPushed the fix to the branch. Changes:
<a href="#" role="button">with a native<button type="button">. This fixes Space key activation (WAI-ARIA APG Button Pattern) and removes the unnecessarytarget="_blank".alt=""to the icon image (WCAG 1.1.1, decorative image inside labeled control).width="30px"towidth="30"(HTML attributes take plain numbers).Tested on a local Drupal 10 install with Olivero: Space key works, WAVE no longer flags missing alt
text, button looks the same as before.
Comment #5
guido_sI tested it and noticed that the widget button had a strange style now because the Olivero theme rendered the block with a different block template in the navigation. So I adjusted the template of our widget and the styles and also removed the vendor prefix in the scss file as the compiler adds vendor prefixes where needed.
Looking good now and will be merged.
Comment #7
guido_s