Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Commit

Permalink
async page inert when nav drawer is opened
Browse files Browse the repository at this point in the history
  • Loading branch information
brendankenny committed Feb 2, 2023
1 parent 7966a87 commit 8a74f09
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions src/lib/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,28 +114,33 @@ export const requestFetchReports = store.action((_, url, startDate) => {
* This is used when we open the navigation drawer or show a modal dialog.
*/
const disablePage = () => {
/** @type {HTMLElement|object} */
const main = document.querySelector('main') || {};
/** @type {HTMLElement|object} */
const footer = document.querySelector('.w-footer') || {};

document.body.classList.add('overflow-hidden');
main.inert = true;
footer.inert = true;
// Setting the majority of the page as inert can have a significant perf hit when
// trying to animate e.g. the navigation drawer, so do it in the frame after this.
requestAnimationFrame(() => {
requestAnimationFrame(() => {
const main = document.querySelector('main');
const footer = document.querySelector('footer');

if (main) main.inert = true;
if (footer) footer.inert = true;
});
});
};

/**
* Uninert the page so scrolling and pointer events work again.
*/
const enablePage = () => {
/** @type {HTMLElement|object} */
const main = document.querySelector('main') || {};
/** @type {HTMLElement|object} */
const footer = document.querySelector('.w-footer') || {};

document.body.classList.remove('overflow-hidden');
main.inert = false;
footer.inert = false;
// Similar to disablePage(), go inert in the next frame to avoid the perf hit.
requestAnimationFrame(() => {
requestAnimationFrame(() => {
const main = document.querySelector('main');
const footer = document.querySelector('footer');

if (main) main.inert = false;
if (footer) footer.inert = false;
});
});
};

export const openNavigationDrawer = store.action(() => {
Expand Down

0 comments on commit 8a74f09

Please sign in to comment.