A platform for community discussion. Free, open, simple.
FIX: allows float-kit to accept a portalOutletElement (#36259)
Joffrey JAFFEUX07654679648a
diff --git a/frontend/discourse/app/components/header/user-dropdown/notifications.gjs b/frontend/discourse/app/components/header/user-dropdown/notifications.gjsindex 43ce7a2f134..99ce2cdffc5 100644--- a/frontend/discourse/app/components/header/user-dropdown/notifications.gjs+++ b/frontend/discourse/app/components/header/user-dropdown/notifications.gjs@@ -63,6 +63,7 @@ export default class Notifications extends Component {@placement="bottom-end"@titleText={{i18n "user_tips.first_notification.title"}}@contentText={{i18n "user_tips.first_notification.content"}}+ @portalOutletSelector=".d-header-wrap"@showSkipButton={{true}}@priority={{1000}}/>diff --git a/frontend/discourse/app/components/topic-timeline/container.gjs b/frontend/discourse/app/components/topic-timeline/container.gjsindex 9101747f9cd..8f1eaea33a9 100644--- a/frontend/discourse/app/components/topic-timeline/container.gjs+++ b/frontend/discourse/app/components/topic-timeline/container.gjs@@ -567,7 +567,8 @@ export default class TopicTimelineScrollArea extends Component {@titleText={{i18n "user_tips.topic_timeline.title"}}@contentText={{i18n "user_tips.topic_timeline.content"}}@placement="left"- @triggerSelector=".timeline-scrollarea-wrapper"+ @portalOutletSelector=".timeline-scrollarea-wrapper"+ @triggerSelector=".timeline-scrollarea"@priority={{900}}/>diff --git a/frontend/discourse/app/components/user-tip.gjs b/frontend/discourse/app/components/user-tip.gjsindex 45178ed4d74..30f964e02a2 100644--- a/frontend/discourse/app/components/user-tip.gjs+++ b/frontend/discourse/app/components/user-tip.gjs@@ -33,6 +33,10 @@ export default class UserTip extends Component {this.args.triggerSelector &&document.querySelector(this.args.triggerSelector);+ const portalOutlet =+ this.args.portalOutletSelector &&+ document.querySelector(this.args.portalOutletSelector);+let buttonText = i18n(this.args.buttonLabel || "user_tips.button");if (this.args.buttonIcon) {buttonText = `${iconHTML(this.args.buttonIcon)} ${buttonText}`;@@ -44,6 +48,7 @@ export default class UserTip extends Component {closeOnScroll: false,closeOnClickOutside: true,placement: this.args.placement,+ portalOutletElement: portalOutlet,component: UserTipContainer,data: {id: this.args.id,diff --git a/frontend/discourse/float-kit/lib/constants.js b/frontend/discourse/float-kit/lib/constants.jsindex 0c7e59bbace..814cfeab22c 100644--- a/frontend/discourse/float-kit/lib/constants.js+++ b/frontend/discourse/float-kit/lib/constants.js@@ -30,6 +30,7 @@ export const TOOLTIP = {component: null,content: null,identifier: null,+ inline: null,interactive: false,listeners: false,maxWidth: 350,@@ -46,6 +47,7 @@ export const TOOLTIP = {onShow: null,onRegisterApi: null,updateOnScroll: true,+ portalOutletElement: null,},portalOutletId: "d-tooltip-portal-outlet",};@@ -87,6 +89,7 @@ export const MENU = {updateOnScroll: true,matchTriggerMinWidth: false,matchTriggerWidth: false,+ portalOutletElement: null,},portalOutletId: "d-menu-portal-outlet",};diff --git a/frontend/discourse/float-kit/lib/d-tooltip-instance.js b/frontend/discourse/float-kit/lib/d-tooltip-instance.jsindex 3fdb34e3e93..4c66951fab5 100644--- a/frontend/discourse/float-kit/lib/d-tooltip-instance.js+++ b/frontend/discourse/float-kit/lib/d-tooltip-instance.js@@ -27,6 +27,7 @@ export default class DTooltipInstance extends FloatKitInstance {* @property {Object} options - Options object that configures the tooltip behavior and display.*/@tracked options;+ @tracked portalOutletOverrideElement;@tracked _trigger;@@ -35,6 +36,7 @@ export default class DTooltipInstance extends FloatKitInstance {setOwner(this, owner);this.options = { ...TOOLTIP.options, ...options };+ this.portalOutletOverrideElement = options.portalOutletElement;}get trigger() {@@ -48,7 +50,10 @@ export default class DTooltipInstance extends FloatKitInstance {}get portalOutletElement() {- return document.getElementById("d-tooltip-portals");+ return (+ this.portalOutletOverrideElement ||+ document.getElementById("d-tooltip-portals")+ );}@actiondiff --git a/frontend/discourse/tests/integration/components/float-kit/d-tooltip-test.gjs b/frontend/discourse/tests/integration/components/float-kit/d-tooltip-test.gjsindex bc1865d936c..6e5811b839f 100644--- a/frontend/discourse/tests/integration/components/float-kit/d-tooltip-test.gjs+++ b/frontend/discourse/tests/integration/components/float-kit/d-tooltip-test.gjs@@ -1,5 +1,6 @@import { hash } from "@ember/helper";import { getOwner } from "@ember/owner";+import didInsert from "@ember/render-modifiers/modifiers/did-insert";import {click,render,@@ -353,4 +354,34 @@ module("Integration | Component | FloatKit | d-tooltip", function (hooks) {assert.dom(".fk-d-tooltip__content").doesNotExist();});++ test("@portalOutletElement", async function (assert) {+ this.set("portalOutletElement", null);+ this.setPortalOutletElement = (element) => {+ this.set("portalOutletElement", element);+ };++ await render(+ <template>+ <div+ id="custom-tooltip-portal"+ {{didInsert this.setPortalOutletElement}}+ ></div>+ {{#if this.portalOutletElement}}+ <DTooltip+ @inline={{false}}+ @label="label"+ @content="content"+ @portalOutletElement={{this.portalOutletElement}}+ />+ {{/if}}+ </template>+ );++ await click(".fk-d-tooltip__trigger");++ assert+ .dom("#custom-tooltip-portal .fk-d-tooltip__content")+ .exists("tooltip renders in custom portal outlet");+ });});