Skip to content

Commit

Permalink
feat(a11y): Making the accordions work via keyboard navigation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Portugal, Marcelo authored and Portugal, Marcelo committed Nov 20, 2016
1 parent d82a112 commit 385e61f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 21 deletions.
20 changes: 13 additions & 7 deletions example/example-report.html
Original file line number Diff line number Diff line change
Expand Up @@ -1367,17 +1367,23 @@ <h3 class="page-header">All Rules</h3>
// accordion
lintResults.forEach(function setUpAccordion(result) {
if (!result.className.includes('bg-success')) {
result.addEventListener('click', function() {
var inGroup = document.getElementsByClassName(this.getAttribute('data-group'));

this.className = this.className.includes('open') ? this.className.replace(' open', '') : this.className + ' open';
for (var j = 0; j < inGroup.length; j++) {
inGroup[j].style.display = (inGroup[j].style.display !== 'none') ? 'none' : 'table-row';
result.setAttribute('tabindex', 0);
result.addEventListener('click', toggleAccordion);
result.addEventListener('keydown', function(event) {
if (event.which === 13) {
toggleAccordion.apply(this);
}
});
}
});

function toggleAccordion() {
var resultDetails = document.getElementsByClassName(this.getAttribute('data-group'));

this.className = this.className.includes('open') ? this.className.replace(' open', '') : this.className + ' open';
resultDetails[0].style.display = resultDetails[0].style.display !== 'none' ? 'none' : 'table-row';
}

// filter
filters.forEach(function addChangeListener(filter) {
filter.addEventListener('change', filterResults);
Expand All @@ -1404,7 +1410,7 @@ <h3 class="page-header">All Rules</h3>
currentTabs.forEach(disableTabs);
tabPanes.forEach(hideElement);
this.parentNode.className = 'active';
tabContent.style.display = (tabContent.style.display !== 'none') ? 'none' : 'block';
toggleDisplay(tabContent);
}

function disableTabs(tab) {
Expand Down
20 changes: 13 additions & 7 deletions example/success-report.html
Original file line number Diff line number Diff line change
Expand Up @@ -389,17 +389,23 @@ <h2 class="page-header">Details</h2>
// accordion
lintResults.forEach(function setUpAccordion(result) {
if (!result.className.includes('bg-success')) {
result.addEventListener('click', function() {
var inGroup = document.getElementsByClassName(this.getAttribute('data-group'));

this.className = this.className.includes('open') ? this.className.replace(' open', '') : this.className + ' open';
for (var j = 0; j < inGroup.length; j++) {
inGroup[j].style.display = (inGroup[j].style.display !== 'none') ? 'none' : 'table-row';
result.setAttribute('tabindex', 0);
result.addEventListener('click', toggleAccordion);
result.addEventListener('keydown', function(event) {
if (event.which === 13) {
toggleAccordion.apply(this);
}
});
}
});

function toggleAccordion() {
var resultDetails = document.getElementsByClassName(this.getAttribute('data-group'));

this.className = this.className.includes('open') ? this.className.replace(' open', '') : this.className + ' open';
resultDetails[0].style.display = resultDetails[0].style.display !== 'none' ? 'none' : 'table-row';
}

// filter
filters.forEach(function addChangeListener(filter) {
filter.addEventListener('change', filterResults);
Expand All @@ -426,7 +432,7 @@ <h2 class="page-header">Details</h2>
currentTabs.forEach(disableTabs);
tabPanes.forEach(hideElement);
this.parentNode.className = 'active';
tabContent.style.display = (tabContent.style.display !== 'none') ? 'none' : 'block';
toggleDisplay(tabContent);
}

function disableTabs(tab) {
Expand Down
20 changes: 13 additions & 7 deletions lib/helpers/scripts.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,23 @@
// accordion
lintResults.forEach(function setUpAccordion(result) {
if (!result.className.includes('bg-success')) {
result.addEventListener('click', function() {
var inGroup = document.getElementsByClassName(this.getAttribute('data-group'));

this.className = this.className.includes('open') ? this.className.replace(' open', '') : this.className + ' open';
for (var j = 0; j < inGroup.length; j++) {
inGroup[j].style.display = (inGroup[j].style.display !== 'none') ? 'none' : 'table-row';
result.setAttribute('tabindex', 0);
result.addEventListener('click', toggleAccordion);
result.addEventListener('keydown', function(event) {
if (event.which === 13) {
toggleAccordion.apply(this);
}
});
}
});

function toggleAccordion() {
var resultDetails = document.getElementsByClassName(this.getAttribute('data-group'));

this.className = this.className.includes('open') ? this.className.replace(' open', '') : this.className + ' open';
resultDetails[0].style.display = resultDetails[0].style.display !== 'none' ? 'none' : 'table-row';
}

// filter
filters.forEach(function addChangeListener(filter) {
filter.addEventListener('change', filterResults);
Expand All @@ -52,7 +58,7 @@
currentTabs.forEach(disableTabs);
tabPanes.forEach(hideElement);
this.parentNode.className = 'active';
tabContent.style.display = (tabContent.style.display !== 'none') ? 'none' : 'block';
toggleDisplay(tabContent);
}

function disableTabs(tab) {
Expand Down

0 comments on commit 385e61f

Please sign in to comment.