mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-26 02:05:31 +00:00
fix(app): keep the context meter's details open after a tap
Ignoring the focus that follows a touch press applied to every hover card, so on a wide touch screen the context window meter's details opened on the tap and closed again after the close grace. Whether a card ignores touch is now one decision on HoverCard, used for both the touch's pointerenter and the focus after it. The workspace row opts in; the meter keeps opening on a tap. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
d4d692260a
commit
f6dd5fdb1a
@@ -26,6 +26,7 @@ import {
|
||||
reloadAgent,
|
||||
scriptAgentUsage,
|
||||
seedAgentWithContextWindow,
|
||||
tapContextWindowMeter,
|
||||
usageCard,
|
||||
} from "../support/helpers/context-window";
|
||||
import { openAgentRoute, seedMockAgentWorkspace } from "../support/helpers/mock-agent";
|
||||
@@ -509,6 +510,24 @@ test("context details stay open while the chat streams", async ({ page }) => {
|
||||
}
|
||||
});
|
||||
|
||||
test.describe("on a wide touch screen", () => {
|
||||
test.use({ hasTouch: true });
|
||||
|
||||
test("tapping the meter opens context details that stay open", async ({ page, agent }) => {
|
||||
const usage = await scriptAgentUsage(page);
|
||||
await page.setViewportSize(DESKTOP);
|
||||
await openAgent(page, agent);
|
||||
const [claude] = claudeAndCodexReports();
|
||||
// A tap can request the agent's usage more than once.
|
||||
usage.answerNext([onPersonalLogin(claude!)]);
|
||||
usage.answerNext([onPersonalLogin(claude!)]);
|
||||
const details = await tapContextWindowMeter(page);
|
||||
// Past the card's close grace. A touch sends no pointer movement after the tap.
|
||||
await page.waitForTimeout(500);
|
||||
await expect(details).toBeVisible();
|
||||
});
|
||||
});
|
||||
|
||||
test("pointer hovering context details preserves composer focus", async ({ page, agent }) => {
|
||||
const usage = await scriptAgentUsage(page);
|
||||
await page.setViewportSize(DESKTOP);
|
||||
|
||||
@@ -41,6 +41,14 @@ export async function hoverContextWindowMeter(page: Page, name = METER_NAME): Pr
|
||||
return card;
|
||||
}
|
||||
|
||||
/** Taps the meter on a touch screen and returns its details once they are on screen. */
|
||||
export async function tapContextWindowMeter(page: Page, name = METER_NAME): Promise<Locator> {
|
||||
await page.getByRole("img", { name, exact: true }).tap({ timeout: 30_000 });
|
||||
const card = contextWindowDetails(page);
|
||||
await expect(card).toBeVisible();
|
||||
return card;
|
||||
}
|
||||
|
||||
/** Walks the pointer from the meter up onto its hover card, across the gap between them. */
|
||||
export async function moveOntoContextWindowDetails(page: Page, card: Locator): Promise<void> {
|
||||
const meter = await page.getByRole("img", { name: METER_NAME }).boundingBox();
|
||||
|
||||
@@ -42,7 +42,7 @@ interface HoverCardContextValue {
|
||||
setTriggerRef: (node: View | null) => void;
|
||||
triggerRef: RefObject<View | null>;
|
||||
contentRef: RefObject<View | null>;
|
||||
openNow: () => void;
|
||||
pointerEntered: (event: ViewPointerEvent) => void;
|
||||
scheduleClose: () => void;
|
||||
}
|
||||
|
||||
@@ -62,21 +62,34 @@ const HoverCardContext = createContext<HoverCardContextValue | null>(null);
|
||||
*/
|
||||
export function HoverCard({
|
||||
disabled = false,
|
||||
ignoreTouch = false,
|
||||
children,
|
||||
}: {
|
||||
/** Closes the card and keeps it closed, e.g. while its trigger is dragged. */
|
||||
disabled?: boolean;
|
||||
/**
|
||||
* The trigger handles a tap itself, so a touch does not open the card: neither the touch's
|
||||
* pointerenter nor the focus the tap leaves on the trigger. Opening during a tap changes the
|
||||
* page under the finger, and iPad Safari then drops the tap.
|
||||
*/
|
||||
ignoreTouch?: boolean;
|
||||
children: ReactNode;
|
||||
}): ReactNode {
|
||||
if (!isWeb) return children;
|
||||
return <WebHoverCard disabled={disabled}>{children}</WebHoverCard>;
|
||||
return (
|
||||
<WebHoverCard disabled={disabled} ignoreTouch={ignoreTouch}>
|
||||
{children}
|
||||
</WebHoverCard>
|
||||
);
|
||||
}
|
||||
|
||||
function WebHoverCard({
|
||||
disabled,
|
||||
ignoreTouch,
|
||||
children,
|
||||
}: {
|
||||
disabled: boolean;
|
||||
ignoreTouch: boolean;
|
||||
children: ReactNode;
|
||||
}): ReactElement {
|
||||
const layer = useOverlayLayer("floating");
|
||||
@@ -86,7 +99,7 @@ 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.
|
||||
// Whether the latest press was a touch, so with ignoreTouch the focus that tap leaves is ignored.
|
||||
const touchPressedRef = useRef(false);
|
||||
|
||||
const clearGraceTimer = useCallback(() => {
|
||||
@@ -134,6 +147,13 @@ function WebHoverCard({
|
||||
setOpen(true);
|
||||
}, [clearGraceTimer, closeNow, disabled, layer]);
|
||||
|
||||
const pointerEntered = useCallback(
|
||||
(event: ViewPointerEvent) => {
|
||||
if (!(ignoreTouch && event.nativeEvent.pointerType === "touch")) openNow();
|
||||
},
|
||||
[ignoreTouch, openNow],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
return () => {
|
||||
@@ -200,8 +220,7 @@ function WebHoverCard({
|
||||
const target = event.target as Element;
|
||||
keyboardFocusedRef.current = target.matches(":focus-visible");
|
||||
if (trigger.contains(target)) {
|
||||
// A tap focuses the trigger too. A touch is not a hover, so that focus does not open it.
|
||||
if (!touchPressedRef.current) openNow();
|
||||
if (!(ignoreTouch && touchPressedRef.current)) openNow();
|
||||
} else if ((contentRef.current as unknown as HTMLElement | null)?.contains(target)) {
|
||||
clearGraceTimer();
|
||||
}
|
||||
@@ -253,7 +272,7 @@ function WebHoverCard({
|
||||
document.removeEventListener("scroll", scrolled, true);
|
||||
window.removeEventListener("resize", close);
|
||||
};
|
||||
}, [clearGraceTimer, keyPressed, open, openNow, scheduleClose]);
|
||||
}, [clearGraceTimer, ignoreTouch, keyPressed, open, openNow, scheduleClose]);
|
||||
|
||||
// While open, the safe zone covers trigger + content + the bridge between
|
||||
// them. Close only fires when the pointer leaves the safe zone; re-entering
|
||||
@@ -276,8 +295,16 @@ function WebHoverCard({
|
||||
useEffect(() => clearGraceTimer, [clearGraceTimer]);
|
||||
|
||||
const value = useMemo<HoverCardContextValue>(
|
||||
() => ({ open, layer, setTriggerRef, triggerRef, contentRef, openNow, scheduleClose }),
|
||||
[open, layer, setTriggerRef, openNow, scheduleClose],
|
||||
() => ({
|
||||
open,
|
||||
layer,
|
||||
setTriggerRef,
|
||||
triggerRef,
|
||||
contentRef,
|
||||
pointerEntered,
|
||||
scheduleClose,
|
||||
}),
|
||||
[open, layer, setTriggerRef, pointerEntered, scheduleClose],
|
||||
);
|
||||
|
||||
return (
|
||||
@@ -295,26 +322,13 @@ export function useHoverCardOpen(): boolean {
|
||||
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: ViewPointerEvent) => {
|
||||
if (!(ignoreTouch && event.nativeEvent.pointerType === "touch")) openNow?.();
|
||||
},
|
||||
[ignoreTouch, openNow],
|
||||
);
|
||||
if (!ctx) return children;
|
||||
return (
|
||||
<View
|
||||
@@ -323,7 +337,7 @@ export function HoverCardTrigger({
|
||||
accessibilityRole={focusable ? "button" : undefined}
|
||||
accessibilityLabel={accessibilityLabel}
|
||||
collapsable={false}
|
||||
onPointerEnter={pointerEntered}
|
||||
onPointerEnter={ctx.pointerEntered}
|
||||
onPointerLeave={ctx.scheduleClose}
|
||||
>
|
||||
{children}
|
||||
|
||||
@@ -64,8 +64,8 @@ export function WorkspaceHoverCard({
|
||||
}
|
||||
|
||||
return (
|
||||
<HoverCard disabled={isDragging || disabled}>
|
||||
<HoverCardTrigger ignoreTouch>{children}</HoverCardTrigger>
|
||||
<HoverCard disabled={isDragging || disabled} ignoreTouch>
|
||||
<HoverCardTrigger>{children}</HoverCardTrigger>
|
||||
<HoverCardContent
|
||||
placement="right"
|
||||
role="menu"
|
||||
|
||||
Reference in New Issue
Block a user