Skip to content

Same agent Smaller bill. The tools and infrastructure to get more work from your AI. Fewer tokens. Less compute. Lower cost.

fix(client): add focus rings to form controls and fix alert contrast (#1564)

Christian Sidaka14c0935baf5
diff --git a/src/client/src/__tests__/components/ui-accessibility.test.tsx b/src/client/src/__tests__/components/ui-accessibility.test.tsx
new file mode 100644
index 00000000..beb71bd6
--- /dev/null
+++ b/src/client/src/__tests__/components/ui-accessibility.test.tsx
@@ -0,0 +1,109 @@
+import { render, screen } from "@testing-library/react";
+import { Input } from "@/components/ui/input";
+import { Textarea } from "@/components/ui/textarea";
+import { Alert, AlertTitle, AlertDescription } from "@/components/ui/alert";
+import { Select, SelectTrigger, SelectValue } from "@/components/ui/select";
+import { Tabs, TabsList, TabsTrigger, TabsContent } from "@/components/ui/tabs";
+
+// Focus-visible ring classes applied consistently across form controls and
+// interactive primitives so keyboard users can identify focus.
+const FOCUS_RING_CLASSES = [
+ "focus-visible:outline-none",
+ "focus-visible:ring-2",
+ "focus-visible:ring-stone-950",
+ "focus-visible:ring-offset-2",
+ "dark:focus-visible:ring-stone-300",
+];
+
+function hasAllClasses(el: HTMLElement, classes: string[]): boolean {
+ return classes.every((cls) => el.classList.contains(cls));
+}
+
+describe("Input accessibility", () => {
+ it("renders a visible focus ring for keyboard navigation", () => {
+ render(<Input placeholder="test" />);
+ const input = screen.getByPlaceholderText("test");
+ expect(hasAllClasses(input, FOCUS_RING_CLASSES)).toBe(true);
+ });
+});
+
+describe("Textarea accessibility", () => {
+ it("renders a visible focus ring for keyboard navigation", () => {
+ render(<Textarea placeholder="test" />);
+ const textarea = screen.getByPlaceholderText("test");
+ expect(hasAllClasses(textarea, FOCUS_RING_CLASSES)).toBe(true);
+ });
+});
+
+describe("TabsTrigger accessibility", () => {
+ it("renders a visible focus ring for keyboard navigation", () => {
+ render(
+ <Tabs defaultValue="a">
+ <TabsList>
+ <TabsTrigger value="a">Tab A</TabsTrigger>
+ </TabsList>
+ <TabsContent value="a">Content A</TabsContent>
+ </Tabs>
+ );
+ const trigger = screen.getByRole("tab", { name: "Tab A" });
+ expect(hasAllClasses(trigger, FOCUS_RING_CLASSES)).toBe(true);
+ });
+});
+
+describe("SelectTrigger accessibility", () => {
+ it("renders a visible focus ring for keyboard navigation", () => {
+ render(
+ <Select>
+ <SelectTrigger aria-label="Choose">
+ <SelectValue placeholder="Choose" />
+ </SelectTrigger>
+ </Select>
+ );
+ const trigger = screen.getByRole("combobox", { name: "Choose" });
+ expect(hasAllClasses(trigger, FOCUS_RING_CLASSES)).toBe(true);
+ expect(
+ hasAllClasses(trigger, [
+ "focus-visible:ring-offset-white",
+ "dark:focus-visible:ring-offset-stone-950",
+ ])
+ ).toBe(true);
+ expect(trigger.className).not.toContain("focus:outline-none");
+ });
+});
+
+describe("Alert destructive variant accessibility", () => {
+ it("owns a fill so 14px error text clears WCAG AA on any parent", () => {
+ render(
+ <Alert variant="destructive">
+ <AlertTitle>Error</AlertTitle>
+ <AlertDescription>Something went wrong.</AlertDescription>
+ </Alert>
+ );
+ const alert = screen.getByRole("alert");
+ // The query debugger sits on stone-100. Transparent red-600 text there
+ // is 4.43:1. White + red-700 is 6.47:1; stone-950 + red-400 is 7.14:1.
+ expect(
+ hasAllClasses(alert, [
+ "bg-white",
+ "text-red-700",
+ "[&>svg]:text-red-700",
+ "dark:bg-stone-950",
+ "dark:text-red-400",
+ "dark:[&>svg]:text-red-400",
+ ])
+ ).toBe(true);
+ expect(alert.className).not.toContain("dark:text-red-900");
+ expect(alert.className).not.toContain("text-red-600");
+ expect(alert.className).not.toContain("text-red-500");
+ });
+
+ it("does not contain the invalid dark:dark: duplicate class", () => {
+ render(
+ <Alert variant="destructive">
+ <AlertDescription>Error details.</AlertDescription>
+ </Alert>
+ );
+ const alert = screen.getByRole("alert");
+ expect(alert.className).not.toContain("dark:dark:");
+ });
+});
diff --git a/src/client/src/components/ui/alert.tsx b/src/client/src/components/ui/alert.tsx
index 2f3000a3..466b5c4c 100644
--- a/src/client/src/components/ui/alert.tsx
+++ b/src/client/src/components/ui/alert.tsx
@@ -10,7 +10,7 @@ const alertVariants = cva(
variant: {
default: "bg-white text-stone-950 dark:bg-stone-950 dark:text-stone-50",
destructive:
- "border-red-500/50 text-red-500 dark:border-red-500 [&>svg]:text-red-500 dark:border-red-900/50 dark:text-red-900 dark:dark:border-red-900 dark:[&>svg]:text-red-900",
+ "border-red-500/50 bg-white text-red-700 [&>svg]:text-red-700 dark:border-red-500/50 dark:bg-stone-950 dark:text-red-400 dark:[&>svg]:text-red-400",
},
},
defaultVariants: {
diff --git a/src/client/src/components/ui/input.tsx b/src/client/src/components/ui/input.tsx
index 459382c1..0c221c76 100644
--- a/src/client/src/components/ui/input.tsx
+++ b/src/client/src/components/ui/input.tsx
@@ -11,7 +11,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
<input
type={type}
className={cn(
- "flex h-10 w-full rounded-md border border-stone-200 bg-white px-3 py-2 text-sm text-stone-900 file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-stone-500 focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50 dark:border-stone-800 dark:bg-stone-950 dark:text-stone-100 dark:placeholder:text-stone-400",
+ "flex h-10 w-full rounded-md border border-stone-200 bg-white px-3 py-2 text-sm text-stone-900 file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-stone-500 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-stone-950 focus-visible:ring-offset-2 focus-visible:ring-offset-white disabled:cursor-not-allowed disabled:opacity-50 dark:border-stone-800 dark:bg-stone-950 dark:text-stone-100 dark:placeholder:text-stone-400 dark:focus-visible:ring-stone-300 dark:focus-visible:ring-offset-stone-950",
className
)}
ref={ref}
diff --git a/src/client/src/components/ui/select.tsx b/src/client/src/components/ui/select.tsx
index ec2b10b2..108a2146 100644
--- a/src/client/src/components/ui/select.tsx
+++ b/src/client/src/components/ui/select.tsx
@@ -19,7 +19,7 @@ const SelectTrigger = React.forwardRef<
<SelectPrimitive.Trigger
ref={ref}
className={cn(
- "flex h-10 w-full items-center justify-between rounded-md border border-stone-200 bg-white px-3 py-2 text-sm placeholder:text-stone-500 focus:outline-none disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1 dark:border-stone-800 dark:bg-stone-950 dark:placeholder:text-stone-400 dark:text-stone-200",
+ "flex h-10 w-full items-center justify-between rounded-md border border-stone-200 bg-white px-3 py-2 text-sm placeholder:text-stone-500 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-stone-950 focus-visible:ring-offset-2 focus-visible:ring-offset-white disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1 dark:border-stone-800 dark:bg-stone-950 dark:placeholder:text-stone-400 dark:text-stone-200 dark:focus-visible:ring-stone-300 dark:focus-visible:ring-offset-stone-950",
className
)}
{...props}
diff --git a/src/client/src/components/ui/tabs.tsx b/src/client/src/components/ui/tabs.tsx
index bae329dc..eb741727 100644
--- a/src/client/src/components/ui/tabs.tsx
+++ b/src/client/src/components/ui/tabs.tsx
@@ -29,7 +29,7 @@ const TabsTrigger = React.forwardRef<
<TabsPrimitive.Trigger
ref={ref}
className={cn(
- "inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium transition-all focus-visible:outline-none disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-primary data-[state=active]:text-stone-50 data-[state=active]:shadow-sm dark:data-[state=active]:bg-primary dark:data-[state=active]:text-stone-50",
+ "inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-stone-950 focus-visible:ring-offset-2 focus-visible:ring-offset-white disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-primary data-[state=active]:text-stone-50 data-[state=active]:shadow-sm dark:focus-visible:ring-stone-300 dark:focus-visible:ring-offset-stone-950 dark:data-[state=active]:bg-primary dark:data-[state=active]:text-stone-50",
className
)}
{...props}
diff --git a/src/client/src/components/ui/textarea.tsx b/src/client/src/components/ui/textarea.tsx
index 3068674e..5bc0dcc1 100644
--- a/src/client/src/components/ui/textarea.tsx
+++ b/src/client/src/components/ui/textarea.tsx
@@ -10,7 +10,7 @@ const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
return (
<textarea
className={cn(
- "flex min-h-[80px] w-full rounded-md border border-stone-200 bg-white px-3 py-2 text-sm ring-offset-white placeholder:text-stone-500 focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50 dark:border-stone-800 dark:bg-stone-950 dark:ring-offset-stone-950 dark:placeholder:text-stone-400",
+ "flex min-h-[80px] w-full rounded-md border border-stone-200 bg-white px-3 py-2 text-sm ring-offset-white placeholder:text-stone-500 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-stone-950 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:border-stone-800 dark:bg-stone-950 dark:ring-offset-stone-950 dark:placeholder:text-stone-400 dark:focus-visible:ring-stone-300",
className
)}
ref={ref}