Skip to content

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

FIX: Correctly position user cards (#38072)

Jarek Radosze46946151cc1
diff --git a/frontend/discourse/app/components/card-contents-base.js b/frontend/discourse/app/components/card-contents-base.js
index 3f9f4fe08d2..bbe322a8104 100644
--- a/frontend/discourse/app/components/card-contents-base.js
+++ b/frontend/discourse/app/components/card-contents-base.js
@@ -1,7 +1,7 @@
/* eslint-disable ember/no-classic-components, ember/require-tagless-components */
import Component from "@ember/component";
import { alias, match } from "@ember/object/computed";
-import { next, schedule, throttle } from "@ember/runloop";
+import { next, throttle } from "@ember/runloop";
import { service } from "@ember/service";
import { bind } from "discourse/lib/decorators";
import { wantsNewWindow } from "discourse/lib/intercept-click";
@@ -194,52 +194,45 @@ export default class CardContentsBase extends Component {
return this._show(target.innerText.replace(/^@/, ""), target, event);
}
- get autoUpdateCard() {
- return this.cardTarget.dataset["autoUpdateCard"] === "true";
- }
-
- _positionCard(target) {
- schedule("afterRender", async () => {
- if (this.site.desktopView) {
- this._menuInstance = await this.menu.show(target, {
- content: this.element,
- autoUpdate: this.autoUpdateCard,
- hide: this.autoUpdateCard,
- identifier: "usercard",
- padding: {
- top: 10 + AVATAR_OVERFLOW_SIZE + headerOffset(),
- right: 10,
- bottom: 10,
- left: 10,
- },
- maxWidth: "unset",
- });
- } else {
- this._menuInstance = await this.menu.show(target, {
- content: this.element,
- strategy: "fixed",
- identifier: "usercard",
- computePosition: (content) => {
- content.style.left = "10px";
- content.style.right = "10px";
- content.style.top = 10 + AVATAR_OVERFLOW_SIZE + "px";
- },
- });
- }
+ async _positionCard(target) {
+ if (this.site.desktopView) {
+ this._menuInstance = await this.menu.show(target, {
+ content: this.element,
+ autoUpdate: { ancestorScroll: false, layoutShift: false },
+ identifier: "usercard",
+ padding: {
+ top: 10 + AVATAR_OVERFLOW_SIZE + headerOffset(),
+ right: 10,
+ bottom: 10,
+ left: 10,
+ },
+ maxWidth: "unset",
+ });
+ } else {
+ this._menuInstance = await this.menu.show(target, {
+ content: this.element,
+ strategy: "fixed",
+ identifier: "usercard",
+ computePosition: (content) => {
+ content.style.left = "10px";
+ content.style.right = "10px";
+ content.style.top = 10 + AVATAR_OVERFLOW_SIZE + "px";
+ },
+ });
+ }
- this.element.classList.toggle("docked-card", this.isDocked);
+ this.element.classList.toggle("docked-card", this.isDocked);
- // After the card is shown, focus on the first link
- //
- // note: we DO NOT use afterRender here cause _positionCard may
- // run afterwards, if we allowed this to happen the usercard
- // may be offscreen and we may scroll all the way to it on focus
+ // After the card is shown, focus on the first link
+ //
+ // note: we DO NOT use afterRender here cause _positionCard may
+ // run afterwards, if we allowed this to happen the usercard
+ // may be offscreen and we may scroll all the way to it on focus
- discourseLater(() => {
- this.element.setAttribute("tabindex", "-1");
- this.element.focus();
- }, 350);
- });
+ discourseLater(() => {
+ this.element.setAttribute("tabindex", "-1");
+ this.element.focus();
+ }, 350);
}
@bind
diff --git a/frontend/discourse/float-kit/components/d-float-body.gjs b/frontend/discourse/float-kit/components/d-float-body.gjs
index 4381f73d22b..4a789b6bcad 100644
--- a/frontend/discourse/float-kit/components/d-float-body.gjs
+++ b/frontend/discourse/float-kit/components/d-float-body.gjs
@@ -1,5 +1,5 @@
import Component from "@glimmer/component";
-import { concat, fn, hash } from "@ember/helper";
+import { fn, hash } from "@ember/helper";
import { htmlSafe } from "@ember/template";
import { modifier as modifierFn } from "ember-modifier";
import DFloatPortal from "discourse/float-kit/components/d-float-portal";
@@ -62,6 +62,15 @@ export default class DFloatBody extends Component {
return this.args.instance.options;
}
+ get style() {
+ const maxWidth =
+ typeof this.options.maxWidth === "number"
+ ? `${this.options.maxWidth}px`
+ : this.options.maxWidth;
+
+ return htmlSafe(`max-width: ${maxWidth}`);
+ }
+
<template>
{{~! strip whitespace ~}}<DFloatPortal
@inline={{@inline}}
@@ -94,7 +103,7 @@ export default class DFloatBody extends Component {
(modifier FloatKitCloseOnEscape @instance.close)
)}}
{{(if this.supportsCloseOnScroll (modifier this.closeOnScroll))}}
- style={{htmlSafe (concat "max-width: " this.options.maxWidth "px")}}
+ style={{this.style}}
...attributes
>
<div class={{@innerClass}}>
diff --git a/frontend/discourse/float-kit/lib/constants.js b/frontend/discourse/float-kit/lib/constants.js
index 814cfeab22c..d89bce55c89 100644
--- a/frontend/discourse/float-kit/lib/constants.js
+++ b/frontend/discourse/float-kit/lib/constants.js
@@ -46,7 +46,6 @@ export const TOOLTIP = {
onClose: null,
onShow: null,
onRegisterApi: null,
- updateOnScroll: true,
portalOutletElement: null,
},
portalOutletId: "d-tooltip-portal-outlet",
@@ -86,7 +85,6 @@ export const MENU = {
triggerClass: null,
contentClass: null,
class: null,
- updateOnScroll: true,
matchTriggerMinWidth: false,
matchTriggerWidth: false,
portalOutletElement: null,
@@ -99,6 +97,7 @@ import DDefaultToast from "discourse/float-kit/components/d-default-toast";
export const TOAST = {
options: {
autoClose: true,
+ autoUpdate: { ancestorScroll: false },
duration: "short",
component: DDefaultToast,
showProgressBar: false,
diff --git a/frontend/discourse/float-kit/modifiers/apply-floating-ui.js b/frontend/discourse/float-kit/modifiers/apply-floating-ui.js
index ccc1cc3232f..99c881f4f8c 100644
--- a/frontend/discourse/float-kit/modifiers/apply-floating-ui.js
+++ b/frontend/discourse/float-kit/modifiers/apply-floating-ui.js
@@ -16,9 +16,14 @@ export default class FloatKitApplyFloatingUi extends Modifier {
this.options = options ?? {};
if (this.options.autoUpdate) {
- this.cleanup = autoUpdate(trigger, element, this.update, {
- ancestorScroll: options.updateOnScroll,
- });
+ this.cleanup = autoUpdate(
+ trigger,
+ element,
+ this.update,
+ typeof this.options.autoUpdate === "object"
+ ? this.options.autoUpdate
+ : {}
+ );
} else {
this.update();
}
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-user-avatar.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-user-avatar.gjs
index 8e776f45483..62382019858 100644
--- a/plugins/chat/assets/javascripts/discourse/components/chat-user-avatar.gjs
+++ b/plugins/chat/assets/javascripts/discourse/components/chat-user-avatar.gjs
@@ -57,7 +57,6 @@ export default class ChatUserAvatar extends Component {
class="chat-user-avatar__container"
href={{this.userPath}}
data-user-card={{@user.username}}
- data-auto-update-card={{this.isFullPageActive}}
>
{{this.avatar}}
</a>
diff --git a/plugins/discourse-ai/assets/javascripts/discourse/connectors/post-text-buttons/ai-post-helper-trigger.gjs b/plugins/discourse-ai/assets/javascripts/discourse/connectors/post-text-buttons/ai-post-helper-trigger.gjs
index 2aa689a816f..0d5bd4281f6 100644
--- a/plugins/discourse-ai/assets/javascripts/discourse/connectors/post-text-buttons/ai-post-helper-trigger.gjs
+++ b/plugins/discourse-ai/assets/javascripts/discourse/connectors/post-text-buttons/ai-post-helper-trigger.gjs
@@ -125,7 +125,7 @@ export default class AiPostHelperTrigger extends Component {
data: this.menuData,
placement: "top-start",
fallbackPlacements: ["bottom-start"],
- updateOnScroll: false,
+ autoUpdate: { ancestorScroll: false },
onClose: () => {
this.removeHighlightedText();
},