Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(web): Clarify disabled syntax highlighting for large values (#18604)

Ben Bachem3afa8cb47390
diff --git a/web/src/components/design-system/Codeblock/Codeblock.stories.tsx b/web/src/components/design-system/Codeblock/Codeblock.stories.tsx
index 64111dbc64..e028f17537 100644
--- a/web/src/components/design-system/Codeblock/Codeblock.stories.tsx
+++ b/web/src/components/design-system/Codeblock/Codeblock.stories.tsx
@@ -1,5 +1,5 @@
import preview from "../../../../.storybook/preview";
-import { expect, spyOn, userEvent, within } from "storybook/test";
+import { expect, spyOn, userEvent, waitFor, within } from "storybook/test";
import { themes } from "prism-react-renderer";
import { Codeblock as CodeBlock } from "./Codeblock";
@@ -137,6 +137,35 @@ export const LargeJson = meta.story({
play: async ({ args, canvasElement }) => {
const canvas = within(canvasElement);
const source = String(args.value);
+ await expect(
+ canvas.getByRole("combobox", { name: "Example language" }),
+ ).toHaveTextContent("Auto (JSON)");
+ const highlightingIndicator = canvas.getByLabelText(
+ /syntax highlighting is disabled/i,
+ );
+ await expect(highlightingIndicator).toBeVisible();
+ await expect(
+ canvas.getByRole("button", { name: "Syntax highlighting disabled" }),
+ ).toBeDisabled();
+ await userEvent.hover(highlightingIndicator);
+ await waitFor(async () => {
+ await expect(within(document.body).getByRole("tooltip")).toBeVisible();
+ });
+ await userEvent.unhover(highlightingIndicator);
+ await waitFor(async () => {
+ await expect(
+ within(document.body).queryByRole("tooltip"),
+ ).not.toBeInTheDocument();
+ });
+ await userEvent.click(
+ canvas.getByRole("combobox", { name: "Example language" }),
+ );
+ await userEvent.keyboard("{Escape}");
+ await userEvent.tab();
+ await expect(highlightingIndicator).toHaveFocus();
+ await waitFor(async () => {
+ await expect(within(document.body).getByRole("tooltip")).toBeVisible();
+ });
await expect(
canvas.getByRole("button", { name: "Pretty-print JSON" }),
).toHaveAttribute("aria-pressed", "true");
diff --git a/web/src/components/design-system/Codeblock/Codeblock.tsx b/web/src/components/design-system/Codeblock/Codeblock.tsx
index d0a2f0be4b..c6671fa849 100644
--- a/web/src/components/design-system/Codeblock/Codeblock.tsx
+++ b/web/src/components/design-system/Codeblock/Codeblock.tsx
@@ -1,5 +1,5 @@
import { memo, useMemo, useState } from "react";
-import { Check, Copy, ListTree } from "lucide-react";
+import { Check, Copy, Highlighter, ListTree } from "lucide-react";
import hljs from "highlight.js/lib/core";
import json from "highlight.js/lib/languages/json";
import javascript from "highlight.js/lib/languages/javascript";
@@ -238,12 +238,24 @@ export const Codeblock = memo(function Codeblock({
</SelectDropdown>
) : null}
{isLargePreview || displayText.length > MAX_HIGHLIGHT_CHARACTERS ? (
- <span
- className="text-muted-foreground text-xs"
- title="Syntax highlighting is disabled for previews over 10,000 characters."
- >
- Plain text (large value)
- </span>
+ <Tooltip label="Syntax highlighting is disabled for values over 10,000 characters.">
+ {({ getTriggerProps }) => (
+ <span
+ {...getTriggerProps()}
+ aria-label="Syntax highlighting is disabled for values over 10,000 characters."
+ tabIndex={0}
+ className="focus-visible:ring-ring inline-flex rounded-sm focus-visible:ring-2 focus-visible:outline-hidden"
+ >
+ <IconButton
+ icon={Highlighter}
+ label="Syntax highlighting disabled"
+ size="sm"
+ variant="toolbar"
+ disabled
+ />
+ </span>
+ )}
+ </Tooltip>
) : null}
{prettyPrintedText !== null ? (
<Tooltip label="Pretty-print JSON">