Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix(live-views): open list tooltip on hover

Louis Beaumont3240a88b1350
diff --git a/apps/screenpipe-app-tauri/components/settings/__tests__/live-view-card.test.tsx b/apps/screenpipe-app-tauri/components/settings/__tests__/live-view-card.test.tsx
index 2a5521ba2..b69091fd9 100644
--- a/apps/screenpipe-app-tauri/components/settings/__tests__/live-view-card.test.tsx
+++ b/apps/screenpipe-app-tauri/components/settings/__tests__/live-view-card.test.tsx
@@ -54,6 +54,7 @@ class ResizeObserverMock {
beforeEach(() => {
vi.stubGlobal("ResizeObserver", ResizeObserverMock);
+ vi.stubGlobal("PointerEvent", MouseEvent);
vi.spyOn(HTMLElement.prototype, "clientWidth", "get").mockReturnValue(160);
vi.spyOn(HTMLElement.prototype, "scrollWidth", "get").mockImplementation(
function (this: HTMLElement) {
@@ -62,6 +63,17 @@ beforeEach(() => {
: 160;
},
);
+ vi.spyOn(HTMLElement.prototype, "getBoundingClientRect").mockReturnValue({
+ x: 0,
+ y: 0,
+ width: 160,
+ height: 40,
+ top: 0,
+ right: 160,
+ bottom: 40,
+ left: 0,
+ toJSON: () => ({}),
+ });
});
afterEach(() => {
@@ -77,10 +89,19 @@ describe("LiveViewCard list overflow", () => {
expect(longText).not.toBeNull();
await waitFor(() => expect(longText?.getAttribute("tabindex")).toBe("0"));
- fireEvent.pointerMove(longText as HTMLElement, { pointerType: "mouse" });
+ fireEvent.pointerEnter(longText as HTMLElement, { pointerType: "mouse" });
const tooltip = await screen.findByRole("tooltip");
expect(within(tooltip).getByText(longTitle)).toBeTruthy();
expect(within(tooltip).getByText(longSubtitle)).toBeTruthy();
+
+ fireEvent.pointerLeave(longText as HTMLElement, {
+ pointerType: "mouse",
+ clientX: 200,
+ clientY: 20,
+ });
+ await waitFor(() => {
+ expect(screen.queryByRole("tooltip")).toBeNull();
+ });
});
it("adds keyboard focus only when a row is truncated", async () => {
@@ -98,5 +119,10 @@ describe("LiveViewCard list overflow", () => {
const tooltip = await screen.findByRole("tooltip");
expect(within(tooltip).getByText(longTitle)).toBeTruthy();
expect(within(tooltip).getByText(longSubtitle)).toBeTruthy();
+
+ fireEvent.blur(longText as HTMLElement);
+ await waitFor(() => {
+ expect(screen.queryByRole("tooltip")).toBeNull();
+ });
});
});
diff --git a/apps/screenpipe-app-tauri/components/settings/live-view-card.tsx b/apps/screenpipe-app-tauri/components/settings/live-view-card.tsx
index 582c907a6..3e1bf1537 100644
--- a/apps/screenpipe-app-tauri/components/settings/live-view-card.tsx
+++ b/apps/screenpipe-app-tauri/components/settings/live-view-card.tsx
@@ -87,15 +87,20 @@ function LiveViewListItemText({
const [isTruncated, setIsTruncated] = useState(false);
const [tooltipOpen, setTooltipOpen] = useState(false);
- const measureTruncation = useCallback(() => {
+ const measureTruncation = useCallback((): boolean => {
const truncated = [titleRef.current, subtitleRef.current].some(
(element) =>
element !== null && element.scrollWidth > element.clientWidth,
);
setIsTruncated(truncated);
if (!truncated) setTooltipOpen(false);
+ return truncated;
}, []);
+ const openTooltipIfTruncated = useCallback(() => {
+ setTooltipOpen(measureTruncation());
+ }, [measureTruncation]);
+
useLayoutEffect(() => {
measureTruncation();
if (typeof ResizeObserver === "undefined") return;
@@ -109,14 +114,20 @@ function LiveViewListItemText({
return (
<Tooltip
open={isTruncated && tooltipOpen}
- onOpenChange={setTooltipOpen}
+ onOpenChange={(open) => {
+ // Pointer entry and keyboard focus open the controlled tooltip below.
+ // Still honor Radix close requests such as Escape.
+ if (!open) setTooltipOpen(false);
+ }}
>
<TooltipTrigger asChild>
<div
className="min-w-0 flex-1 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-foreground focus-visible:ring-offset-1"
tabIndex={isTruncated ? 0 : undefined}
- onPointerEnter={measureTruncation}
- onFocus={measureTruncation}
+ onPointerEnter={openTooltipIfTruncated}
+ onPointerLeave={() => setTooltipOpen(false)}
+ onFocus={openTooltipIfTruncated}
+ onBlur={() => setTooltipOpen(false)}
>
<p ref={titleRef} className="truncate text-sm">
{title}