Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix(themes): make toast text readable in light themes (#18403)

Engel Nyst4a5447d21c55
diff --git a/__tests__/themes/color-themes.test.tsx b/__tests__/themes/color-themes.test.tsx
index c516e00186..bce84d7cf1 100644
--- a/__tests__/themes/color-themes.test.tsx
+++ b/__tests__/themes/color-themes.test.tsx
@@ -87,6 +87,15 @@ describe("color themes", () => {
`--oh-feedback-warning against ${surfaceName}`,
).toBeGreaterThanOrEqual(4.5);
}
+
+ // @spec TN-001 β€” Toast text stays readable on the toast surface
+ expect(
+ contrast(
+ luminance(resolve("--oh-contrast")),
+ luminance(resolve("--oh-color-tertiary")),
+ ),
+ "--oh-contrast against the toast surface",
+ ).toBeGreaterThanOrEqual(4.5);
},
);
diff --git a/__tests__/utils/custom-toast-handlers.test.ts b/__tests__/utils/custom-toast-handlers.test.ts
index 251c01bd60..add9856b79 100644
--- a/__tests__/utils/custom-toast-handlers.test.ts
+++ b/__tests__/utils/custom-toast-handlers.test.ts
@@ -89,7 +89,6 @@ describe("custom-toast-handlers", () => {
borderRadius: "var(--oh-radius)",
maxWidth: "400px",
wordBreak: "break-word",
- color: "var(--oh-muted)",
}),
}),
);
@@ -110,7 +109,6 @@ describe("custom-toast-handlers", () => {
borderRadius: "var(--oh-radius)",
maxWidth: "400px",
wordBreak: "break-word",
- color: "var(--oh-muted)",
}),
}),
);
diff --git a/specs/toast-notifications.md b/specs/toast-notifications.md
new file mode 100644
index 0000000000..08da72dff0
--- /dev/null
+++ b/specs/toast-notifications.md
@@ -0,0 +1,5 @@
+# Toast notification specs
+
+### TN-001: Readable toast text in every theme
+
+- [x] Success, warning, loading and error toasts shall draw their text in the `contrast` high-emphasis ink on the `--oh-color-tertiary` toast surface. The built-in palettes keep that pairing at 4.5:1 or better: white in dark palettes, dark ink in Light+ and Solarized Light. Error toasts keep the status-error icon as their error cue. Embedding roots may override `--oh-contrast`, and toasts follow the nearest `[data-agent-server-ui]` scope. Toast copy, icons, placement, duration and links are unchanged.
diff --git a/src/utils/custom-toast-handlers.tsx b/src/utils/custom-toast-handlers.tsx
index 62342d60d0..4c747c4ede 100644
--- a/src/utils/custom-toast-handlers.tsx
+++ b/src/utils/custom-toast-handlers.tsx
@@ -17,10 +17,11 @@ import {
} from "./api-error-message";
// react-hot-toast accepts only CSSProperties via the style option β€” cannot use className
+// @spec TN-001 β€” Every toast uses the theme's high-emphasis ink on its surface
const TOAST_STYLE: CSSProperties = {
background: "var(--oh-color-tertiary)",
border: "1px solid var(--oh-border-input)",
- color: "#fff",
+ color: "var(--oh-contrast)",
borderRadius: "var(--oh-radius)",
maxWidth: "400px",
wordBreak: "break-word",
@@ -33,11 +34,6 @@ export const TOAST_OPTIONS: ToastOptions = {
style: TOAST_STYLE,
};
-const ERROR_TOAST_STYLE: CSSProperties = {
- ...TOAST_STYLE,
- color: "var(--oh-muted)",
-};
-
/** Icon + message row; center icon for single-line text, top-align when wrapped. */
export function ErrorToastContent({ message }: { message: ReactNode }) {
const contentRef = React.useRef<HTMLSpanElement>(null);
@@ -95,7 +91,6 @@ export function ErrorToastContent({ message }: { message: ReactNode }) {
export const ERROR_TOAST_OPTIONS: ToastOptions = {
...TOAST_OPTIONS,
icon: null,
- style: ERROR_TOAST_STYLE,
};
function showErrorToast(message: string) {
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 906b929c62..cd84255015 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
@@ -450,6 +450,43 @@ test.describe("UI regressions", () => {
);
});
+ // @spec TN-001 β€” Toasts follow the embedding host's contrast ink
+ test("error and success toasts follow the host contrast color", async ({
+ page,
+ }) => {
+ await routeSessionApiKey(page);
+ // A host stylesheet override that survives full-page navigation.
+ await page.addInitScript(() => {
+ document.addEventListener("DOMContentLoaded", () => {
+ const style = document.createElement("style");
+ style.textContent =
+ "[data-agent-server-ui] { --oh-contrast: #8b1029 !important; }";
+ document.head.append(style);
+ });
+ });
+
+ await page.goto("/conversations/0123456789abcdef0123456789abcdef", {
+ waitUntil: "domcontentloaded",
+ });
+ await expect(
+ page.getByRole("status").filter({ hasText: "does not exist" }),
+ ).toHaveCSS("color", "rgb(139, 16, 41)");
+
+ await page.goto("/settings/app", { waitUntil: "domcontentloaded" });
+ const soundSwitch = page.getByText("Sound Notifications", { exact: true });
+ const saveButton = page.getByRole("button", { name: "Save Changes" });
+ await soundSwitch.click();
+ await saveButton.click();
+ await expect(
+ page.getByRole("status").filter({ hasText: "Settings saved" }),
+ ).toHaveCSS("color", "rgb(139, 16, 41)");
+
+ // Restore the original setting for later serial scenarios.
+ await soundSwitch.click();
+ await saveButton.click();
+ await expect(saveButton).toBeDisabled();
+ });
+
// ── critic result rendering ──────────────────────────────────────
test("renders critic results on agent messages and finish actions", async ({