From 9c0d5228d4338da33042e44449b717c24976be3c Mon Sep 17 00:00:00 2001 From: Bruno Boi Date: Mon, 11 Oct 2021 12:18:51 +0000 Subject: [PATCH] [REV] web: reintroduce mobile dropdown positioning Revert "[FIX] web: dropdown: avoid positioning in mobile" This reverts commit 1271ef80fafa4438271af0919dcca229aa20bf81. Revert Reason: A better alternative fix to the original issue has been found. See preceding commit. X-original-commit: 384169fb1b5874fd670f07fb2a6b1aca449f56c9 Part-of: odoo/odoo#78261 --- .../web/static/src/core/dropdown/dropdown.js | 52 ++++++++----------- 1 file changed, 23 insertions(+), 29 deletions(-) diff --git a/addons/web/static/src/core/dropdown/dropdown.js b/addons/web/static/src/core/dropdown/dropdown.js index 561fa21266a..9ea0336e6cd 100644 --- a/addons/web/static/src/core/dropdown/dropdown.js +++ b/addons/web/static/src/core/dropdown/dropdown.js @@ -73,6 +73,24 @@ export class Dropdown extends Component { useDropdownNavigation(); // Set up toggler and positioning -------------------------------------- + /** @type {string} **/ + let position = + this.props.position || (this.hasParentDropdown ? "right-start" : "bottom-start"); + let [direction, variant = "middle"] = position.split("-"); + if (localization.direction === "rtl") { + if (["bottom", "top"].includes(direction)) { + variant = variant === "start" ? "end" : "start"; + } else { + direction = direction === "left" ? "right" : "left"; + } + position = [direction, variant].join("-"); + } + const positioningOptions = { + popper: "menuRef", + position, + directionFlipOrder: { right: "rl", bottom: "bt", top: "tb", left: "lr" }, + }; + this.directionCaretClass = DIRECTION_CARET_CLASS[direction]; this.togglerRef = useRef("togglerRef"); if (this.props.toggler === "parent") { // Add parent click listener to handle toggling @@ -92,37 +110,13 @@ export class Dropdown extends Component { }, () => [] ); - } - - // Setup positioning only when in desktop - if (!this.env.isSmall) { - /** @type {string} **/ - let position = - this.props.position || (this.hasParentDropdown ? "right-start" : "bottom-start"); - let [direction, variant = "middle"] = position.split("-"); - if (localization.direction === "rtl") { - if (["bottom", "top"].includes(direction)) { - variant = variant === "start" ? "end" : "start"; - } else { - direction = direction === "left" ? "right" : "left"; - } - position = [direction, variant].join("-"); - } - this.directionCaretClass = DIRECTION_CARET_CLASS[direction]; - - const positioningOptions = { - popper: "menuRef", - position, - directionFlipOrder: { right: "rl", bottom: "bt", top: "tb", left: "lr" }, - }; // Position menu relatively to parent element - if (this.props.toggler === "parent") { - usePosition(() => this.el.parentElement, positioningOptions); - } else { - // Position menu relatively to inner toggler - usePosition(() => this.togglerRef.el, positioningOptions); - } + usePosition(() => this.el.parentElement, positioningOptions); + } else { + // Position menu relatively to inner toggler + const togglerRef = useRef("togglerRef"); + usePosition(() => togglerRef.el, positioningOptions); } }