Skip to content

Commit

Permalink
fix #1014 SubMenu position goes off the screen
Browse files Browse the repository at this point in the history
  • Loading branch information
vegegoku committed Mar 9, 2025
1 parent 535a2ed commit 9080544
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,12 @@ public AppLayout() {
.addCss(dui_content)
.setZIndexLayer(ZIndexLayer.Z_LAYER_1)));
header =
LazyChild.of(header().addCss(dui_header).setZIndexLayer(ZIndexLayer.Z_LAYER_2), body)
LazyChild.of(
header()
.addCss(dui_header)
.setAttribute("dui-reserve-top-space", "true")
.setZIndexLayer(ZIndexLayer.Z_LAYER_2),
body)
.whenInitialized(() -> layout.addCss(dui_has_header));
navBar = LazyChild.of(NavBar.create(), header);
footer =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.dominokit.domino.ui.utils.ElementsFactory.elements;
import static org.dominokit.domino.ui.utils.Unit.px;

import elemental2.dom.DomGlobal;
import elemental2.dom.Element;
import org.dominokit.domino.ui.style.Style;

Expand All @@ -34,13 +35,19 @@ public DropDirection position(Element source, Element target) {
if (spaceChecker.hasSpaceBelow()) {
double delta = 0;
double availableSpace = spaceChecker.getAvailableSpaceOnTop();
DomGlobal.console.info("availableSpace : " + availableSpace);
if (availableSpace < spaceChecker.getSourceHeight()) {
delta = spaceChecker.getSourceHeight() - availableSpace;
}
DomGlobal.console.info("delta : " + delta);

Style.of(source)
.style
.setProperty("top", px.of((spaceChecker.getTargetTop() + window.pageYOffset - delta)));
double top = spaceChecker.getTargetTop() + window.pageYOffset - delta;
double thresholdTopSpace = spaceChecker.getThresholdTopSpace();

if (top < thresholdTopSpace) {
top = thresholdTopSpace;
}
Style.of(source).style.setProperty("top", px.of(top));

Style.of(source).style.setProperty("left", px.of(0));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public boolean hasSpaceAbove() {
return (topSpace - getThresholdHeightSpace("dui-reserve-top-space")) > sourceHeight;
}

private double getThresholdSideSpace(String attribute) {
public double getThresholdSideSpace(String attribute) {
List<Element> footerElements =
DomGlobal.document.querySelectorAll("[" + attribute + "]").asList();
return footerElements.stream()
Expand All @@ -122,7 +122,11 @@ private double getVisibleWidth(Element element) {
return elements.elementOf(element).getVisibleWidth();
}

private double getThresholdHeightSpace(String attribute) {
public double getThresholdTopSpace() {
return getThresholdHeightSpace("dui-reserve-top-space");
}

public double getThresholdHeightSpace(String attribute) {
List<Element> footerElements =
DomGlobal.document.querySelectorAll("[" + attribute + "]").asList();
return footerElements.stream()
Expand Down

0 comments on commit 9080544

Please sign in to comment.