Problem/Motivation
When the withdraw consent banner is enabled and a user has accepted cookies, the privacy settings button becomes available and the withdraw consent banner is visually hidden off-screen. Keyboard users can tab onto any links or the withdraw consent button within the hidden banner, but there is no visible focus indicator because the banner is hidden. This is probably confusing for sighted users navigating the page by keyboard and is likely to be a failure under WCAG SC 2.4.7. It is probably best to prevent controls within the banner receiving keyboard focus when the banner is hidden.
Steps to reproduce
- Enable the
Opt-in. Don't track visitors unless they specifically give consent. (GDPR compliant)option - Enable the options
Enable floating privacy settings tab and withdraw consent bannerandEnable floating privacy settings tab after withdrawing consent - Get the cookie consent banner to trigger and select the option to accept cookies
- The privacy settings button should now be visible and the withdraw consent banner should be hidden (the privacy button must be clicked to reveal the withdraw consent banner)
- Whilst the withdraw consent banner is hidden, use the keyboard to tab onto the privacy settings button
- Press tab again - any links or the withdraw consent button within the hidden withdraw consent banner can obtain keyboard focus
- Possibly a side issue, but notice also that just after cookies are accepted and the withdraw consent banner is present in the DOM (but visually hidden) the body tag contains the class "eu-cookie-compliance-popup-open". The privacy settings tab must be toggled to open and close the withdraw consent banner for the class to be removed.
Proposed resolution
- When the withdraw consent banner is hidden, set
tabindex="-1"on all controls (links, buttons, inputs) within the withdraw banner to prevent the controls receiving keyboard focus. - When the withdraw consent banner is shown, set
tabindex="0"on all controls with the withdraw banner so that they can again receive keyboard focus - Ensure the body class "eu-cookie-compliance-popup-open" is always removed when the withdraw consent banner is hidden
Issue fork eu_cookie_compliance-3298345
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
svenryen commentedThanks for the patch! I'll take a look.
Comment #4
svenryen commented@Glugmeister, did you plan to add code in the issue fork, or do you want the maintainer team to fix this issue?
Comment #5
mzouari commented@svenryen
Hello everyone,
when the banner is folded, it is still possible to access it in keyboard navigation and with a screen reader. I added a js script that allows:
1. Add the aria-hidden="true" attribute on the element that contains the banner when it is collapsed (aria-hidden="false" when it is open).
2. Add the tabindex="-1" attribute to all buttons, links and fields of the banner when it is collapsed (tabindex="0" when it is open).
My problem: When I click on the "Accept all cookies" or "Save my choices" button, the attributes that I added beforehand are removed and the "eu-cookie-compliance-popup-open" class is still present in the body tag when the banner is in the hidden position.
Banner removal links/buttons are keyboard enabled when the banner is hidden. Do you have any ideas to resolve my problem ? Thank you
Comment #6
glugmeister commented@svenryen yes I planned to add code into the issue fork - but I had some difficulty getting the forked version to work in my local dev environment. I then went on holiday! So apologies for that. I am not overly familiar with submitting patches via issue forks. Yes please if the maintainer team could look at fixing this issue that would be much appreciated. In the meantime I will attempt to better understand how to work with issue forks ...!
Comment #7
svenryen commentedI will not have time until the week after next week, and there's the Reject all feature I'd like to work on before the early Sept release window that we're aiming for.
We also accept old-style patches, so don't be shy about uploading a patch! :)
Comment #8
glugmeister commentedThanks @svenryen - I'll try to contribute a patch in some form!
Comment #9
svenryen commentedHi @Glugmeister. I'll add a patch today for setting the aria-hidden to true and tabindex to -1 when hidden and the opposite for the visible banner.
If you think additional changes need be made, please follow up and post another patch in this issue. :)
Comment #11
svenryen commentedHi @Glugmeister and @mzouari, can you test the 1.x-dev version or the branch from this issue fork to see if this resolves your issue?
Comment #15
glugmeister commentedHi @svenryen,
Please see my most recent merge request above (#14). I have added aria-hidden attribute to the compliance and withdraw banner and I also noticed that tabindex is not being set for the "Cookie Policy" and "More info" buttons if they are enabled in the banner (also if you add any links into the banner compliance and withdraw messages, tabindex is not set for them either).
So have changed lines in the JS like this:
To this:
I am thinking that it should be safe to target all focusable controls inside the banners to set tabindex. Hopefully that makes sense!
Comment #17
svenryen commentedComment #18
svenryen commentedThanks for helping. That was a much better selector.
Comment #19
glugmeister commentedComment #20
glugmeister commentedComment #22
glugmeister commentedChanging back to "Needs review" because I've submitted a merge request with couple of extra fixes.
Comment #24
svenryen commentedThanks for the fixes.