Push dropdown up if it's off bottom of screen/site

Use bottom: 100% to make sure the menu does not overlap the
button (as with bottom: 0). If it overlaps the button then
that interferes with the button click handler.
This commit is contained in:
Andrew Shu
2020-07-15 14:02:19 -07:00
committed by Deimos
parent 33f551fb21
commit ca38cd67fd
2 changed files with 20 additions and 0 deletions

View File

@@ -11,6 +11,13 @@
}
}
&.dropdown-bottom {
.menu {
top: auto;
bottom: 100%;
}
}
&-toggle.btn-post-action {
height: auto;
}

View File

@@ -34,6 +34,19 @@ $.onmount(".dropdown-toggle", function() {
"dropdown-right",
$this.offset().left + $this.width() - $menu.width() > 0
);
// If the menu extends past the bottom of the viewport, or the site footer
// overlaps the menu, push the menu above the button instead.
var menuBottom = $this.offset().top + $this.height() + $menu.height();
var viewportHeight = $(window).height();
var scrollTop = $(document).scrollTop();
var footerTop = $("#site-footer").offset().top;
$this
.parent()
.toggleClass(
"dropdown-bottom",
menuBottom > viewportHeight + scrollTop || menuBottom > footerTop
);
});
$(this).blur(function() {