Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close menu dropdown on scroll offset update #13310

Merged
merged 4 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% load static wagtailcore_tags wagtailadmin_tags nav_tags %}

{% fragment as content_base_styles %}tw-overflow-y-auto tw-transition-all tw-duration-500 tw-bg-white xlarge:tw-bg-transparent xlarge:tw-max-w-[1200px]{% endfragment %}
{% fragment as content_base_styles %}tw-overflow-y-auto tw-transition-all tw-duration-500 tw-bg-white xlarge:tw-bg-transparent xlarge:tw-max-w-[1200px] xlarge:tw-transition-none xlarge:tw-duration-0{% endfragment %}
{% fragment as dropdown_selector_base %}tw-container tw-flex tw-flex-row tw-items-center tw-justify-between tw-w-full tw-gap-4{% endfragment %}

{% fragment as content_desktop %}xlarge:tw-px-0 xlarge:tw-hidden{% endfragment %}
Expand Down
18 changes: 18 additions & 0 deletions source/js/components/nav/desktop-dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class NavDesktopDropdown extends Accordion {
sibling.classList.remove("tw-highlighted");
}
});

document.addEventListener("scroll", this.handleScroll);
}

closeSiblings() {
Expand Down Expand Up @@ -115,7 +117,23 @@ class NavDesktopDropdown extends Accordion {

this.closeAccordion(this.accordion, this.titleButton, this.content);
this.closeSiblings();

document.removeEventListener("scroll", this.handleScroll);
}

scrollListener() {
const newTopOffset = document
ramram-mf marked this conversation as resolved.
Show resolved Hide resolved
.querySelector(".wide-screen-menu-container")
.getBoundingClientRect().bottom;
const currentTopOffset = parseFloat(
this.content.style.top.replace("px", "")
);
if (currentTopOffset !== newTopOffset) {
this.content.style.top = `${newTopOffset}px`;
}
}

handleScroll = this.scrollListener.bind(this);
}

export default NavDesktopDropdown;