A platform for community discussion. Free, open, simple.
FIX: Stop maxWidth capping a menu that matches its trigger's width (#44338)
Sérgio Saquetim58ac44833251
diff --git a/frontend/discourse/app/components/discovery/filter-navigation-menu.gjs b/frontend/discourse/app/components/discovery/filter-navigation-menu.gjsindex 7e3d9d92ee3..adcbcd86104 100644--- a/frontend/discourse/app/components/discovery/filter-navigation-menu.gjs+++ b/frontend/discourse/app/components/discovery/filter-navigation-menu.gjs@@ -234,7 +234,6 @@ export default class FilterNavigationMenu extends Component {identifier: "filter-navigation-menu-list",component: FilterNavigationMenuList,data: this.trackedMenuListData,- maxWidth: 2000,matchTriggerWidth: true,visibilityOptimizer: VISIBILITY_OPTIMIZERS.NONE,constrainHeightToViewport: true,diff --git a/frontend/discourse/float-kit/components/d-float-body.gts b/frontend/discourse/float-kit/components/d-float-body.gtsindex 3c9d0848bb9..aed05834621 100644--- a/frontend/discourse/float-kit/components/d-float-body.gts+++ b/frontend/discourse/float-kit/components/d-float-body.gts@@ -212,12 +212,19 @@ export default class DFloatBody extends Component<DFloatBodySignature> {get style() {const { maxWidth } = this.options;+ const viewportWidth = `calc(100dvw - ${horizontalViewportInset(this.options)}px)`;++ // A float that matches its trigger's width takes that width, so only the viewport bounds+ // it: a `maxWidth` narrower than the trigger would give a wide field a narrow menu.+ if ("matchTriggerWidth" in this.options && this.options.matchTriggerWidth) {+ return trustHTML(`max-width: ${viewportWidth}`);+ }// Only a number is clamped: a keyword like `none` or `unset` is invalid inside `min()`,// which would drop the declaration and hand the float to whatever CSS sets `max-width`.const value =typeof maxWidth === "number"- ? `min(${maxWidth}px, calc(100dvw - ${horizontalViewportInset(this.options)}px))`+ ? `min(${maxWidth}px, ${viewportWidth})`: maxWidth;return trustHTML(`max-width: ${value}`);diff --git a/frontend/discourse/float-kit/lib/constants.ts b/frontend/discourse/float-kit/lib/constants.tsindex 4b2c3e2b009..0297dd78b96 100644--- a/frontend/discourse/float-kit/lib/constants.ts+++ b/frontend/discourse/float-kit/lib/constants.ts@@ -152,10 +152,9 @@ export interface TooltipOptions {hoverGracePeriod: number;/**- * The maximum width of the content: a number in pixels, or any CSS `max-width` value. Pass- * `"none"` alongside `matchTriggerWidth` — the two are both applied inline, so a numeric cap- * silently wins over the matched width and a trigger wider than the cap gets a narrower- * overlay.+ * The maximum width of the content: a number in pixels, or any CSS `max-width` value. Ignored+ * when `matchTriggerWidth` is set, since the trigger then decides the width; only the viewport+ * bounds it.** A number is additionally capped to the width the viewport leaves the float, so it can never* overflow the document; a string is applied verbatim and gets no such cap.diff --git a/frontend/discourse/tests/integration/components/float-kit/d-menu-test.gjs b/frontend/discourse/tests/integration/components/float-kit/d-menu-test.gjsindex 406fcce0fba..e2aa4fd2b3b 100644--- a/frontend/discourse/tests/integration/components/float-kit/d-menu-test.gjs+++ b/frontend/discourse/tests/integration/components/float-kit/d-menu-test.gjs@@ -1247,6 +1247,43 @@ module("Integration | Component | FloatKit | DMenu", function (hooks) {});});+ // Matching the trigger's width already decides the width, so the menu's default max width+ // must not cap it: a trigger wider than the cap would otherwise get a narrower menu.+ test("@matchTriggerWidth is not capped by the default max width", async function (assert) {+ await render(+ <template>+ <DMenu+ style="width: 500px;"+ @inline={{true}}+ @label="a long label"+ @matchTriggerWidth={{true}}+ >1</DMenu>+ </template>+ );++ await open();++ assert.dom(".fk-d-menu.-content").hasStyle({ width: "500px" });+ });++ test("@matchTriggerWidth is not capped by an explicit @maxWidth", async function (assert) {+ await render(+ <template>+ <DMenu+ style="width: 500px;"+ @inline={{true}}+ @label="a long label"+ @matchTriggerWidth={{true}}+ @maxWidth={{300}}+ >1</DMenu>+ </template>+ );++ await open();++ assert.dom(".fk-d-menu.-content").hasStyle({ width: "500px" });+ });+test("delayed-hover opens menu after delay", async function (assert) {await render(<template>diff --git a/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/variable/expression-preview.gjs b/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/variable/expression-preview.gjsindex 6c4bc6158a4..5ce39baacbc 100644--- a/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/variable/expression-preview.gjs+++ b/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/variable/expression-preview.gjs@@ -64,7 +64,6 @@ export default class ExpressionPreview extends Component {closeOnClickOutside: false,closeOnScroll: false,matchTriggerWidth: true,- maxWidth: 9999,offset: 4,portalOutletElement,});