What is accessibility and why is it important?
People with disabilities, like blindness or very poor vision need screen readers to be able to discern certain things on our banner. For example how many checkboxes it has, whether they're checked or not, or if the dialog is collapsed or expanded, etc.
They're things that a person with normal vision takes for granted and can simply see. Conversely they can't tell if any of the accessibility attributes are even there and won't miss them if they're absent.
For this very reason, accessibility is hard to get right (and we're still missing some attributes). There are tools available that can check if certain attributes are missing, but the only way to be really sure is from user feedback.
This script seeks to remedy the flaws we know are present today (March 1st 2021):
So what does it do?
If you have a look at our banner, there's actually quite a lot going on, without you realizing it:
First off, the 3 consent choice buttons and the details button aren't actually
<button> elements, they are
<a> elements (hyperlinks). So we have to tell a screen reader that they in fact function as buttons by assigning the
The same can be said for tabs, these too are
<a> elements, and need to have
role="tab" attributes to signify that they function as tabs. The parent element which contains these tabs needs to be assigned the
role="tablist" attribute. The element which contains the tabs for the cookie categories needs to be assigned the
aria-orientation="vertical" attribute, to inform the user that these tabs are stacked vertically, and not horizontally which is the default.
The panel that goes with the tabs needs to be assigned the
role="tabpanel" attribute, and to signify the connection between the two the tab needs to be assigned the
aria-controls attribute, with the id of the tabpanel as its value.
For each of the tablists only one tab can have 0 as it's
tabindex value, the others must have -1, so pressing tab jumps to the next group of focusable elements, not the next element. To inform the user which tab is actively selected, the
aria-selected attribute needs to be used. The active tabs has "true" and the others have "false". These values need to be updated each time a different tab is selected.
When the details panel is opened, this needs to be signified with the
aria-expanded attribute, "false" for closed, "true" for opened.
The checkboxes need to be grouped, to signify they are related by encasing them in a
<fieldset> element. The Fieldset also needs to have a
<legend> element which essentially is used as a header. Currently this has no value, but it could be something like "Consent categories". The problem here, and the reason I've left this element empty, is that assigning this a value would deviate from the language the rest of the banner is displayed in, if this is anything other than English.
lastly, the checkboxes are displayed as "inline-table", which gives the impression data is contained within the table. To rectify this, I've assigned the element
style = display: inline; instead.
Essentially the script waits for the banner to announce that it's been loaded and is being displayed on the page, and then adds the attributes using DOM manipulation.
To add it to a page you can add the script inline, or copy the content in an external js-script and reference to that instead. Remeber to remove the
</script> tags if you take the latter approach.
If you want to add the script using Google Tag Manager you can create a new Custom HTML tag. Copy the script above and paste it in the new tag.
Assign the "All pages" trigger and remember to publish your changes.