Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
Add toggleTabbing function(to solve a DAC issue) (#291)
Browse files Browse the repository at this point in the history
* add toggleTabbing function

* add lines

* Update drawer.js
  • Loading branch information
fenglish authored and gvonkoss committed Mar 28, 2018
1 parent bb9a619 commit ef3285b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions src/js/drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,14 @@ function addDrawerToggles (drawerEl) {

function toggleCallback (state, e) {
if (state === 'close') {
toggleTabbing(drawerEl, false);

handleClose.removeEvents();

openingControl.focus();
} else {
toggleTabbing(drawerEl, true);

// don't capture the initial click or accidental double taps etc.
// we could use transitionend but scoping is tricky and it needs prefixing and...
setTimeout(handleClose.addEvents, LISTEN_DELAY);
Expand Down Expand Up @@ -142,11 +146,28 @@ function addSubmenuToggles (drawerEl) {
});
}

// This function is to solve accessibility issue
// when o-header-drawer is closed => tabbing is disabled.
// when o-header-drawer is open => tabbing is enabled.
function toggleTabbing (drawerEl, isEnabled) {
const allFocusable = drawerEl.querySelectorAll('a, button, input, select');
if (isEnabled) {
allFocusable.forEach(el => {
el.removeAttribute('tabindex');
});
} else {
allFocusable.forEach(el => {
el.setAttribute('tabindex', '-1');
});
}
}

function init () {
const drawerEl = document.body.querySelector('[data-o-header-drawer]');
if (!drawerEl) {
return;
}
toggleTabbing(drawerEl, false);
addSubmenuToggles(drawerEl);
addDrawerToggles(drawerEl);

Expand Down

0 comments on commit ef3285b

Please sign in to comment.