Skip to content

Commit

Permalink
adding background no scroll to when the off canvas area is open
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-c-woodard committed Sep 26, 2024
1 parent ea34fcd commit 383defb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion includes/assets/js/kb-off-canvas-trigger.min.js

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

9 changes: 9 additions & 0 deletions src/assets/js/kb-off-canvas-trigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@
focusableElements = Array.prototype.slice.call(focusableElements);
const firstFocusableElement = focusableElements[0];
const lastFocusableElement = focusableElements[focusableElements.length - 1];
const scrollBarWidth = window.innerWidth - document.documentElement.clientWidth;

const openOffCanvas = function (event) {
document.body.style.setProperty('--kb-scrollbar-offset', scrollBarWidth + 'px');
document.body.classList.add('kb-modal-open');
document.body.classList.add('kb-scrollbar-fixer');

event.target.classList.add('triggered');
offCanvasArea.classList.add('show-off-canvas');

setTimeout(function () {
offCanvasArea.classList.add('active');
triggerButtons.forEach((button) => button.setAttribute('aria-expanded', 'true'));
Expand All @@ -23,6 +29,9 @@
};

const closeOffCanvas = function () {
document.body.classList.remove('kb-modal-open');
document.body.classList.remove('kb-scrollbar-fixer');

offCanvasArea.classList.remove('active');
triggerButtons.forEach((button) => button.setAttribute('aria-expanded', 'false'));
for (let i = 0; i < triggerButtons.length; i++) {
Expand Down
11 changes: 11 additions & 0 deletions src/blocks/header/children/off-canvas/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,14 @@ body.admin-bar .kb-off-canvas-inner-wrap {
top: $admin-bar-height;
}
}

body.kb-modal-open {
overflow: hidden;
}

.kb-scrollbar-fixer {
margin-right: var(--kb-scrollbar-offset, unset);
.item-is-fixed {
right: var(--kb-scrollbar-offset, 0);
}
}

0 comments on commit 383defb

Please sign in to comment.