Skip to content

Commit

Permalink
Added Layer timeout for safe aria hidden work
Browse files Browse the repository at this point in the history
  • Loading branch information
alansouzati committed Oct 24, 2017
1 parent fb80494 commit b0345ab
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions src/js/components/Layer.js
Expand Up @@ -236,30 +236,32 @@ export default class Layer extends Component {
}

_handleAriaHidden (hideOverlay) {
const ariaHidden = hideOverlay || false;
const grommetApps = document.querySelectorAll(`.${APP}`);
const visibleLayers = document.querySelectorAll(
`.${CLASS_ROOT}:not(.${CLASS_ROOT}--hidden)`
);

if (grommetApps) {
Array.prototype.slice.call(grommetApps).forEach((grommetApp) => {
if (ariaHidden && visibleLayers.length === 0) {
// make sure to only show grommet apps if there is no other layer
grommetApp.setAttribute('aria-hidden', false);
grommetApp.classList.remove(`${APP}--hidden`);
// scroll body content to the original position
grommetApp.style.top = `-${this._originalScrollPosition.top}px`;
grommetApp.style.left = `-${this._originalScrollPosition.left}px`;
} else {
grommetApp.setAttribute('aria-hidden', true);
grommetApp.classList.add(`${APP}--hidden`);
// this must be null to work
grommetApp.style.top = null;
grommetApp.style.left = null;
}
}, this);
}
setTimeout(() => {
const ariaHidden = hideOverlay || false;
const grommetApps = document.querySelectorAll(`.${APP}`);
const visibleLayers = document.querySelectorAll(
`.${CLASS_ROOT}:not(.${CLASS_ROOT}--hidden)`
);

if (grommetApps) {
Array.prototype.slice.call(grommetApps).forEach((grommetApp) => {
if (ariaHidden && visibleLayers.length === 0) {
// make sure to only show grommet apps if there is no other layer
grommetApp.setAttribute('aria-hidden', false);
grommetApp.classList.remove(`${APP}--hidden`);
// scroll body content to the original position
grommetApp.style.top = `-${this._originalScrollPosition.top}px`;
grommetApp.style.left = `-${this._originalScrollPosition.left}px`;
} else {
grommetApp.setAttribute('aria-hidden', true);
grommetApp.classList.add(`${APP}--hidden`);
// this must be null to work
grommetApp.style.top = null;
grommetApp.style.left = null;
}
}, this);
}
}, 0);
}

_renderLayer () {
Expand Down

0 comments on commit b0345ab

Please sign in to comment.