MDL-73771 theme: Fix scrollbar position

This commit is contained in:
Carlos Castillo 2023-03-08 09:15:41 -05:00
parent 449a8b0b31
commit f17b006dcb
6 changed files with 27 additions and 4 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -47,6 +47,7 @@ const CLASSES = {
SCROLLED: 'scrolled',
SHOW: 'show',
NOTINITIALISED: 'not-initialized',
TOGGLERIGHT: '.drawer-right-toggle',
};
/**
@ -589,6 +590,11 @@ const scroller = () => {
const body = document.querySelector('body');
const drawerLayout = document.querySelector(SELECTORS.CONTAINER);
if (drawerLayout) {
// If there is not visible scrollbar then remove extra margin from right drawer.
const drawerRight = document.querySelector(SELECTORS.CONTAINER + ' ' + CLASSES.TOGGLERIGHT);
if (!scrollbarVisible(drawerLayout) && drawerRight) {
drawerRight.style.marginRight = '0';
}
drawerLayout.addEventListener("scroll", () => {
if (drawerLayout.scrollTop >= window.innerHeight) {
body.classList.add(CLASSES.SCROLLED);
@ -599,6 +605,16 @@ const scroller = () => {
}
};
/**
* Check if there is a visible scrollbar in the given html element.
*
* @param {object} htmlNode The html element.
* @returns {boolean} true if the scroll height is greater than client height.
*/
const scrollbarVisible = (htmlNode) => {
return htmlNode.scrollHeight > htmlNode.clientHeight;
};
/**
* Set the last used attribute for the last used toggle button for a drawer.
*

View File

@ -181,6 +181,9 @@
#page.drawers .main-inner {
margin-top: 1.5rem;
}
#page.drawers .drawer-right-toggle {
margin-right: 0.7rem;
}
}
@include media-breakpoint-up(md) {

View File

@ -20756,7 +20756,9 @@ span[data-flexitour="container"][x-placement="right"], span[data-flexitour="cont
@media (min-width: 576px) {
#page.drawers .main-inner {
margin-top: 1.5rem; } }
margin-top: 1.5rem; }
#page.drawers .drawer-right-toggle {
margin-right: 0.7rem; } }
@media (min-width: 768px) {
#page.drawers {

View File

@ -20702,7 +20702,9 @@ span[data-flexitour="container"][x-placement="right"], span[data-flexitour="cont
@media (min-width: 576px) {
#page.drawers .main-inner {
margin-top: 1.5rem; } }
margin-top: 1.5rem; }
#page.drawers .drawer-right-toggle {
margin-right: 0.7rem; } }
@media (min-width: 768px) {
#page.drawers {