From 669ff34c80e5a0a4c04bfac46ea1be4b8bca0b39 Mon Sep 17 00:00:00 2001 From: Seung Park Date: Wed, 23 Oct 2024 10:55:19 -0400 Subject: [PATCH] include script for sidenav height --- src/utils/head-scripts/offline-ui/sidenav.js | 22 ++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/utils/head-scripts/offline-ui/sidenav.js diff --git a/src/utils/head-scripts/offline-ui/sidenav.js b/src/utils/head-scripts/offline-ui/sidenav.js new file mode 100644 index 000000000..239fec09e --- /dev/null +++ b/src/utils/head-scripts/offline-ui/sidenav.js @@ -0,0 +1,22 @@ +/** + * For offline HTML builds, sidenav should adjust to scroll position + * so that it is sticky, but takes up full height when scrolled down + * and leaves room for Header Navigation at initial scrollY 0 + */ + +function updateSidenavHeight() { + const updateScrollY = () => { + // pulled from SIDE_NAV_CONTAINER_ID + // 'docs-side-nav-container' + const sidenavElm = document.querySelector('#docs-side-nav-container'); + sidenavElm.style = `--scroll-y: ${window.scrollY}px`; + window.addEventListener('scroll', (e) => { + sidenavElm.style = `--scroll-y: ${e.currentTarget.scrollY}px`; + }); + }; + + // TODO: account for multiple browsers here. Which are we supporting? verify with PD + document.addEventListener('DOMContentLoaded', updateScrollY, false); +} + +export default updateSidenavHeight;