Revert "DEV: Experimental scroll sidebar to specific element event handler (#17727)" (#17920)

This reverts commit af912b4b0efc9a8182c5b70a323f593b14e7ca38.
This commit is contained in:
Krzysztof Kotlarek 2022-08-15 13:10:58 +10:00 committed by GitHub
parent 6c13d82630
commit 8cd1340170
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 0 additions and 62 deletions

View File

@ -12,8 +12,6 @@ export default class Sidebar extends Component {
if (this.site.mobileView) {
document.addEventListener("click", this.collapseSidebar);
}
// This appEvent handler is experimental and should not be relied on as an extension point yet.
this.appEvents.on("sidebar:scroll-to-element", this, this.#scrollToElement);
}
@bind
@ -37,68 +35,9 @@ export default class Sidebar extends Component {
}
}
#scrollToElement(destinationElement) {
const topPadding = 10;
const sidebarContainerElement =
document.querySelector(".sidebar-container");
const distanceFromTop =
document.getElementsByClassName(destinationElement)[0].offsetTop -
topPadding;
this.#setMissingHeightForScroll(sidebarContainerElement, distanceFromTop);
sidebarContainerElement.scrollTop = distanceFromTop;
}
#setMissingHeightForScroll(sidebarContainerElement, distanceFromTop) {
const allSections = document.getElementsByClassName(
"sidebar-section-wrapper"
);
const lastSectionElement = allSections[allSections.length - 1];
const lastSectionBottomPadding = parseInt(
lastSectionElement.style.paddingBottom?.replace("px", "") || 0,
10
);
const headerOffset = parseInt(
document.documentElement.style.getPropertyValue("--header-offset"),
10
);
let allSectionsHeight = 0;
for (const section of allSections) {
allSectionsHeight +=
section.clientHeight +
parseInt(
window.getComputedStyle(section).marginBottom.replace("px", ""),
10
);
}
const missingHeight =
sidebarContainerElement.clientHeight -
headerOffset +
lastSectionBottomPadding -
(allSectionsHeight - distanceFromTop);
lastSectionElement.style.paddingBottom =
missingHeight > 0 ? `${missingHeight}px` : null;
}
willDestroy() {
if (this.site.mobileView) {
document.removeEventListener("click", this.collapseSidebar);
}
this.appEvents.off(
"sidebar:scroll-to-element",
this,
this.#scrollToElement
);
}
}

View File

@ -38,7 +38,6 @@
scrollbar-color: transparent var(--scrollbarBg);
transition: scrollbar-color 0.25s ease-in-out;
transition-delay: 0.5s;
scroll-behavior: smooth;
&::-webkit-scrollbar-thumb {
background-color: transparent;