Problem/Motivation
There are few acessibility issues with the accordion title:
- Screenreader - Accordion title is announced as link, when it is behaving as a button.
- Screenreader - Accordion title is missing aria-expanded to indicate visibility of content.
- Keyboard - Pressing spacebar while the title is active should toggle the visibility of the content.
There is a similar issue open #3124167: Provide an accessible variant, but don't believe this is a duplicate. The focus of that issue is adding a variant system, with an optional accessible variant. However, accessibility improvements should be the default and not an optional add-on. I opened this issue to add the accessibility improvements in a backwards-compatible way.
Steps to reproduce
Keyboard:
- Tab to an accordion title and press the spacebar. The content doesn't toggle.
VoiceOver in Safari:
- Navigate to the accordion title, it's announced as a link
- Navigate to the accordion title and activate it. There's no feedback that content is revealed.
Proposed resolution
- Add
role="button"to title link - Add
aria-expandedto title link, and update it based on accordion state - Toggle accordion when space bar is pressed on link
For the next major version it should be updated to use the semantic <button> element for the title.
| Comment | File | Size | Author |
|---|
Issue fork ckeditor_accordion-3424786
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 #2
hbrokmeier commentedComment #4
hbrokmeier commentedMerge request submitted with the proposed changes:
role="button"to title linkaria-expandedto title link, and update it based on accordion stateComment #5
tiagozThere is already a related issue with patches https://www.drupal.org/project/ckeditor_accordion/issues/2869510
Comment #6
tiagozComment #9
sonfdI think the approach in the MR is more complete than the patch in #6. Also the patch contains a number of whitespace issues. MR !18 is the same as MR !15, but on top of the 2.x branch which seems to be the current development branch.
I'm concerned that the related issue referenced in #6 has been open for 8 years.
Comment #11
sonfdMR 18 updated to apply to the latest 2.x dev.
Attaching patch equivalent of MR 18 for use with composer.
Comment #13
sclsweb commented#11 and #12 fix the following error (using the current version, 2.3.0, with #10) that I kept seeing in this scenario:
What remains to get this merged and committed? My org is working to make all our sites WCAG 2.1 Level AA compliant. In order to do that we'll have to be using this patch in production sites, or abandoning CKEditor Accordion altogether, or switching to something like CKEditor Details Accordion. Would love to see the changes in this issue become a standard feature and part of the next commit.
Comment #14
whiplashomega commentedapplied this patch on our site to improve accessibility. It caused errors due to these lines (39 and 40 in the patch) whenever you click on another accordion title when one is already expanded.
It appears to be because the forEach loop is hitting both the DT and DD tags, but the DD tags do not have any children with the class ckeditor-accordion-toggler, and thus the querySelector function returns null.
Altering those lines to use the conditional operator fixed the issue: