Problem/Motivation
Drupal's page template has several regions with the landmark role: <aside role="complementary">.
The WAI-ARIA Authoring Practices recommends giving these accessible names. Currently, ours do not.
Accessible Name Guidance by Role
- Naming is necessary when two complementary landmark regions are present on the same page.
- Naming is recommended even when one complementary region is present to help users understand the purpose of the region's content when navigating among landmark regions.
- Use
aria-labelledbyif a visible label is present, otherwise usearia-label.
Proposed resolution
Add accessible names to the theme regions. For example: <aside role="complementary" aria-label="First sidebar">
Problem:
What names will we use for the complementary landmarks?
The names of the theme regions are almost a good fit, but not exactly. Some tweaks are needed:
- Bartik has several regions called "Featured bottom first", etc, but these are all wrapped up in a single landmark region. So we can call that one "Featured Bottom".
-
The "First sidebar" and "Second sidebar" names are potentially confusing:
- If there's only one sidebar, and it's called "first sidebar", that sets up the expectation that there is another one.
- Even worse, if there's only one sidebar, but it's called "second sidebar", then that would be even more confusing.
To address this, we can make the name conditional:
- If there is only one sidebar, call it "sidebar".
- If both sidebars are present, use the names "first sidebar" and "second sidebar".
There is already some code in which adds CSS classes based on the number of sidebars, so a similar approach could be used to create conditional
aria-labelattributes for the sidebars.
Remaining tasks
- Figure out the names to use. DONE, see comments #7-8.
- Patch the page templates. See the file list in comment #5.
User interface changes
No visible changes. Addition of accessible names for assistive technology.
API changes
None expected.
Data model changes
None expected.
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #50 | 3105316-50.patch | 9.65 KB | gauravvvv |
| #49 | 3105316-nr-bot.txt | 144 bytes | needs-review-queue-bot |
| #38 | 3105316-38.patch | 17.9 KB | andrewmacpherson |
| #38 | interdiff-3105316-37-38.txt | 7.43 KB | andrewmacpherson |
Comments
Comment #2
xjmComment #3
andrewmacpherson commentedOoh, I forgot I filed this!
Thinking about it, this should probably be classed as a bug report, on the basis that the W3C ARIA Authoring Practices says "Naming is necessary when two complementary landmark regions are present on the same page" (emphasisi mine).
This might be a somewhat disruptive for a patch release, depending on how we implement it. We'll see.
We could split this into child issues for each theme if needs be.
Comment #4
andrewmacpherson commentedminor issue summary updates
Comment #5
andrewmacpherson commentedI looked over all the variants of
page.html.twigin core.ALL of the
complementarylandmarks are hard-coded HTML elements with no dynamic twig variables (e.g. attributes) in the tag. This example comes from Bartik, and is typical:This is good news for backwards compatibility - the fact that none of these instances have any twig variables in the tag means that the only way this could have been fixed in an existing website was by overriding (or hacking) the Twig template. I think that means we can introduce an
aria-label="First sidebar"attribute without worrying about disrupting existing sites. That includes the Classy, Stable, and Stable9 themes; non-disruptive accessibility fixes have been permitted in these templates in the past.So the only outstanding question is to figure out what to call a few of the regions.
Here's the full list of
complementarylandmark regions in theme templates. Output ofack --type=twig --sort-files "complementary":Comment #6
andrewmacpherson commentedComment #7
maxstarkenburgA few comments from a Slack discussion on this:
Minor point, but the
<aside>in Bartik forfeatured_bottom_...regions at least wraps all three in one, so a default for that particular one could at least presumably be a simpler "Featured bottom".Assuming some defaults really are needed, it would be a better experience for a screen reader user to only hear something like "First sidebar" on pages where more than one sidebar is used (and otherwise just hear "Sidebar" if it's the only one, lest they wonder why they can't find the second one), and as mentioned in the Slack thread, it would be even more confusing if "Second sidebar" was output on pages that didn't have a first sidebar to begin with. But obviously adding such conditionals would make any patches a bit more complex.
As Andrew also mentioned in Slack, sites in RTL languages might also add a wrinkle (though maybe other parts of core are already doing a good enough job of not assuming
sidebar-firstis necessarily on the left?).Comment #8
andrewmacpherson commented@maxstarkenburg - thanks for adding your insights here. It was a productive Slack chat.
I think this pretty much solves that problem! I noticed the same thing when I did the survey in #5.
The discussion about the "first sidebar" and "second sidebar" names was very useful. I think it's definitely worth putting the conditional names in place to avoid this confusion. Bartik already has some code which adds some CSS classes based on the number of sidebars present, so a similar approach should be achievable for the accessible names of the landmark regions.
Yeah, my idea was to check the language direction so they can be conditionally named "left sidebar" and "right sidebar". I'm less convinced by that idea though, because the sidebars are moved below the main content on narrow viewports. Let's park that idea.
Updating the proposed resolution. Crediting @maxstarkenburg.
Comment #9
andrewmacpherson commentedComment #10
andrewmacpherson commentedComment #11
abhisekmazumdarComment #12
abhisekmazumdarI have created a patch here Kindly review
I have a few points to make about it:
1. The themes which doesn't have first and second sidebar region like umami, seven, claro.
2. classy will be removed from Drupal 9. So think there's no need to do the changes.
3. Do the sidebar first & second things needed to be taken care on the stable base themes?
Kindly give your feedback. Thank You
Comment #14
abhisekmazumdarComment #15
kostyashupenko1.
You missed translations for aria-labels.
2.
Replace
aria_labelbyaria-labelin twig filesComment #16
prabha1997 commentedComment #17
prabha1997 commentedReplace aria_label by aria-label in twig files.
I did above point. Kindly review patch
Comment #19
piyuesh23 commentedComment #20
drupradComment #21
drupradComment #22
sja112 commentedComment #23
xjmComment #24
sja112 commentedUpdated patch and replaced aria_label by aria-label in twig files, also updated code in preprocess hook to eradicate the issue coming up in testing.
Please review.
Comment #26
sja112 commentedUpdated patch to resolve the failed test case issue.
Drupal\KernelTests\Core\Theme\ConfirmClassyCopiesTest::testClassyHashes this case failed because as suggested,
Changes reverted from the classy theme.
Comment #27
abhisekmazumdarLooks good to me.
Comment #28
xjmNormally, we would not change the stable templates, but since this is an accessibility fix, there's a chance of doing this in a minor release. I especially think their might be an opportunity to make this change in Stable 9 before RC so that this is present throughout D9 without disrupting that base theme.
I'm less sure about whether it's safe to make the change in the D8 version of Stable; that's up to the frontend framework manager. So tagging for that review.
Comment #29
lauriiiWe might be able to find a better way to pass the labels to the template. These will stay in the render array when the region is being rendered. Maybe we can just move the string to templates?
Let's make sure all the new strings have been passed through
t()function.Comment #30
sja112 commentedHi @laurii,
Thanks for reviewing the patch.
I have updated the patch to add the suggested changes. I have passed the new strings through t() function. I have handled the addition of aria-label in twigs itself instead of adding them in a render array.
Comment #31
sja112 commentedAdding interdiff file.
Comment #32
andrewmacpherson commentedThanks for working on this everybody. I've skim-read the latest patch, but I haven't manually tested each theme yet. I'll give it some manual testing soon.
Partial review of patch #30:
aria-label="{{ page.sidebar_first ? 'Second Sidebar'|t : 'Sidebar'|t }}".There's a Twig syntax error in this instance. Notice there are 3 curly braces (
}}}) at the end of the aria-label.There's a HTML syntax error here. Notice the 2 closing angle brackets (
>>). This is repeated several times in the patch.Re. #12:
Classy hasn't been removed from D9, so the changes are needed there too. (It looks like Classy won't be removed until D10 now - see #3110137: Remove Classy from core and #2659890: [Policy] [Plan] Drupal 9 and 10 markup and CSS backwards compatibility).
Comment #33
sja112 commentedComment #34
andrewmacpherson commentedAny website which uses the stable or classy themes can automatically benefit from this change, but themes which have overridden the page template won't.
A change record would be good for this issue, to advise themers and distro maintainers to do something similar in their own page templates.
Comment #35
sja112 commentedHi @andrewmacpherson,
Thanks for the review of the patch. I have updated the patch to fix the issues mentiond above #32.
When I am trying to update the classy theme test case is failing with the error,
Drupal\KernelTests\Core\Theme\ConfirmClassyCopiesTest::testClassyHashes,
Comment #36
sja112 commentedHi @andrewmacpherson,
(Uploaded incorrect patch. re-adding the patch.)
Thanks for the review of the patch. I have updated the patch to fix the issues mentioned above #32.
When I am trying to update the classy theme test case is failing with the error,
Drupal\KernelTests\Core\Theme\ConfirmClassyCopiesTest::testClassyHashes,
So haven't added changes in classy theme.
Comment #37
andrewmacpherson commentedThanks for working on this @sja112.
I looked at
ConfirmClassyCopiesTestto see what we need to do, and I understand it now. Here's a summary of what it does:getClassyHash()helper method has a big list of MD5 checksums for all of the templates in the Classy theme. We're expecting to see these in the following tests.testClassyHashes()) calculates the MD5 checksum for each template in the Classy theme, and confirms it is the expected value from the helper method. If we change a template from the Classy theme (for examplemaintenance-page.html.twig) then this test will fail.testClassyCopies()) calculates the MD5 checksum for templates in other themes, which are supposed to be exact copies of the template in Classy. If we change themaintenance-page.html.twigtemplate from Umami, this test will fail.maintenance-page.html.twigtemplates in Classy and Umami are identical.So, if we want to make changes to templates in Classy, we have to update the expected MD5 checksum stored in the
ConfirmClassyCopiesTest::getClassyHash(), and make sure exactly the same changes are made to the Classy copies in the other core themes.The affected templates are these ones. In this patch, I've updated the templates and the MD5 hashes stored in the test.
Comment #38
andrewmacpherson commentedI did some other remaining work. These page templates have 2 sidebars, but didn't have the conditional name check yet.
core/themes/claro/templates/install-page.html.twigcore/themes/seven/templates/install-page.html.twigcore/themes/stable/templates/layout/install-page.html.twigcore/themes/stable/templates/layout/maintenance-page.html.twigcore/themes/stable/templates/layout/page.html.twigcore/themes/stable9/templates/layout/install-page.html.twigcore/themes/stable9/templates/layout/maintenance-page.html.twigcore/themes/stable9/templates/layout/page.html.twigComment #39
andrewmacpherson commentedA good issue for the Accessibility Bug Bash during DrupalCon Global 2020.
Comment #40
carlygerard@andrewmacpherson I can confirm #38 works in Bartik and Stark for sure. Not sure how to get the two sidebars to appear on the admin install pages to check those, but it's the same markup so I imagine it would work for Stable/Seven/Claro--being able to check would be good though.
Comment #41
andrewmacpherson commentedYou get sidebars to appear by placing blocks in them. The templates check whether there is anything in the sidebar, before creating the HTML wrapper.
Comment #43
pasqualleComment #44
xjmThis was only a beta target for the 9.0.x beta, so fixing metadata. Beta targets for minor branches are different. Thanks!
Comment #49
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #50
gauravvvv commentedAs stable and seven are no longer part of 10.1.X. Patch #38, no longer applies. I have added an updated patch. please review
Comment #51
smustgrave commentedWas previously tagged for tests. Can probably do simple assertions
This seems tied to #2655794: Remove redundant WAI-ARIA role attributes from <main>, <nav>, <aside>, <header>, and <footer> elements so maybe they should be combined or least share a change record.
If kept separate think this one needs to get in first over #2655794: Remove redundant WAI-ARIA role attributes from <main>, <nav>, <aside>, <header>, and <footer> elements as that one removes redundant roles but aside tags would still be wrong until this lands.
Comment #52
mgiffordAdding WCAG SC 4.1.2 https://www.w3.org/WAI/WCAG21/Understanding/name-role-value
Comment #54
kristen polI’m triaging for DrupalCon mentored contribution and reviewing as this issue is tagged novice.
*******
Please leave this issue for DrupalCon mentored contribution as a possible first time issue.
*******
The patch is simple and passes tests. Smustgrave noted maybe other issues should be considered at the same time as this but, even so, tests can be added to this patch.
This issue requires someone who knows how to code. They don’t necessarily need to know how to create tests and could be mentored on that.
Comment #55
kristen polTagging
Comment #56
kristen polFixing tag :)
Comment #57
kristen polTag normalization happening:)