fix: stop click handlers firing after long-press and drag-select

Long-press on a room/space nav item opened the context menu, but the
synthetic click that followed navigated and immediately dismissed it.
Guard the click path with menu.consumeLongPressFired() (RoomNavItem,
SpaceTabs).

Drag-selecting across an abbreviation or mention link fired click on
mouseup, toggling the tooltip or navigating away and killing the
selection. Guard those handlers with a collapsed-selection check
(AbbreviationTerm, useMentionClickHandler) and make abbreviation text
selectable on desktop only (mobile keeps userSelect:none so the
long-press context menu isn't hijacked by the native callout).
This commit is contained in:
Erwan Leboucher committed 2026-07-27 08:30:35 +02:00
1 parent 960b4d43fe
commit 249977a8a0
4 files changed
+10 -3

No files matched your search

@@ -10,6 +10,7 @@ import { PopOut, Text, Tooltip, TooltipProvider, toRem } from 'folds';
import { sanitizeCustomHtml } from '$utils/sanitize';
import { highlightText, scaleSystemEmoji } from '$plugins/react-custom-html-parser';
import { useRoomAbbreviationsContext } from '$hooks/useRoomAbbreviations';
import { isMobileOrTablet } from '$utils/platform';
import type { TextSegment } from '$utils/abbreviations';
import { splitByAbbreviations } from '$utils/abbreviations';
import { MessageEmptyContent } from './content';
@@ -91,6 +92,7 @@ function AbbreviationTerm({ text, definition }: AbbreviationTermProps) {
};
const handleClick: MouseEventHandler<HTMLElement> = (e) => {
if (!window.getSelection()?.isCollapsed) return;
e.stopPropagation();
toggleAnchor(e.currentTarget);
};
@@ -140,6 +142,7 @@ function AbbreviationTerm({ text, definition }: AbbreviationTermProps) {
padding: 0,
font: 'inherit',
color: 'inherit',
userSelect: isMobileOrTablet() ? 'none' : 'text',
}}
>
{text}
@@ -379,6 +379,7 @@ export function RoomNavItem({
};
const handleNavItemClick: MouseEventHandler<HTMLElement> = (evt) => {
if (menu.consumeLongPressFired() || menu.anchor) return;
if (room.isCallRoom()) {
if (!livekitSupport(autoDiscoveryInfo) && callMembers.length === 0) return;
if (callEmbed && !isActiveCall) return;
+1
View File
@@ -21,6 +21,7 @@ export const useMentionClickHandler = (roomId: string): ReactEventHandler<HTMLEl
const handleClick: ReactEventHandler<HTMLElement> = useCallback(
(evt) => {
if (!window.getSelection()?.isCollapsed) return;
evt.stopPropagation();
evt.preventDefault();
const target = evt.currentTarget;
+5 -3
View File
@@ -540,10 +540,14 @@ function SpaceTab({
}: Readonly<SpaceTabProps>) {
const isMobile = useScreenSizeContext() === ScreenSize.Mobile;
const targetRef = useRef<HTMLDivElement>(null);
const menu = useMenuAnchor<HTMLButtonElement>();
const mobileTapActivation = useMobileTapActivation(
isMobile,
() => onSelect(space.roomId),
() => onSelect(space.roomId)
() => {
if (menu.consumeLongPressFired() || menu.anchor) return;
onSelect(space.roomId);
}
);
const spaceDraggable: SidebarDraggable = useMemo(
@@ -561,8 +565,6 @@ function SpaceTab({
const dropState = useDropTarget(spaceDraggable, targetRef, !isMobile);
const dropType = dropState?.type;
const menu = useMenuAnchor<HTMLButtonElement>();
return (
<RoomUnreadProvider roomId={space.roomId}>
{(unread) => (