Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

PWA: DS::Menu - Place below button and center (#291)

Dylan Corralesb533a9b9b7e6
diff --git a/app/components/DS/menu_controller.js b/app/components/DS/menu_controller.js
index d5cfec2bcf..1dc01db3dc 100644
--- a/app/components/DS/menu_controller.js
+++ b/app/components/DS/menu_controller.js
@@ -1,7 +1,6 @@
import {
autoUpdate,
computePosition,
- flip,
offset,
shift,
} from "@floating-ui/dom";
@@ -103,15 +102,30 @@ export default class extends Controller {
}
update() {
+ if (!this.buttonTarget || !this.contentTarget) return;
+
+ const isSmallScreen = !window.matchMedia("(min-width: 768px)").matches;
+
computePosition(this.buttonTarget, this.contentTarget, {
- placement: this.placementValue,
- middleware: [offset(this.offsetValue), flip(), shift({ padding: 5 })],
+ placement: isSmallScreen ? "bottom" : this.placementValue,
+ middleware: [offset(this.offsetValue), shift({ padding: 5 })],
+ strategy: "fixed",
}).then(({ x, y }) => {
- Object.assign(this.contentTarget.style, {
- position: "fixed",
- left: `${x}px`,
- top: `${y}px`,
- });
+ if (isSmallScreen) {
+ Object.assign(this.contentTarget.style, {
+ position: "fixed",
+ left: "0px",
+ width: "100vw",
+ top: `${y}px`,
+ });
+ } else {
+ Object.assign(this.contentTarget.style, {
+ position: "fixed",
+ left: `${x}px`,
+ top: `${y}px`,
+ width: "",
+ });
+ }
});
}
}