Skip to content

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

fix(web): name four dialog surfaces for screen readers (#18363)

Der Geräta52268afb356
diff --git a/web/src/__tests__/dialog-accessible-names.clienttest.tsx b/web/src/__tests__/dialog-accessible-names.clienttest.tsx
new file mode 100644
index 0000000000..a6446b0250
--- /dev/null
+++ b/web/src/__tests__/dialog-accessible-names.clienttest.tsx
@@ -0,0 +1,107 @@
+/**
+ * Radix names a dialog from a Title *element* in the DOM — it looks the id up
+ * with `document.getElementById(titleId)` — and logs a `console.error` when
+ * there is none. `TitleWarning` has no `NODE_ENV` guard, so that error ships to
+ * production as well as dev.
+ *
+ * The surfaces below show no visible heading, so each carries an `sr-only`
+ * title instead of omitting one. Both halves are asserted on purpose: an
+ * `aria-label` would give the dialog an accessible name while leaving the
+ * warning (and Radix's own title contract) unsatisfied, so a name check alone
+ * would not have caught the original bug.
+ */
+import { cleanup, fireEvent, render, screen } from "@testing-library/react";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+
+import {
+ Sidebar,
+ SidebarProvider,
+ SidebarTrigger,
+} from "@/src/components/ui/sidebar";
+import { LayerProvider } from "@/src/context/LayerContext/LayerContext";
+import { V4IntroDialog } from "@/src/features/events/components/V4IntroDialog";
+
+vi.mock("next/router", () => ({
+ useRouter: () => ({ events: { on: vi.fn(), off: vi.fn() } }),
+}));
+
+const TITLE_WARNING = /requires a `?DialogTitle`?/;
+
+let consoleErrors: string[] = [];
+
+beforeEach(() => {
+ consoleErrors = [];
+ vi.spyOn(console, "error").mockImplementation((...args: unknown[]) => {
+ consoleErrors.push(args.map(String).join(" "));
+ });
+});
+
+afterEach(() => {
+ cleanup();
+ vi.unstubAllGlobals();
+ vi.restoreAllMocks();
+});
+
+function titleWarnings() {
+ return consoleErrors.filter((message) => TITLE_WARNING.test(message));
+}
+
+describe("V4IntroDialog", () => {
+ it("names the dialog even though the design shows no heading", () => {
+ render(<V4IntroDialog open onConfirm={vi.fn()} onDismiss={vi.fn()} />, {
+ wrapper: LayerProvider,
+ });
+
+ expect(
+ screen.getByRole("dialog", { name: "Welcome to a faster Langfuse" }),
+ ).toBeInTheDocument();
+ expect(titleWarnings()).toEqual([]);
+ });
+
+ it("keeps the floating close button suppressed", () => {
+ render(<V4IntroDialog open onConfirm={vi.fn()} onDismiss={vi.fn()} />, {
+ wrapper: LayerProvider,
+ });
+
+ // The dialog is dismissed through its footer action. The title is an `h2`,
+ // so `[&>div:last-child]:hidden` still resolves to the close wrapper.
+ const dialog = screen.getByRole("dialog");
+ // DialogContent carries the suppressing class from V4IntroDialog — this
+ // is the discriminating assertion: `DialogContent` itself also adds
+ // `[&:has(.dialog-header)]:hidden` to the close-wrapper element, so
+ // checking the wrapper's own className would pass even without the fix.
+ expect(dialog.className).toContain("[&>div:last-child]:hidden");
+ // The close wrapper is still the last child (the selector still resolves).
+ const closeWrapper = dialog.querySelector(":scope > div:last-child");
+ expect(closeWrapper?.querySelector("button")).not.toBeNull();
+ });
+});
+
+describe("mobile sidebar sheet", () => {
+ beforeEach(() => {
+ // `useIsMobile` reads `matchMedia` synchronously; jsdom does not ship it.
+ vi.stubGlobal("matchMedia", (media: string) => ({
+ matches: true,
+ media,
+ addEventListener: vi.fn(),
+ removeEventListener: vi.fn(),
+ }));
+ });
+
+ it("names the off-canvas navigation sheet", () => {
+ render(
+ <SidebarProvider>
+ <Sidebar>
+ <span>Projects</span>
+ </Sidebar>
+ <SidebarTrigger />
+ </SidebarProvider>,
+ { wrapper: LayerProvider },
+ );
+
+ fireEvent.click(screen.getByRole("button", { name: "Toggle Sidebar" }));
+
+ expect(screen.getByRole("dialog", { name: "Sidebar" })).toBeInTheDocument();
+ expect(titleWarnings()).toEqual([]);
+ });
+});
diff --git a/web/src/components/ui/sidebar.tsx b/web/src/components/ui/sidebar.tsx
index 94d4e3b2c4..a88bc14bcd 100644
--- a/web/src/components/ui/sidebar.tsx
+++ b/web/src/components/ui/sidebar.tsx
@@ -12,7 +12,7 @@ import { cn } from "@/src/utils/tailwind";
import { Button } from "@/src/components/ui/button";
import { Input } from "@/src/components/ui/input";
import { Separator } from "@/src/components/ui/separator";
-import { Sheet, SheetContent } from "@/src/components/ui/sheet";
+import { Sheet, SheetContent, SheetTitle } from "@/src/components/ui/sheet";
import { Skeleton } from "@/src/components/ui/skeleton";
import {
Tooltip,
@@ -235,6 +235,7 @@ const Sidebar = React.forwardRef<
}
side={side}
>
+ <SheetTitle className="sr-only">Sidebar</SheetTitle>
<div className="flex h-full w-full flex-col">{children}</div>
</SheetContent>
</Sheet>
diff --git a/web/src/features/evals/components/default-eval-model-setup.tsx b/web/src/features/evals/components/default-eval-model-setup.tsx
index 29fccc6373..a86929837c 100644
--- a/web/src/features/evals/components/default-eval-model-setup.tsx
+++ b/web/src/features/evals/components/default-eval-model-setup.tsx
@@ -13,6 +13,7 @@ import { ManageDefaultEvalModel } from "@/src/features/evals/components/manage-d
import { useState } from "react";
import {
DialogContent,
+ DialogTitle,
DialogTrigger,
Dialog,
} from "@/src/components/ui/dialog";
@@ -212,6 +213,9 @@ export function DefaultEvalModelSetup({
</Button>
</DialogTrigger>
<DialogContent className="px-3 py-10">
+ <DialogTitle className="sr-only">
+ Default evaluation model
+ </DialogTitle>
<div className="flex flex-col gap-2">
<DefaultEvalModelFields setup={setup} />
<div className="mt-2 flex justify-end gap-2">
diff --git a/web/src/features/events/components/V4IntroDialog.tsx b/web/src/features/events/components/V4IntroDialog.tsx
index 48bf61a71d..c19977ae06 100644
--- a/web/src/features/events/components/V4IntroDialog.tsx
+++ b/web/src/features/events/components/V4IntroDialog.tsx
@@ -4,6 +4,7 @@ import {
DialogContent,
DialogBody,
DialogFooter,
+ DialogTitle,
} from "@/src/components/ui/dialog";
export function V4IntroDialog({
@@ -17,10 +18,13 @@ export function V4IntroDialog({
}) {
return (
<Dialog open={open} onOpenChange={(o) => !o && onDismiss()}>
- <DialogContent
- className="[&>div:last-child]:hidden"
- aria-label="Welcome to a faster Langfuse"
- >
+ {/* `[&>div:last-child]:hidden` suppresses DialogContent's floating close
+ button; this dialog is dismissed through its footer action. The title
+ below is an h2, so it is not caught by that selector. */}
+ <DialogContent className="[&>div:last-child]:hidden">
+ <DialogTitle className="sr-only">
+ Welcome to a faster Langfuse
+ </DialogTitle>
<DialogBody>
{/* eslint-disable-next-line @next/next/no-img-element */}
<img
diff --git a/web/src/features/scores/components/AnnotateDrawerController.tsx b/web/src/features/scores/components/AnnotateDrawerController.tsx
index 2e7fa72fa2..4b28c89bfd 100644
--- a/web/src/features/scores/components/AnnotateDrawerController.tsx
+++ b/web/src/features/scores/components/AnnotateDrawerController.tsx
@@ -1,5 +1,9 @@
import { useHasProjectAccess } from "@/src/features/rbac";
-import { DrawerContent, DrawerController } from "@/src/components/ui/drawer";
+import {
+ DrawerContent,
+ DrawerController,
+ DrawerTitle,
+} from "@/src/components/ui/drawer";
import { usePostHogClientCapture } from "@/src/features/posthog-analytics";
import {
type ScoreTarget,
@@ -63,6 +67,9 @@ export function AnnotateDrawerController<Target extends ScoreTarget>({
triggerRef.current.focus({ preventScroll: true });
}}
>
+ {/* AnnotationPanelContent's visible "Annotate" header is a plain
+ heading, so the drawer still needs its own Title element. */}
+ <DrawerTitle className="sr-only">Annotate</DrawerTitle>
<div className="min-h-0 overflow-y-auto overscroll-contain p-3">
<AnnotationPanelContent
data={state}