Skip to content

Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.

feat(prompts): show a tracked prompt's full text on hover when the table cuts it (#1112)

Cihan86c7f95fefba
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx
index 619e81c21..6a54746c8 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx
@@ -175,6 +175,11 @@ import { BulkActionBar } from './_bulk-action-bar';
import { formatCompactNumber, formatNumber } from '@/lib/format';
import { usePagination, TablePager } from '@/components/table-pager';
import { PromptPositionsSheet } from '@/components/prompts/prompt-positions-sheet';
+import {
+ ClampedText,
+ ClampedTextTooltip,
+ createClampedTextHandle,
+} from '@/components/prompts/clamped-text';
import {
panelRangeFromTable,
parsePositionsRange,
@@ -2610,6 +2615,8 @@ function AllPromptsTab({
onChanged: () => void;
}) {
const tCommon = useTranslations('common');
+ // One tooltip for every prompt and topic the table cuts short.
+ const fullText = useMemo(() => createClampedTextHandle(), []);
const tUsage = useTranslations('prompts.usage');
const format = useFormatter();
const tDelete = useTranslations('prompts.bulkDelete');
@@ -3463,18 +3470,32 @@ function AllPromptsTab({
aria-label={`Select ${p.text}`}
/>
)}
- <Link
- href={`/dashboard/prompts/${p.id}`}
- className="line-clamp-2 transition-colors hover:text-primary hover:underline"
- >
- {p.text}
- </Link>
+ <ClampedText
+ handle={fullText}
+ text={p.text}
+ render={
+ <Link
+ href={`/dashboard/prompts/${p.id}`}
+ className="line-clamp-2 transition-colors hover:text-primary hover:underline"
+ />
+ }
+ />
</div>
</TableCell>
<TableCell>
- <span className="text-xs text-muted-foreground truncate inline-block max-w-[140px] align-middle">
- {p.category?.trim() ? p.category : '—'}
- </span>
+ {p.category?.trim() ? (
+ <ClampedText
+ handle={fullText}
+ text={p.category}
+ render={
+ <span className="text-xs text-muted-foreground truncate inline-block max-w-[140px] align-middle" />
+ }
+ />
+ ) : (
+ <span className="text-xs text-muted-foreground inline-block align-middle">
+ —
+ </span>
+ )}
</TableCell>
<TableCell className="text-center">
<Badge
@@ -3629,6 +3650,7 @@ function AllPromptsTab({
})}
</TableBody>
</Table>
+ <ClampedTextTooltip handle={fullText} />
<TablePager
page={promptsPager.page}
totalPages={promptsPager.totalPages}
diff --git a/web/src/components/prompts/clamped-text.test.tsx b/web/src/components/prompts/clamped-text.test.tsx
new file mode 100644
index 000000000..494befed2
--- /dev/null
+++ b/web/src/components/prompts/clamped-text.test.tsx
@@ -0,0 +1,115 @@
+import { act } from 'react';
+import { createRoot, type Root } from 'react-dom/client';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import {
+ ClampedText,
+ ClampedTextTooltip,
+ createClampedTextHandle,
+ isTextCut,
+} from './clamped-text';
+
+(
+ globalThis as typeof globalThis & {
+ IS_REACT_ACT_ENVIRONMENT: boolean;
+ }
+).IS_REACT_ACT_ENVIRONMENT = true;
+
+describe('isTextCut', () => {
+ const box = (scroll: [number, number], client: [number, number]) => ({
+ scrollWidth: scroll[0],
+ scrollHeight: scroll[1],
+ clientWidth: client[0],
+ clientHeight: client[1],
+ });
+
+ it('reads a clamped block or a truncated line as cut', () => {
+ expect(isTextCut(box([320, 60], [320, 40]))).toBe(true);
+ expect(isTextCut(box([210, 16], [140, 16]))).toBe(true);
+ });
+
+ it('leaves text that fits, within a pixel of rounding', () => {
+ expect(isTextCut(box([320, 40], [320, 40]))).toBe(false);
+ expect(isTextCut(box([141, 17], [140, 16]))).toBe(false);
+ });
+});
+
+describe('ClampedText', () => {
+ let container: HTMLDivElement;
+ let root: Root;
+ const text = 'Which specialty coffee subscriptions ship internationally to Europe?';
+
+ beforeEach(() => {
+ vi.useFakeTimers();
+ container = document.createElement('div');
+ document.body.appendChild(container);
+ root = createRoot(container);
+ });
+
+ afterEach(() => {
+ act(() => root.unmount());
+ container.remove();
+ vi.useRealTimers();
+ });
+
+ function hover(sizes: { scrollHeight: number; clientHeight: number }) {
+ const handle = createClampedTextHandle();
+ act(() => {
+ root.render(
+ <>
+ <ClampedText handle={handle} text={text} render={<span data-testid="cell" />} />
+ <ClampedTextTooltip handle={handle} />
+ </>,
+ );
+ });
+ const cell = container.querySelector('[data-testid="cell"]') as HTMLElement;
+ for (const [key, value] of Object.entries({ ...sizes, scrollWidth: 300, clientWidth: 300 })) {
+ Object.defineProperty(cell, key, { configurable: true, value });
+ }
+ // jsdom has no PointerEvent; React and the tooltip read the event type.
+ act(() => {
+ for (const type of ['pointerover', 'pointerenter', 'mouseover', 'mouseenter', 'mousemove']) {
+ cell.dispatchEvent(new MouseEvent(type, { bubbles: !type.endsWith('enter') }));
+ }
+ });
+ act(() => vi.advanceTimersByTime(400));
+ return cell;
+ }
+
+ it('keeps the whole text in the element', () => {
+ const cell = hover({ scrollHeight: 40, clientHeight: 40 });
+ expect(cell.textContent).toBe(text);
+ });
+
+ it('shows the whole text on hover when the element cut it', () => {
+ hover({ scrollHeight: 60, clientHeight: 40 });
+ const popup = document.querySelector('[data-slot="tooltip-content"]');
+ expect(popup?.textContent).toBe(text);
+ });
+
+ it('shows the whole text when a cut link gets keyboard focus', () => {
+ const handle = createClampedTextHandle();
+ act(() => {
+ root.render(
+ <>
+ <ClampedText
+ handle={handle}
+ text={text}
+ render={<a href="#prompt" data-testid="cell" />}
+ />
+ <ClampedTextTooltip handle={handle} />
+ </>,
+ );
+ });
+ const cell = container.querySelector('[data-testid="cell"]') as HTMLElement;
+ Object.defineProperty(cell, 'scrollWidth', { configurable: true, value: 420 });
+ Object.defineProperty(cell, 'clientWidth', { configurable: true, value: 320 });
+ act(() => cell.focus());
+ act(() => vi.advanceTimersByTime(400));
+ expect(document.querySelector('[data-slot="tooltip-content"]')?.textContent).toBe(text);
+ });
+
+ it('shows nothing for text that fits', () => {
+ hover({ scrollHeight: 40, clientHeight: 40 });
+ expect(document.querySelector('[data-slot="tooltip-content"]')).toBeNull();
+ });
+});
diff --git a/web/src/components/prompts/clamped-text.tsx b/web/src/components/prompts/clamped-text.tsx
new file mode 100644
index 000000000..2ebbeb581
--- /dev/null
+++ b/web/src/components/prompts/clamped-text.tsx
@@ -0,0 +1,78 @@
+'use client';
+
+import { useState, type ReactElement } from 'react';
+import {
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger,
+ createTooltipHandle,
+} from '@/components/ui/tooltip';
+
+/** One tooltip shared by every cut text in a table (see ClampedText). */
+export type ClampedTextHandle = ReturnType<typeof createTooltipHandle<string | null>>;
+
+export function createClampedTextHandle(): ClampedTextHandle {
+ return createTooltipHandle<string | null>();
+}
+
+/** Whether CSS cut the element's text short (line-clamp, truncate). */
+export function isTextCut(el: {
+ scrollHeight: number;
+ clientHeight: number;
+ scrollWidth: number;
+ clientWidth: number;
+}): boolean {
+ // A pixel of slack: subpixel layout can leave scroll a hair over client.
+ return el.scrollHeight > el.clientHeight + 1 || el.scrollWidth > el.clientWidth + 1;
+}
+
+/**
+ * Text that CSS cuts short and shows in full on hover, only when it was cut:
+ * a short text has nothing more to show. Every row shares one tooltip through
+ * `handle`, so a long table doesn't mount one per cell; render
+ * ClampedTextTooltip once beside them. The whole text stays in the element,
+ * so screen readers read it in full either way.
+ */
+export function ClampedText({
+ handle,
+ text,
+ render,
+}: {
+ handle: ClampedTextHandle;
+ text: string;
+ /** The element that cuts the text, e.g. a link with `line-clamp-2`. */
+ render: ReactElement;
+}) {
+ const [cut, setCut] = useState(false);
+ return (
+ <TooltipTrigger
+ handle={handle}
+ payload={cut ? text : null}
+ delay={300}
+ closeDelay={0}
+ render={render}
+ // Measured as the tooltip is about to open, by pointer or keyboard focus.
+ onPointerEnter={(e) => setCut(isTextCut(e.currentTarget))}
+ onFocus={(e) => setCut(isTextCut(e.currentTarget))}
+ >
+ {text}
+ </TooltipTrigger>
+ );
+}
+
+/**
+ * The shared tooltip. It opens over the neighbouring row, so it lets the
+ * pointer through and closes as soon as the pointer leaves the text: moving
+ * to the next row must reach that row, not stay on this tooltip.
+ */
+export function ClampedTextTooltip({ handle }: { handle: ClampedTextHandle }) {
+ return (
+ <Tooltip handle={handle} disableHoverablePopup>
+ {({ payload }) =>
+ payload ? (
+ <TooltipContent className="pointer-events-none max-w-sm">{payload}</TooltipContent>
+ ) : null
+ }
+ </Tooltip>
+ );
+}