fix(app): a tap on a touch screen opens a workspace row instead of its hover card

On a wide touch screen the workspace hover card opened on the tap's
pointerenter and on the focus the tap left behind. On iPad Safari that
changed the page under the finger, so the tap showed the card and never
opened the workspace. The workspace row's trigger now ignores touch, and
focus that follows a touch press no longer opens a hover card. Mouse hover
and keyboard focus open cards as before. Other triggers, such as the
context meter, which has no press of its own on wide screens, keep opening
on a touch's pointerenter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zen
2026-11-25 06:41:15 +00:00
committed by paseo-bot[bot]
co-authored by Claude Opus 5.5
parent 1ff119dc2a
commit d741af03cd
3 changed files with 58 additions and 3 deletions
@@ -544,6 +544,26 @@ test.describe("Sidebar workspace list", () => {
});
});
// On a wide touch screen (iPad) a tap is not a hover. Opening the card on the tap changes the page
// under the finger, and iPad Safari then drops the tap instead of opening the workspace.
test.describe("Sidebar workspace rows on a touch screen", () => {
test.use({ hasTouch: true, viewport: { width: 1180, height: 820 } });
test("tapping a workspace row opens it without the hover card", async ({ page }) => {
const workspace = await seedWorkspace({ repoPrefix: "sidebar-touch-tap-" });
try {
await gotoAppShell(page);
await waitForSidebarProject(page, path.basename(workspace.repoPath));
const row = await waitForSidebarWorkspace(page, workspace.workspaceId);
await row.tap();
await expect(page).toHaveURL(/\/workspace\//, { timeout: 30_000 });
await expectWorkspaceHoverCardClosed(page);
} finally {
await workspace.cleanup();
}
});
});
test.describe("Mobile sidebar panelState transition", () => {
test.use({ viewport: { width: 390, height: 844 } });
+37 -2
View File
@@ -79,6 +79,8 @@ function WebHoverCard({
const graceTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
// Read when focus arrives: by focusout the element losing focus no longer matches :focus-visible.
const keyboardFocusedRef = useRef(false);
// Whether the latest press was a touch, so the focus that tap leaves on the trigger is ignored.
const touchPressedRef = useRef(false);
const clearGraceTimer = useCallback(() => {
if (graceTimerRef.current) {
@@ -191,7 +193,8 @@ function WebHoverCard({
const target = event.target as Element;
keyboardFocusedRef.current = target.matches(":focus-visible");
if (trigger.contains(target)) {
openNow();
// A tap focuses the trigger too. A touch is not a hover, so that focus does not open it.
if (!touchPressedRef.current) openNow();
} else if ((contentRef.current as unknown as HTMLElement | null)?.contains(target)) {
clearGraceTimer();
}
@@ -208,6 +211,12 @@ function WebHoverCard({
scheduleClose();
}
};
const pointerPressed = (event: PointerEvent) => {
touchPressedRef.current = event.pointerType === "touch";
};
const keyPressedAnywhere = () => {
touchPressedRef.current = false;
};
const activateClosedTrigger = (event: KeyboardEvent) => {
if (
!open &&
@@ -221,12 +230,16 @@ function WebHoverCard({
const scrolled = (event: Event) => {
if ((event.target as Node).contains(trigger)) close();
};
document.addEventListener("pointerdown", pointerPressed, true);
document.addEventListener("keydown", keyPressedAnywhere, true);
document.addEventListener("focusin", focusEntered);
document.addEventListener("focusout", focusLeft);
trigger.addEventListener("keydown", activateClosedTrigger);
document.addEventListener("scroll", scrolled, true);
window.addEventListener("resize", close);
return () => {
document.removeEventListener("pointerdown", pointerPressed, true);
document.removeEventListener("keydown", keyPressedAnywhere, true);
document.removeEventListener("focusin", focusEntered);
document.removeEventListener("focusout", focusLeft);
trigger.removeEventListener("keydown", activateClosedTrigger);
@@ -272,16 +285,38 @@ export function useHoverCardOpen(): boolean {
return useContext(HoverCardContext)?.open ?? false;
}
interface PointerLikeEvent {
nativeEvent?: { pointerType?: string };
pointerType?: string;
}
function isTouch(event: PointerLikeEvent): boolean {
return (event.nativeEvent?.pointerType ?? event.pointerType) === "touch";
}
export function HoverCardTrigger({
children,
focusable = false,
ignoreTouch = false,
accessibilityLabel,
}: {
children: ReactNode;
focusable?: boolean;
/**
* The trigger handles a tap itself, so a touch must not open the card. Opening on a touch's
* pointerenter changes the page under the finger, and iPad Safari then drops the tap.
*/
ignoreTouch?: boolean;
accessibilityLabel?: string;
}): ReactNode {
const ctx = useContext(HoverCardContext);
const openNow = ctx?.openNow;
const pointerEntered = useCallback(
(event: PointerLikeEvent) => {
if (!(ignoreTouch && isTouch(event))) openNow?.();
},
[ignoreTouch, openNow],
);
if (!ctx) return children;
return (
<View
@@ -290,7 +325,7 @@ export function HoverCardTrigger({
accessibilityRole={focusable ? "button" : undefined}
accessibilityLabel={accessibilityLabel}
collapsable={false}
onPointerEnter={ctx.openNow}
onPointerEnter={pointerEntered}
onPointerLeave={ctx.scheduleClose}
>
{children}
@@ -65,7 +65,7 @@ export function WorkspaceHoverCard({
return (
<HoverCard disabled={isDragging || disabled}>
<HoverCardTrigger>{children}</HoverCardTrigger>
<HoverCardTrigger ignoreTouch>{children}</HoverCardTrigger>
<HoverCardContent
placement="right"
role="menu"