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

Make sure new nav works well with the donate banner #12926

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
Expand Up @@ -6,7 +6,7 @@
{% fragment as content_desktop %}xlarge:tw-px-0 xlarge:tw-hidden{% endfragment %}
{% fragment as content_desktop_border %}xlarge:tw-border xlarge:tw-border-gray-20{% endfragment %}
{% comment %} 40 (5rem) is the height of the navbar {% endcomment %}
{% fragment as content_desktop_positioning %}xlarge:tw-fixed xlarge:tw-top-40 xlarge:tw-left-0 xlarge:tw-right-0 xlarge:tw-mx-auto{% endfragment %}
{% fragment as content_desktop_positioning %}xlarge:tw-fixed xlarge:tw-left-0 xlarge:tw-right-0 xlarge:tw-mx-auto{% endfragment %}

{% fragment as title_base_typography %}tw-font-sans tw-font-bold tw-text-xl tw-text-black{% endfragment %}
{% fragment as title_desktop_typography %}xlarge:tw-text-lg{% endfragment %}
Expand Down
6 changes: 6 additions & 0 deletions source/js/components/nav/desktop-dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,14 @@ class NavDesktopDropdown extends Accordion {
open() {
super.open();

let topOffset = document
.querySelector(".wide-screen-menu-container")
.getBoundingClientRect().bottom;

this.accordion.setAttribute("aria-selected", "true");
this.accordion.classList.remove("tw-grayed-out");

this.content.style.top = `${topOffset}px`;
this.content.classList.add("xlarge:tw-flex");
this.content.classList.remove("xlarge:tw-hidden");

Expand Down
13 changes: 12 additions & 1 deletion source/js/donate-banner.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ const DonateBanner = {
: banner?.querySelector(`a.banner-close`);

// skip the banner if it got dismissed by the user today already
if (hideBanner) {
// remove the banner from the DOM to prevent it
// from creating unexpected behavior due to its absolute positioning.
banner.remove();
return;
}

if (!hideBanner && banner) {
banner.classList.remove(`tw-hidden`);
}
Expand Down Expand Up @@ -57,8 +64,12 @@ const DonateBanner = {
);

closeAnimation.onfinish = () => {
banner.classList.add(`tw-hidden`);
this.setDismissDate();

// The banner will not reappear after the user has dismissed it until the next day.
// We might as well remove it from the DOM to prevent it
// from creating unexpected behavior due to its absolute positioning.
banner.remove();
};
});
},
Expand Down
16 changes: 16 additions & 0 deletions source/js/primary-nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,28 @@ let primaryNav = {
}

function setMenuState(openMenu) {
toggleDonateBanner(openMenu);
setNarrowMenuState(openMenu);
setBurgerState(openMenu);
trackMenuState(openMenu);
setBodyHeight(openMenu);
}

// temporarily hide the donate banner when the menu is open
function toggleDonateBanner(hideDonateBanner) {
const donateBanner = document.querySelector(`.donate-banner`);

if (!donateBanner) {
return;
}

if (hideDonateBanner) {
donateBanner.classList.add(`tw-hidden`);
} else {
donateBanner.classList.remove(`tw-hidden`);
}
}

document.addEventListener(`keyup`, (e) => {
if (e.keyCode === 27) {
menuOpen = false;
Expand Down
Loading