Skip to content

Commit

Permalink
A11Y > Cookie banner identified as dialog when orientation=middle|pop…
Browse files Browse the repository at this point in the history
…up + focus trap
  • Loading branch information
nicozerr committed Oct 4, 2023
1 parent c758628 commit 4be35a6
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions tarteaucitron.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ var tarteaucitron = {
html = '',
index,
orientation = 'Top',
modalAttrs = '',
cat = ['ads', 'analytic', 'api', 'comment', 'social', 'support', 'video', 'other'],
i;

Expand Down Expand Up @@ -419,8 +420,12 @@ var tarteaucitron = {
orientation = 'Bottom';
}

if (tarteaucitron.parameters.orientation === 'middle' || tarteaucitron.parameters.orientation === 'popup') {
modalAttrs = ' role="dialog" aria-modal="true" aria-labelledby="tac_title"';
}

if (tarteaucitron.parameters.highPrivacy && !tarteaucitron.parameters.AcceptAllCta) {
html += '<div tabindex="-1" id="tarteaucitronAlertBig" class="tarteaucitronAlertBig' + orientation + '">';
html += '<div tabindex="-1" id="tarteaucitronAlertBig" class="tarteaucitronAlertBig' + orientation + '"' + modalAttrs + '>';
//html += '<div class="tarteaucitronAlertBigWrapper">';
html += ' <span id="tarteaucitronDisclaimerAlert" role="paragraph">';
html += ' ' + tarteaucitron.lang.alertBigPrivacy;
Expand All @@ -440,7 +445,7 @@ var tarteaucitron = {
//html += '</div>';
html += '</div>';
} else {
html += '<div tabindex="-1" id="tarteaucitronAlertBig" class="tarteaucitronAlertBig' + orientation + '">';
html += '<div tabindex="-1" id="tarteaucitronAlertBig" class="tarteaucitronAlertBig' + orientation + '"' + modalAttrs + '>';
//html += '<div class="tarteaucitronAlertBigWrapper">';
html += ' <span id="tarteaucitronDisclaimerAlert" role="paragraph">';

Expand Down Expand Up @@ -985,6 +990,10 @@ var tarteaucitron = {
if (property == "display" && value == "block" && id == "tarteaucitronBack") {
document.getElementById(id).style["opacity"] = "0.7";
}

if (property == "display" && value == "block" && id == "tarteaucitronAlertBig" && (tarteaucitron.parameters.orientation == "middle"|| tarteaucitron.parameters.orientation == "popup")) {
tarteaucitron.userInterface.focusTrap('tarteaucitronAlertBig');
}
}
}
},
Expand Down Expand Up @@ -1258,7 +1267,7 @@ var tarteaucitron = {
if (document.getElementsByTagName('body')[0].classList !== undefined) {
document.getElementsByTagName('body')[0].classList.add('tarteaucitron-modal-open');
}
tarteaucitron.userInterface.focusTrap();
tarteaucitron.userInterface.focusTrap('tarteaucitron');
tarteaucitron.userInterface.jsSizing('main');

//ie compatibility
Expand Down Expand Up @@ -1327,15 +1336,15 @@ var tarteaucitron = {

if (typeof(window.dispatchEvent) === 'function') {window.dispatchEvent(tacClosePanelEvent);}
},
"focusTrap": function() {
"focusTrap": function(parentElement) {
"use strict";

var focusableEls,
firstFocusableEl,
lastFocusableEl,
filtered;

focusableEls = document.getElementById('tarteaucitron').querySelectorAll('a[href], button');
focusableEls = document.getElementById(parentElement).querySelectorAll('a[href], button');
filtered = [];

// get only visible items
Expand All @@ -1349,7 +1358,7 @@ var tarteaucitron = {
lastFocusableEl = filtered[filtered.length - 1];

//loop focus inside tarteaucitron
document.getElementById('tarteaucitron').addEventListener("keydown", function (evt) {
document.getElementById(parentElement).addEventListener("keydown", function (evt) {

if ( evt.key === 'Tab' || evt.keyCode === 9 ) {

Expand Down

0 comments on commit 4be35a6

Please sign in to comment.