diff --git a/src/app/features/room-nav/RoomNavItem.tsx b/src/app/features/room-nav/RoomNavItem.tsx index 9b0c089ba..733c81c06 100644 --- a/src/app/features/room-nav/RoomNavItem.tsx +++ b/src/app/features/room-nav/RoomNavItem.tsx @@ -351,7 +351,13 @@ export function RoomNavItem({ const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false); - const { onTouchStart, onTouchEnd, onTouchMove, firedRef: longPressFiredRef } = useMobileLongPress(() => { + const { + onTouchStart, + onTouchEnd, + onTouchMove, + firedRef: longPressFiredRef, + isPressing, + } = useMobileLongPress(() => { setIsMobileMenuOpen(true); }); @@ -458,7 +464,7 @@ export function RoomNavItem({ radii="400" highlight={shouldShowUnreadIndicator} aria-selected={selected} - data-hover={!!menuAnchor} + data-hover={!!menuAnchor || isPressing || isMobileMenuOpen} onContextMenu={handleContextMenu} {...hoverProps} {...focusWithinProps} diff --git a/src/app/features/room/message/Message.tsx b/src/app/features/room/message/Message.tsx index e93c93611..fb3291541 100644 --- a/src/app/features/room/message/Message.tsx +++ b/src/app/features/room/message/Message.tsx @@ -838,6 +838,7 @@ function MessageInternal( onTouchEnd, onTouchMove, firedRef: longPressFiredRef, + isPressing, } = useMobileLongPress(() => { if (!edit) openMobileOptions(); }); @@ -898,7 +899,7 @@ function MessageInternal( collapse={collapse} highlight={highlight} notifyHighlight={highlightMentions ? notifyHighlight : undefined} - selected={!!menuAnchor || isEmoji} + selected={!!menuAnchor || isEmoji || isPressing} isMarked={isMarked} mobile={mobileOrTablet()} {...props} diff --git a/src/app/hooks/useMobileLongPress.ts b/src/app/hooks/useMobileLongPress.ts index c1839154f..484820244 100644 --- a/src/app/hooks/useMobileLongPress.ts +++ b/src/app/hooks/useMobileLongPress.ts @@ -1,22 +1,26 @@ -import { useRef, useCallback } from 'react'; +import { useRef, useCallback, useState } from 'react'; import { mobileOrTablet } from '$utils/user-agent'; export function useMobileLongPress(callback: () => void, delay = 500) { const timerRef = useRef | null>(null); const firedRef = useRef(false); + const [isPressing, setIsPressing] = useState(false); const clear = useCallback(() => { if (timerRef.current !== null) { clearTimeout(timerRef.current); timerRef.current = null; } + setIsPressing(false); }, []); const onTouchStart = useCallback(() => { if (!mobileOrTablet()) return; firedRef.current = false; + setIsPressing(true); timerRef.current = setTimeout(() => { firedRef.current = true; + setIsPressing(false); callback(); }, delay); }, [callback, delay]); @@ -29,5 +33,5 @@ export function useMobileLongPress(callback: () => void, delay = 500) { clear(); }, [clear]); - return { onTouchStart, onTouchEnd, onTouchMove, firedRef }; + return { onTouchStart, onTouchEnd, onTouchMove, firedRef, isPressing }; }