Skip to content

Commit

Permalink
Fixed a JavaScript issue with multiple dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
KittyGiraudel committed Mar 17, 2016
1 parent 66b9079 commit cf3f5d8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 4 additions & 2 deletions a11y-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,27 @@
}
});

document.body.addEventListener('focus', function (event) {
function maintainFocus (event) {
if (that.shown && !node.contains(event.target)) {
setFocusToFirstItem(node);
}
}, true);
}

function show () {
that.shown = true;
node.removeAttribute('aria-hidden');
main.setAttribute('aria-hidden', 'true');
focusedBeforeDialog = document.activeElement;
setFocusToFirstItem(node);
document.body.addEventListener('focus', maintainFocus, true);
}

function hide () {
that.shown = false;
node.setAttribute('aria-hidden', 'true');
main.removeAttribute('aria-hidden');
focusedBeforeDialog.focus();
document.body.removeEventListener('focus', maintainFocus, true);
}
};

Expand Down
2 changes: 1 addition & 1 deletion a11y-dialog.min.js

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

6 changes: 4 additions & 2 deletions example/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,27 @@
}
});

document.body.addEventListener('focus', function (event) {
function maintainFocus (event) {
if (that.shown && !node.contains(event.target)) {
setFocusToFirstItem(node);
}
}, true);
}

function show () {
that.shown = true;
node.removeAttribute('aria-hidden');
main.setAttribute('aria-hidden', 'true');
focusedBeforeDialog = document.activeElement;
setFocusToFirstItem(node);
document.body.addEventListener('focus', maintainFocus, true);
}

function hide () {
that.shown = false;
node.setAttribute('aria-hidden', 'true');
main.removeAttribute('aria-hidden');
focusedBeforeDialog.focus();
document.body.removeEventListener('focus', maintainFocus, true);
}
};

Expand Down

0 comments on commit cf3f5d8

Please sign in to comment.