Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix(themes): use readable backend focus and valid scrim opacity (#18327)

Engel Nyst508c874ca04e
diff --git a/__tests__/components/features/settings/settings-navigation.test.tsx b/__tests__/components/features/settings/settings-navigation.test.tsx
index eec4226782..2511b23aa0 100644
--- a/__tests__/components/features/settings/settings-navigation.test.tsx
+++ b/__tests__/components/features/settings/settings-navigation.test.tsx
@@ -1,3 +1,6 @@
+import { readFile } from "node:fs/promises";
+import { resolve } from "node:path";
+import { compile } from "@tailwindcss/node";
import type { ReactNode } from "react";
import { render, screen, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
@@ -63,6 +66,41 @@ describe("SettingsNavigation", () => {
).toBeGreaterThan(0);
});
+ it("builds a half-transparent backdrop for the exported mobile drawer", async () => {
+ renderSettingsNavigation(
+ <SettingsNavigation
+ isMobileMenuOpen
+ onCloseMobileMenu={vi.fn()}
+ navigationItems={baseItems}
+ />,
+ );
+ const backdrop = screen.getByTestId("settings-navbar")
+ .previousElementSibling as HTMLElement;
+ const candidates = [...backdrop.classList];
+ const selectors = new Set(
+ candidates.map(
+ (candidate) =>
+ `.${candidate.replace(/[^\w-]/g, (character) => `\\${character}`)}`,
+ ),
+ );
+ const compiler = await compile(
+ await readFile(resolve("src/tailwind.css"), "utf8"),
+ { base: resolve("src"), onDependency: () => {} },
+ );
+ const stylesheet = compiler.build(candidates);
+ const backgrounds = [...stylesheet.matchAll(/(\.[^\s{]+)\s*\{([^}]+)\}/g)]
+ .filter(([, selector]) => selectors.has(selector))
+ .flatMap(([, , declarations]) =>
+ [...declarations.matchAll(/background-color:\s*([^;]+);/g)].map(
+ ([, value]) => value,
+ ),
+ );
+ expect(backgrounds).not.toEqual([]);
+ for (const background of backgrounds) {
+ expect(background).toMatch(/50%|0\.5\b/);
+ }
+ });
+
it("closes the mobile drawer when the close button is clicked", async () => {
const onCloseMobileMenu = vi.fn();
renderSettingsNavigation(
diff --git a/__tests__/themes/color-themes.test.tsx b/__tests__/themes/color-themes.test.tsx
index 7a52127edd..9f0b19e4ad 100644
--- a/__tests__/themes/color-themes.test.tsx
+++ b/__tests__/themes/color-themes.test.tsx
@@ -18,7 +18,7 @@ describe("color themes", () => {
// @spec MCP-004 β€” Form feedback follows readable theme text roles
// @spec WN-001 β€” Warning feedback also meets the small-text contrast contract
it.each(Object.entries(COLOR_THEMES))(
- "keeps small text readable on the %s theme surfaces",
+ "keeps feedback and keyboard focus readable on the %s theme surfaces",
(_key, theme) => {
// Resolve the shipped palette, including stylesheet-owned defaults.
const variables: Record<string, string> = {
@@ -60,6 +60,22 @@ describe("color themes", () => {
).toBeGreaterThanOrEqual(4.5);
}
+ // Focus contrast includes each neutral control surface.
+ for (const surfaceRole of [
+ "--oh-color-base",
+ "--oh-color-base-secondary",
+ "--oh-surface-raised",
+ "--oh-interactive-hover",
+ ]) {
+ expect(
+ contrast(
+ luminance(resolve("--oh-focus")),
+ luminance(resolve(surfaceRole)),
+ ),
+ `--oh-focus against ${surfaceRole}`,
+ ).toBeGreaterThanOrEqual(3);
+ }
+
// @spec FF-001 β€” Theme-aware validation and load errors
// The automation setup draft bar's error pill: Tailwind red-500
// (#fb2c36) at 5% over the theme surface.
diff --git a/src/components/features/backends/backend-form-modal.tsx b/src/components/features/backends/backend-form-modal.tsx
index 269ff3531f..94c519f02b 100644
--- a/src/components/features/backends/backend-form-modal.tsx
+++ b/src/components/features/backends/backend-form-modal.tsx
@@ -1142,7 +1142,7 @@ function BackendOptionTab({
className={cn(
"relative flex min-h-14 w-full cursor-pointer items-center gap-2.5 px-2.5 py-2.5 text-left transition-colors",
"not-last:border-r not-last:border-r-border",
- "focus-visible:z-10 focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-blue-300",
+ "focus-visible:z-10 focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-focus",
isSelected
? "bg-surface-raised text-contrast after:absolute after:inset-x-0 after:bottom-0 after:h-0.5 after:bg-primary"
: "text-muted hover:bg-surface-raised hover:text-contrast",
@@ -1264,7 +1264,7 @@ function AgentServerGuidance({ location }: { location: AgentServerLocation }) {
// fill spans the full row.
"flex w-full cursor-pointer items-center justify-between gap-2 rounded-lg px-3 py-2 text-left font-medium",
"transition-colors hover:bg-interactive-hover",
- "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-300",
+ "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus",
)}
>
<span className="flex min-w-0 items-center gap-2">
@@ -1371,7 +1371,7 @@ function AddBackendChooser({
type="button"
data-testid="add-backend-provider-digitalocean"
onClick={onSelectProvider}
- className="flex w-full cursor-pointer items-center gap-3 rounded-xl border border-border bg-base-secondary px-4 py-3 text-left transition-colors hover:bg-surface-raised focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-300"
+ className="flex w-full cursor-pointer items-center gap-3 rounded-xl border border-border bg-base-secondary px-4 py-3 text-left transition-colors hover:bg-surface-raised focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus"
>
<span
className="flex size-10 shrink-0 items-center justify-center rounded-lg bg-surface-raised"
diff --git a/src/components/features/settings/settings-mobile-drawer.tsx b/src/components/features/settings/settings-mobile-drawer.tsx
index 2626f0c2f2..c44be481d5 100644
--- a/src/components/features/settings/settings-mobile-drawer.tsx
+++ b/src/components/features/settings/settings-mobile-drawer.tsx
@@ -35,7 +35,7 @@ export function SettingsMobileDrawer({
<>
{isMobileMenuOpen && (
<div
- className="fixed inset-0 z-40 bg-black bg-opacity-50 md:hidden"
+ className="fixed inset-0 z-40 bg-black/50 md:hidden"
onClick={onCloseMobileMenu}
/>
)}
diff --git a/src/themes/README.md b/src/themes/README.md
index 05f73727ee..a07624b0d9 100644
--- a/src/themes/README.md
+++ b/src/themes/README.md
@@ -42,6 +42,10 @@ them; changing the page background alone is not a complete theme.
the built-in modal surface and leave the general danger/success/warning control
colors unchanged. Embedded hosts can override `--oh-feedback-error`,
`--oh-feedback-success`, and `--oh-feedback-warning` for their surfaces.
+- Use `focus` for keyboard outlines and rings on neutral controls. The default
+ role meets 3:1 against base, modal, raised, and interactive-hover surfaces;
+ retain the control's outline width/offset and preserve host `--oh-focus`
+ overrides. Check the settled color after a focus transition.
- Literal white is reserved for fixed-color surfaces (for example the blue
Plan control, an image-lightbox scrim, or a document preview). Do not globally
redefine white or add theme-specific selectors that reinterpret utilities.
diff --git a/src/themes/color-theme/definitions/solarized-light.ts b/src/themes/color-theme/definitions/solarized-light.ts
index 8a8e3acf3a..51fbe62a69 100644
--- a/src/themes/color-theme/definitions/solarized-light.ts
+++ b/src/themes/color-theme/definitions/solarized-light.ts
@@ -114,7 +114,8 @@ const SOLARIZED_LIGHT_TOKENS: Partial<
"--oh-border-input": "#C8C1AE",
"--oh-border-subtle": "#E6DFCC",
"--oh-separator": "rgba(88, 110, 117, 0.22)",
- "--oh-focus": "#268BD2",
+ // Focus remains visible on neutral and hovered surfaces.
+ "--oh-focus": "#227FBE",
"--oh-status-success": "#859900",
"--oh-status-error": "#DC322F",
"--oh-link": "#268BD2",
diff --git a/tests/e2e/mock-llm/regressions/mock-llm-ui-regressions.spec.ts b/tests/e2e/mock-llm/regressions/mock-llm-ui-regressions.spec.ts
index cd84255015..a24df3ca04 100644
--- a/tests/e2e/mock-llm/regressions/mock-llm-ui-regressions.spec.ts
+++ b/tests/e2e/mock-llm/regressions/mock-llm-ui-regressions.spec.ts
@@ -815,4 +815,32 @@ test.describe("UI regressions", () => {
await unselected.hover();
await expect(unselected).toHaveCSS("color", "rgb(139, 16, 41)");
});
+
+ test("backend keyboard focus follows the host focus role", async ({
+ page,
+ }) => {
+ await routeSessionApiKey(page);
+ await page.goto("/", { waitUntil: "domcontentloaded" });
+ const shell = page.locator("[data-agent-server-ui]").first();
+ await expect(shell).toBeVisible();
+ await shell.evaluate((el) => {
+ (el as HTMLElement).style.setProperty("--oh-focus", "#7314b9");
+ });
+ await page.getByTestId("backend-selector").click();
+ await page.getByTestId("add-backend-menu-item").click();
+ await page.getByTestId("add-backend-option-agent-server").click();
+
+ for (const id of [
+ "add-backend-option-agent-server",
+ "add-backend-local-guidance-toggle",
+ ]) {
+ const control = page.getByTestId(id);
+ await control.focus();
+ await page.keyboard.press("Space");
+ await page.keyboard.press("Tab");
+ await page.keyboard.press("Shift+Tab");
+ await expect(control).toBeFocused();
+ await expect(control).toHaveCSS("outline-color", "rgb(115, 20, 185)");
+ }
+ });
});