fix: retain profile popup placement

This commit is contained in:
Erwan Leboucher committed 2026-08-13 23:25:26 +02:00
1 parent 5c4e6d448c
commit 04efa82209
3 files changed
+34 -4

No files matched your search

@@ -42,6 +42,8 @@ function UserRoomProfileContextMenu({ state }: { state: UserRoomProfileState })
initialProfile={initialProfile}
onSurfaceColorChange={setSurfaceColor}
pmp={pmp}
anchor={cords}
position={position}
/>
</RoomProvider>
</SpaceProvider>
@@ -1,4 +1,5 @@
import { Box, Button, color, config, Menu, MenuItem, Scroll, Text, toRem } from 'folds';
import type { Position, RectCords } from 'folds';
import type { CSSProperties } from 'react';
import { useLayoutEffect, useMemo, useState } from 'react';
import { useNavigate } from 'react-router-dom';
@@ -416,12 +417,16 @@ type UserRoomProfileProps = {
pmp?: Persona;
initialProfile?: Partial<UserProfile>;
onSurfaceColorChange?: (color: string) => void;
anchor: RectCords;
position?: Position;
};
export function UserRoomProfile({
userId,
pmp: initialPmp,
initialProfile,
onSurfaceColorChange,
anchor,
position,
}: Readonly<UserRoomProfileProps>) {
const theme = useTheme();
const mx = useMatrixClient();
@@ -497,7 +502,7 @@ export function UserRoomProfile({
navigate(withSearchParam(getDirectCreatePath(), directSearchParam));
};
const mentionClickHandler = useMentionClickHandler(room.roomId);
const mentionClickHandler = useMentionClickHandler(room.roomId, anchor, position);
const settingsLinkBaseUrl = useSettingsLinkBaseUrl();
const linkifyOpts = useMemo<LinkifyOpts>(
+26 -3
View File
@@ -1,6 +1,7 @@
import type { ReactEventHandler } from 'react';
import { useCallback } from 'react';
import { useNavigate } from 'react-router-dom';
import type { Position, RectCords } from 'folds';
import { isRoomId, isUserId } from '$utils/matrix';
import { getHomeRoomPath, withSearchParam } from '$pages/pathUtils';
import { isSettingsSectionId } from '$features/settings/routes';
@@ -11,7 +12,11 @@ import { useMatrixClient } from './useMatrixClient';
import { useRoomNavigate } from './useRoomNavigate';
import { useSpaceOptionally } from './useSpace';
export const useMentionClickHandler = (roomId: string): ReactEventHandler<HTMLElement> => {
export const useMentionClickHandler = (
roomId: string,
profileAnchor?: RectCords,
profilePosition?: Position
): ReactEventHandler<HTMLElement> => {
const mx = useMatrixClient();
const { navigateRoom, navigateSpace } = useRoomNavigate();
const navigate = useNavigate();
@@ -38,7 +43,14 @@ export const useMentionClickHandler = (roomId: string): ReactEventHandler<HTMLEl
if (typeof mentionId !== 'string') return;
if (isUserId(mentionId)) {
openProfile(roomId, space?.roomId, mentionId, undefined, target.getBoundingClientRect());
openProfile(
roomId,
space?.roomId,
mentionId,
undefined,
profileAnchor ?? target.getBoundingClientRect(),
profilePosition
);
return;
}
@@ -54,7 +66,18 @@ export const useMentionClickHandler = (roomId: string): ReactEventHandler<HTMLEl
navigate(viaServers ? withSearchParam(path, { viaServers }) : path);
},
[mx, navigate, navigateRoom, navigateSpace, openProfile, openSettings, roomId, space]
[
mx,
navigate,
navigateRoom,
navigateSpace,
openProfile,
openSettings,
profileAnchor,
profilePosition,
roomId,
space,
]
);
return handleClick;