Skip to content

A platform for community discussion. Free, open, simple.

DEV: Replace popperjs with floating-ui (#35492)

Jarek Radosz1ea6dd56cacc
diff --git a/app/assets/stylesheets/common/select-kit/select-kit.scss b/app/assets/stylesheets/common/select-kit/select-kit.scss
index c9713a4f2bc..543351a4af6 100644
--- a/app/assets/stylesheets/common/select-kit/select-kit.scss
+++ b/app/assets/stylesheets/common/select-kit/select-kit.scss
@@ -191,18 +191,14 @@
display: none;
background: var(--secondary);
box-sizing: border-box;
+ width: max-content;
+ top: 0;
+ left: 0;
.selected-content {
max-height: 300px;
overflow-y: auto;
}
-
- &[data-popper-reference-hidden] {
- html:not(.ios-device) & {
- visibility: hidden;
- pointer-events: none;
- }
- }
}
.select-kit-row {
diff --git a/frontend/discourse/app/lib/hashtag-autocomplete.js b/frontend/discourse/app/lib/hashtag-autocomplete.js
index c2faac5406c..3ac5c67ffc8 100644
--- a/frontend/discourse/app/lib/hashtag-autocomplete.js
+++ b/frontend/discourse/app/lib/hashtag-autocomplete.js
@@ -28,7 +28,7 @@ import { CANCELLED_STATUS } from "discourse/modifiers/d-autocomplete";
* Can also include:
*
* - treatAsTextarea - Whether to anchor the autocompletion to the start of the input and
- * ensure the popper is always on top.
+ * ensure the floating element is always on top.
**/
export function setupHashtagAutocomplete(
contextualHashtagConfiguration,
diff --git a/frontend/discourse/app/loader-shims.js b/frontend/discourse/app/loader-shims.js
index d1c0040e791..0903a8b731f 100644
--- a/frontend/discourse/app/loader-shims.js
+++ b/frontend/discourse/app/loader-shims.js
@@ -70,7 +70,6 @@ loaderShim("@messageformat/runtime/lib/cardinals", () =>
loaderShim("@messageformat/runtime/messages", () =>
importSync("@messageformat/runtime/messages")
);
-loaderShim("@popperjs/core", () => importSync("@popperjs/core"));
loaderShim("@uppy/aws-s3", () => importSync("@uppy/aws-s3"));
loaderShim("@uppy/core", () => importSync("@uppy/core"));
loaderShim("@uppy/drop-target", () => importSync("@uppy/drop-target"));
diff --git a/frontend/discourse/package.json b/frontend/discourse/package.json
index cba45a28f6e..5be7be744c7 100644
--- a/frontend/discourse/package.json
+++ b/frontend/discourse/package.json
@@ -96,7 +96,6 @@
"@embroider/webpack": "^4.1.0",
"@floating-ui/dom": "^1.7.4",
"@glimmer/component": "^2.0.0",
- "@popperjs/core": "^2.11.8",
"@swc/core": "^1.15.3",
"@types/jquery": "^3.5.33",
"@types/qunit": "^2.19.13",
diff --git a/frontend/discourse/select-kit/components/select-kit.js b/frontend/discourse/select-kit/components/select-kit.js
index 53e2769c94e..ddc2b491aa7 100644
--- a/frontend/discourse/select-kit/components/select-kit.js
+++ b/frontend/discourse/select-kit/components/select-kit.js
@@ -11,11 +11,19 @@ import {
classNames,
tagName,
} from "@ember-decorators/component";
-import { createPopper } from "@popperjs/core";
+import {
+ autoUpdate,
+ computePosition,
+ flip,
+ hide,
+ limitShift,
+ offset,
+ shift,
+ size,
+} from "@floating-ui/dom";
import { Promise } from "rsvp";
import { uniqueItemsFromArray } from "discourse/lib/array-tools";
import discourseDebounce from "discourse/lib/debounce";
-import { bind as bindDecorator } from "discourse/lib/decorators";
import deprecated from "discourse/lib/deprecated";
import { INPUT_DELAY } from "discourse/lib/environment";
import { makeArray } from "discourse/lib/helpers";
@@ -53,6 +61,11 @@ function concatProtoProperty(target, key, value) {
];
}
+function roundByDPR(value) {
+ const dpr = window.devicePixelRatio || 1;
+ return Math.round(value * dpr) / dpr;
+}
+
/**
* @decorator
*
@@ -307,7 +320,11 @@ export default class SelectKit extends Component {
didInsertElement() {
super.didInsertElement(...arguments);
- this.appEvents.on("keyboard-visibility-change", this, this._updatePopper);
+ this.appEvents.on(
+ "keyboard-visibility-change",
+ this,
+ this.updateFloatingUiPosition
+ );
if (this.selectKit.options.expandedOnInsert) {
next(() => {
@@ -326,12 +343,13 @@ export default class SelectKit extends Component {
this._cancelSearch();
- this.appEvents.off("keyboard-visibility-change", this, this._updatePopper);
+ this.appEvents.off(
+ "keyboard-visibility-change",
+ this,
+ this.updateFloatingUiPosition
+ );
- if (this.popper) {
- this.popper.destroy();
- this.popper = null;
- }
+ this.cleanupFloatingUi?.();
}
didReceiveAttrs() {
@@ -450,8 +468,6 @@ export default class SelectKit extends Component {
if (!this.errorsCollection.includes(error)) {
this.errorsCollection.push(error);
}
-
- this._safeAfterRender(() => this._updatePopper());
}
clearErrors() {
@@ -485,8 +501,6 @@ export default class SelectKit extends Component {
}
_onInput(event) {
- this._updatePopper();
-
if (this._searchPromise) {
cancel(this._searchPromise);
}
@@ -554,7 +568,6 @@ export default class SelectKit extends Component {
if (this.selectKit.options.focusAfterOnChange) {
this._safeAfterRender(() => {
this._focusFilter();
- this._updatePopper();
});
}
}
@@ -712,7 +725,6 @@ export default class SelectKit extends Component {
"selectKit.isLoading": true,
"selectKit.enterDisabled": true,
});
- this._safeAfterRender(() => this._updatePopper());
let content = [];
@@ -778,7 +790,6 @@ export default class SelectKit extends Component {
this._safeAfterRender(() => {
if (this.selectKit.isExpanded) {
- this._updatePopper();
this._focusFilter();
}
});
@@ -935,6 +946,8 @@ export default class SelectKit extends Component {
return;
}
+ this.cleanupFloatingUi?.();
+
this.selectKit.mainElement().open = false;
this.clearErrors();
@@ -956,107 +969,15 @@ export default class SelectKit extends Component {
this.clearErrors();
this.selectKit.onOpen(event);
- if (!this.popper) {
- const anchor = document.querySelector(
- `#${this.selectKit.uniqueID}-header`
+ if (this.site.desktopView) {
+ this.cleanupFloatingUi?.();
+ this.cleanupFloatingUi = autoUpdate(
+ this.getHeader(),
+ this._mainElement(),
+ () => this.updateFloatingUiPosition()
);
- const popper = document.querySelector(`#${this.selectKit.uniqueID}-body`);
- const strategy = this._computePlacementStrategy();
-
- let bottomOffset = 0;
- if (this.capabilities.isIOS) {
- bottomOffset +=
- parseInt(
- getComputedStyle(document.documentElement)
- .getPropertyValue("--safe-area-inset-bottom")
- .trim(),
- 10
- ) || 0;
- }
- if (this.site.mobileView) {
- bottomOffset +=
- parseInt(
- getComputedStyle(document.documentElement)
- .getPropertyValue("--footer-nav-height")
- .trim(),
- 10
- ) || 0;
- }
-
- this.popper = createPopper(anchor, popper, {
- eventsEnabled: false,
- strategy,
- placement: this.selectKit.options.placement,
- modifiers: [
- {
- name: "eventListeners",
- options: {
- resize: this.site.desktopView,
- scroll: this.site.desktopView,
- },
- },
- {
- name: "flip",
- options: {
- padding: {
- top:
- parseInt(
- document.documentElement.style.getPropertyValue(
- "--header-offset"
- ),
- 10
- ) || 0,
- bottom: bottomOffset,
- },
- },
- },
- {
- name: "offset",
- options: {
- offset: [0, this.selectKit.options.verticalOffset],
- },
- },
- {
- name: "applySmallScreenOffset",
- enabled: window.innerWidth <= 450,
- phase: "main",
- fn({ state }) {
- let { x } = state.elements.reference.getBoundingClientRect();
- if (strategy === "fixed") {
- state.modifiersData.popperOffsets.x = 0 + 10;
- } else {
- state.modifiersData.popperOffsets.x = -x + 10;
- }
- },
- },
- {
- name: "applySmallScreenMaxWidth",
- enabled: window.innerWidth <= 450,
- phase: "beforeWrite",
- fn: ({ state }) => {
- state.styles.popper.width = `${window.innerWidth - 20}px`;
- },
- },
- {
- name: "minWidth",
- enabled: window.innerWidth > 450,
- phase: "beforeWrite",
- requires: ["computeStyles"],
- fn: ({ state }) => {
- state.styles.popper.minWidth = `${Math.max(
- state.rects.reference.width,
- 220
- )}px`;
- },
- effect: ({ state }) => {
- state.elements.popper.style.minWidth = `${Math.max(
- state.elements.reference.offsetWidth,
- 220
- )}px`;
- },
- },
- ],
- });
+ } else {
+ this.updateFloatingUiPosition();
}
this.selectKit.setProperties({
@@ -1074,7 +995,125 @@ export default class SelectKit extends Component {
this._safeAfterRender(() => {
this._focusFilter();
this._scrollToCurrent();
- this._updatePopper();
+ });
+ }
+
+ updateFloatingUiPosition() {
+ const referenceElement = this.getHeader();
+ const floatingElement = this._bodyElement();
+
+ const strategy = this._computePlacementStrategy();
+ floatingElement.style.position = strategy;
+
+ let width;
+ let minWidth;
+
+ const middleware = [
+ {
+ name: "minWidth",
+ fn: (state) => {
+ if (window.innerWidth <= 450) {
+ return state;
+ }
+
+ return size({
+ apply({ rects }) {
+ minWidth = `${Math.max(Math.round(rects.reference.width), 220)}px`;
+ },
+ }).fn(state);
+ },
+ },
+ {
+ name: "flip",
+ fn: (state) => {
+ const top =
+ parseInt(
+ document.documentElement.style.getPropertyValue(
+ "--header-offset"
+ ),
+ 10
+ ) || 0;
+
+ let bottom = 0;
+ if (this.capabilities.isIOS) {
+ bottom +=
+ parseInt(
+ getComputedStyle(document.documentElement)
+ .getPropertyValue("--safe-area-inset-bottom")
+ .trim(),
+ 10
+ ) || 0;
+ }
+ if (this.site.mobileView) {
+ bottom +=
+ parseInt(
+ getComputedStyle(document.documentElement)
+ .getPropertyValue("--footer-nav-height")
+ .trim(),
+ 10
+ ) || 0;
+ }
+
+ return flip({
+ padding: { top, bottom },
+ fallbackStrategy: "initialPlacement",
+ }).fn(state);
+ },
+ },
+ shift({ limiter: limitShift() }),
+ offset(this.selectKit.options.verticalOffset),
+ {
+ name: "applySmallScreenOffset",
+ fn: (state) => {
+ if (window.innerWidth > 450) {
+ return state;
+ }
+
+ let { x } = state.elements.reference.getBoundingClientRect();
+ if (strategy === "fixed") {
+ return { x: 10, y: state.y };
+ } else {
+ return { x: -x + 10, y: state.y };
+ }
+ },
+ },
+ {
+ name: "applySmallScreenMaxWidth",
+ fn: (state) => {
+ if (window.innerWidth <= 450) {
+ width = `${window.innerWidth - 20}px`;
+ }
+
+ return state;
+ },
+ },
+ hide(),
+ ];
+
+ computePosition(referenceElement, floatingElement, {
+ placement: this.selectKit.options.placement,
+ strategy,
+ middleware,
+ }).then(({ x, y, middlewareData }) => {
+ const style = {
+ width,
+ minWidth,
+ top: "0",
+ left: "0",
+ transform: `translate(${roundByDPR(x)}px,${roundByDPR(y)}px)`,
+ };
+
+ if (middlewareData.hide && !this.capabilities.isIOS) {
+ if (middlewareData.hide.referenceHidden) {
+ style.visibility = "hidden";
+ style.pointerEvents = "none";
+ } else {
+ style.visibility = "visible";
+ style.pointerEvents = "auto";
+ }
+ }
+
+ Object.assign(floatingElement.style, style);
});
}
@@ -1151,11 +1190,6 @@ export default class SelectKit extends Component {
this._handleDeprecatedArgs();
}
- @bindDecorator
- _updatePopper() {
- this.popper?.update?.();
- }
-
_computePlacementStrategy() {
let placementStrategy = this.selectKit.options.placementStrategy;
diff --git a/frontend/discourse/select-kit/components/select-kit/select-kit-body.gjs b/frontend/discourse/select-kit/components/select-kit/select-kit-body.gjs
index eea6db6f548..4a8c3a3e0b9 100644
--- a/frontend/discourse/select-kit/components/select-kit/select-kit-body.gjs
+++ b/frontend/discourse/select-kit/components/select-kit/select-kit-body.gjs
@@ -16,7 +16,6 @@ export default class SelectKitBody extends Component {
didInsertElement() {
super.didInsertElement(...arguments);
- this.element.style.position = "relative";
document.addEventListener("click", this.handleClick, true);
this.selectKit
.mainElement()
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-message-actions-desktop.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-message-actions-desktop.gjs
index 4b92562cada..9efa8d8c81d 100644
--- a/plugins/chat/assets/javascripts/discourse/components/chat-message-actions-desktop.gjs
+++ b/plugins/chat/assets/javascripts/discourse/components/chat-message-actions-desktop.gjs
@@ -6,10 +6,15 @@ import { action } from "@ember/object";
import { getOwner } from "@ember/owner";
import didInsert from "@ember/render-modifiers/modifiers/did-insert";
import didUpdate from "@ember/render-modifiers/modifiers/did-update";
-import willDestroy from "@ember/render-modifiers/modifiers/will-destroy";
-import { schedule } from "@ember/runloop";
import { service } from "@ember/service";
-import { createPopper } from "@popperjs/core";
+import {
+ computePosition,
+ flip,
+ hide,
+ limitShift,
+ offset,
+ shift,
+} from "@floating-ui/dom";
import BookmarkIcon from "discourse/components/bookmark-icon";
import DButton from "discourse/components/d-button";
import concatClass from "discourse/helpers/concat-class";
@@ -30,8 +35,6 @@ export default class ChatMessageActionsDesktop extends Component {
@tracked size = FULL;
- popper = null;
-
get message() {
return this.chat.activeMessage.model;
}
@@ -64,50 +67,50 @@ export default class ChatMessageActionsDesktop extends Component {
@action
setup(element) {
- this.popper?.destroy();
-
- schedule("afterRender", () => {
- if (!this.messageContainer) {
- return;
- }
-
- const viewport = this.messageContainer.closest(".popper-viewport");
- this.size =
- viewport.clientWidth < REDUCED_WIDTH_THRESHOLD ? REDUCED : FULL;
+ if (!this.messageContainer) {
+ return;
+ }
- if (!this.messageContainer) {
- return;
+ const boundary = this.messageContainer.closest(".chat-messages-scroller");
+ this.size = boundary.clientWidth < REDUCED_WIDTH_THRESHOLD ? REDUCED : FULL;
+
+ computePosition(this.messageContainer, element, {
+ placement: "top-end",
+ strategy: "fixed",
+ middleware: [
+ offset({
+ mainAxis: MSG_ACTIONS_VERTICAL_PADDING,
+ crossAxis: -2,
+ }),
+ flip({
+ boundary,
+ fallbackPlacements: ["bottom-end"],
+ }),
+ shift({ limiter: limitShift() }),
+ hide({ strategy: "referenceHidden" }),
+ hide({ strategy: "escaped" }),
+ ],
+ }).then(({ x, y, middlewareData }) => {
+ const style = {
+ left: `${x}px`,
+ top: `${y}px`,
+ };
+
+ if (
+ middlewareData.hide?.referenceHidden ||
+ middlewareData.hide?.escaped
+ ) {
+ style.visibility = "hidden";
+ style.pointerEvents = "none";
+ } else {
+ style.visibility = "visible";
+ style.pointerEvents = "auto";
}
- this.popper = createPopper(this.messageContainer, element, {
- placement: "top-end",
- strategy: "fixed",
- modifiers: [
- {
- name: "flip",
- enabled: true,
- options: {
- boundary: viewport,
- fallbackPlacements: ["bottom-end"],
- },
- },
- { name: "hide", enabled: true },
- { name: "eventListeners", options: { scroll: false } },
- {
- name: "offset",
- options: { offset: [-2, MSG_ACTIONS_VERTICAL_PADDING] },
- },
- ],
- });
+ Object.assign(element.style, style);
});
}
- @action
- teardown() {
- this.popper?.destroy();
- this.popper = null;
- }
-
@action
redirectScroll(event) {
event.preventDefault();
@@ -128,7 +131,6 @@ export default class ChatMessageActionsDesktop extends Component {
<div
{{didInsert this.setup}}
{{didUpdate this.setup this.chat.activeMessage.model.id}}
- {{willDestroy this.teardown}}
class={{concatClass
"chat-message-actions-container"
(concat "is-size-" this.size)
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-messages-scroller.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-messages-scroller.gjs
index b76a1db8390..7c1ac10aa2f 100644
--- a/plugins/chat/assets/javascripts/discourse/components/chat-messages-scroller.gjs
+++ b/plugins/chat/assets/javascripts/discourse/components/chat-messages-scroller.gjs
@@ -4,7 +4,7 @@ import ChatScrollableList from "../modifiers/chat/scrollable-list";
const ChatMessagesScroller = <template>
<div
- class="chat-messages-scroller popper-viewport"
+ class="chat-messages-scroller"
{{didInsert @onRegisterScroller}}
{{this.setupLock}}
{{ChatScrollableList
diff --git a/plugins/chat/assets/stylesheets/common/base-common.scss b/plugins/chat/assets/stylesheets/common/base-common.scss
index e13fe233011..02964952230 100644
--- a/plugins/chat/assets/stylesheets/common/base-common.scss
+++ b/plugins/chat/assets/stylesheets/common/base-common.scss
@@ -293,10 +293,6 @@ html.has-full-page-chat {
min-height: 0;
}
}
-
- [data-popper-reference-hidden] {
- visibility: hidden;
- }
}
.sidebar-section-link-wrapper[data-list-item-name="new-chat-dm"] {
diff --git a/plugins/chat/assets/stylesheets/common/chat-message-actions.scss b/plugins/chat/assets/stylesheets/common/chat-message-actions.scss
index 5c52b885d9b..26c89223d34 100644
--- a/plugins/chat/assets/stylesheets/common/chat-message-actions.scss
+++ b/plugins/chat/assets/stylesheets/common/chat-message-actions.scss
@@ -5,6 +5,10 @@
.chat-message-actions-container {
@include unselectable;
+ position: fixed;
+ width: max-content;
+ top: 0;
+ left: 0;
z-index: z("composer", "content");
}
diff --git a/plugins/chat/assets/stylesheets/desktop/chat-message-actions.scss b/plugins/chat/assets/stylesheets/desktop/chat-message-actions.scss
index 2e443d11289..9ac3da847cc 100644
--- a/plugins/chat/assets/stylesheets/desktop/chat-message-actions.scss
+++ b/plugins/chat/assets/stylesheets/desktop/chat-message-actions.scss
@@ -1,9 +1,3 @@
.chat-message-actions {
background-color: var(--secondary);
}
-
-.chat-message-actions-container[data-popper-reference-hidden],
-.chat-message-actions-container[data-popper-escaped] {
- visibility: hidden;
- pointer-events: none;
-}
diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/lib/popover.js b/plugins/discourse-calendar/assets/javascripts/discourse/lib/popover.js
deleted file mode 100644
index 65a262bd346..00000000000
--- a/plugins/discourse-calendar/assets/javascripts/discourse/lib/popover.js
+++ /dev/null
@@ -1,39 +0,0 @@
-import { createPopper } from "@popperjs/core";
-
-let eventPopper;
-const EVENT_POPOVER_ID = "event-popover";
-
-export function buildPopover(jsEvent, htmlContent) {
- const node = document.createElement("div");
- node.setAttribute("id", EVENT_POPOVER_ID);
- node.innerHTML = htmlContent;
-
- const arrow = document.createElement("span");
- arrow.dataset.popperArrow = true;
- node.appendChild(arrow);
- document.body.appendChild(node);
-
- eventPopper = createPopper(
- jsEvent.target,
- document.getElementById(EVENT_POPOVER_ID),
- {
- placement: "bottom",
- modifiers: [
- {
- name: "arrow",
- },
- {
- name: "offset",
- options: {
- offset: [20, 10],
- },
- },
- ],
- }
- );
-}
-
-export function destroyPopover() {
- eventPopper?.destroy();
- document.getElementById(EVENT_POPOVER_ID)?.remove();
-}
diff --git a/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-actions.gjs b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-actions.gjs
index d371a0f07ff..14ddae61773 100644
--- a/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-actions.gjs
+++ b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-actions.gjs
@@ -6,7 +6,13 @@ import { action } from "@ember/object";
import didInsert from "@ember/render-modifiers/modifiers/did-insert";
import { cancel, later, run, schedule } from "@ember/runloop";
import { service } from "@ember/service";
-import { createPopper } from "@popperjs/core";
+import {
+ computePosition,
+ flip,
+ limitShift,
+ offset,
+ shift,
+} from "@floating-ui/dom";
import curryComponent from "ember-curry-component";
import $ from "jquery";
import { Promise } from "rsvp";
@@ -24,11 +30,10 @@ import DiscourseReactionsReactionButton from "./discourse-reactions-reaction-but
const VIBRATE_DURATION = 5;
-let _popperPicker;
-let _currentReactionWidget;
+let activeReactionsComponent;
export function resetCurrentReaction() {
- _currentReactionWidget = null;
+ activeReactionsComponent = null;
}
function buildFakeReaction(reactionId) {
@@ -610,25 +615,19 @@ export default class DiscourseReactionsActions extends Component {
expandReactionsPicker() {
cancel(this._collapseHandler);
- _currentReactionWidget?.collapseAllPanels();
+ activeReactionsComponent?.collapseAllPanels();
this.statePanelExpanded = false;
this.reactionsPickerExpanded = true;
- this._setupPopper([
- ".discourse-reactions-reaction-button",
- ".discourse-reactions-picker",
- ]);
+ this.updateReactionsPickerPopover();
}
@action
expandStatePanel() {
cancel(this._collapseHandler);
- _currentReactionWidget?.collapseAllPanels();
+ activeReactionsComponent?.collapseAllPanels();
this.statePanelExpanded = true;
this.reactionsPickerExpanded = false;
- this._setupPopper([
- ".discourse-reactions-counter",
- ".discourse-reactions-state-panel",
- ]);
+ this.updateReactionsStatePanel();
}
@action
@@ -657,42 +656,47 @@ export default class DiscourseReactionsActions extends Component {
}
@action
- updatePopperPosition() {
- _popperPicker?.update();
+ updateReactionsPickerPopover() {
+ this.showPopover(
+ ".discourse-reactions-reaction-button",
+ ".discourse-reactions-picker"
+ );
+ }
+
+ @action
+ updateReactionsStatePanel() {
+ this.showPopover(
+ ".discourse-reactions-counter",
+ ".discourse-reactions-state-panel"
+ );
}
- _setupPopper(selectors) {
+ showPopover(referenceSelector, floatingSelector) {
schedule("afterRender", () => {
- if (!this.containerElement) {
+ const referenceElement =
+ this.containerElement?.querySelector(referenceSelector);
+ const floatingElement =
+ this.containerElement?.querySelector(floatingSelector);
+
+ if (!floatingElement) {
return;
}
- const trigger = this.containerElement.querySelector(selectors[0]);
- const popper = this.containerElement.querySelector(selectors[1]);
-
- _popperPicker?.destroy();
- _popperPicker = this._applyPopper(trigger, popper);
- _currentReactionWidget = this;
- });
- }
+ computePosition(referenceElement, floatingElement, {
+ placement: "top",
+ middleware: [
+ offset(-5),
+ shift({ limiter: limitShift() }),
+ flip({ padding: 5 }),
+ ],
+ }).then(({ x, y }) => {
+ Object.assign(floatingElement.style, {
+ left: `${x}px`,
+ top: `${y}px`,
+ });
+ });
- _applyPopper(button, picker) {
- return createPopper(button, picker, {
- placement: "top",
- modifiers: [
- {
- name: "offset",
- options: {
- offset: [0, -5],
- },
- },
- {
- name: "preventOverflow",
- options: {
- padding: 5,
- },
- },
- ],
+ activeReactionsComponent = this;
});
}
@@ -774,7 +778,7 @@ export default class DiscourseReactionsActions extends Component {
collapseStatePanel=this.collapseStatePanel
cancelCollapse=this.cancelCollapse
scheduleCollapse=this.scheduleCollapse
- updatePopperPosition=this.updatePopperPosition
+ updatePopover=this.updateReactionsStatePanel
collapseAllPanels=this.collapseAllPanels
)
)
diff --git a/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-counter.gjs b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-counter.gjs
index fea7d5f2652..7b09d1dceab 100644
--- a/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-counter.gjs
+++ b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-counter.gjs
@@ -32,28 +32,26 @@ export default class DiscourseReactionsCounter extends Component {
}
@bind
- getUsers(reactionValue) {
- return CustomReaction.findReactionUsers(this.args.post.id, {
+ async getUsers(reactionValue) {
+ const response = await CustomReaction.findReactionUsers(this.args.post.id, {
reactionValue,
- }).then((response) => {
- response.reaction_users.forEach((reactionUser) => {
- this.reactionsUsers[reactionUser.id] = reactionUser.users;
- });
+ });
- this.args.updatePopperPosition();
+ response.reaction_users.forEach((reactionUser) => {
+ this.reactionsUsers[reactionUser.id] = reactionUser.users;
});
+
+ this.args.updatePopover();
}
@action
mouseDown(event) {
event.stopImmediatePropagation();
- return false;
}
@action
mouseUp(event) {
event.stopImmediatePropagation();
- return false;
}
@action
diff --git a/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-list-emoji.gjs b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-list-emoji.gjs
index a8ea2bd356f..683ab4837e7 100644
--- a/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-list-emoji.gjs
+++ b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-list-emoji.gjs
@@ -2,15 +2,20 @@ import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
import { on } from "@ember/modifier";
import { action } from "@ember/object";
-import { debounce, schedule } from "@ember/runloop";
+import { debounce } from "@ember/runloop";
import { service } from "@ember/service";
-import { createPopper } from "@popperjs/core";
+import {
+ computePosition,
+ flip,
+ limitShift,
+ offset,
+ shift,
+} from "@floating-ui/dom";
import emoji from "discourse/helpers/emoji";
import { bind } from "discourse/lib/decorators";
import { i18n } from "discourse-i18n";
const DISPLAY_MAX_USERS = 19;
-let _popperReactionUserPanel;
export default class DiscourseReactionsListEmoji extends Component {
@service siteSettings;
@@ -23,43 +28,33 @@ export default class DiscourseReactionsListEmoji extends Component {
@action
pointerOver(event) {
- if (event.pointerType !== "mouse") {
+ if (event.pointerType !== "mouse" || !this.args.reaction.count) {
return;
}
- this._setupPopper(".user-list");
+ this.showTooltip();
if (!this.args.users?.length && !this.loadingReactions) {
debounce(this, this._loadReactionUsers, 3000, true);
}
}
- _setupPopper(selector) {
- schedule("afterRender", () => {
- const elementId = CSS.escape(this.elementId);
- const trigger = document.querySelector(`#${elementId}`);
- const popperElement = document.querySelector(`#${elementId} ${selector}`);
+ showTooltip() {
+ const referenceElement = document.getElementById(this.elementId);
+ const floatingElement = referenceElement.querySelector(".user-list");
- if (popperElement) {
- _popperReactionUserPanel && _popperReactionUserPanel.destroy();
- _popperReactionUserPanel = createPopper(trigger, popperElement, {
- placement: "bottom",
- modifiers: [
- {
- name: "offset",
- options: {
- offset: [0, -5],
- },
- },
- {
- name: "preventOverflow",
- options: {
- padding: 5,
- },
- },
- ],
- });
- }
+ computePosition(referenceElement, floatingElement, {
+ placement: "bottom",
+ middleware: [
+ offset(-5),
+ shift({ limiter: limitShift() }),
+ flip({ padding: 5 }),
+ ],
+ }).then(({ x, y }) => {
+ Object.assign(floatingElement.style, {
+ left: `${x}px`,
+ top: `${y}px`,
+ });
});
}
diff --git a/plugins/discourse-reactions/assets/stylesheets/common/discourse-reactions.scss b/plugins/discourse-reactions/assets/stylesheets/common/discourse-reactions.scss
index e80ac1e8dd1..eb70a71e368 100644
--- a/plugins/discourse-reactions/assets/stylesheets/common/discourse-reactions.scss
+++ b/plugins/discourse-reactions/assets/stylesheets/common/discourse-reactions.scss
@@ -61,6 +61,9 @@ html.discourse-reactions-no-select {
padding: 0.5em 0;
min-width: 120px;
min-height: 80px;
+ width: max-content;
+ top: 0;
+ left: 0;
.spinner {
animation-play-state: paused;
@@ -124,6 +127,9 @@ html.discourse-reactions-no-select {
position: absolute;
visibility: hidden;
padding: 15px 0;
+ width: max-content;
+ top: 0;
+ left: 0;
&.is-expanded {
visibility: visible;
@@ -187,6 +193,9 @@ html.discourse-reactions-no-select {
position: absolute;
visibility: hidden;
padding: 15px 0;
+ width: max-content;
+ top: 0;
+ left: 0;
&.is-expanded {
min-width: 80px;
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 919dd60fe30..b6b7e3e17fa 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -437,9 +437,6 @@ importers:
'@glimmer/component':
specifier: ^2.0.0
version: 2.0.0
- '@popperjs/core':
- specifier: ^2.11.8
- version: 2.11.8
'@swc/core':
specifier: ^1.15.3
version: 1.15.3
@@ -2471,9 +2468,6 @@ packages:
resolution: {integrity: sha512-4rdu8GPY9TeQwsYp5D2My74dC3dSVS3tghAvisG80ybK4lqa0gvlrglaSTBxogJbxqHRw/NjI/liEtb3+SD+Bw==}
engines: {node: '>=18.12'}
- '@popperjs/[email protected]':
- resolution: {integrity: sha512-P1st0aksCrn9sGZhp8GMYwBnQsbvAWsZAX44oXNNvLHGqAOcoVxmjZiohstwQ7SqKnbR47akdNi+uleWD8+g6A==}
-
'@puppeteer/[email protected]':
resolution: {integrity: sha512-n6oQX6mYkG8TRPuPXmbPidkUbsSRalhmaaVAQxvH1IkQy63cwsH+kOjB3e4cpCDHg0aSvsiX9bQ4s2VB6mGWUQ==}
engines: {node: '>=18'}
@@ -11184,8 +11178,6 @@ snapshots:
'@pnpm/error': 1000.0.5
find-up: 5.0.0
- '@popperjs/[email protected]': {}
-
'@puppeteer/[email protected]':
dependencies:
debug: 4.4.3([email protected])