π OpenHands: AI-Driven Development
fix(chat): show git chip icons in light themes (#18660)
Engel Nyst1f7b1e69a19c
diff --git a/.pr/git-chip-icons/README.md b/.pr/git-chip-icons/README.mdnew file mode 100644index 0000000000..967a92bdcb--- /dev/null+++ b/.pr/git-chip-icons/README.md@@ -0,0 +1,44 @@+# Git chip icons in light themes (#18657)++Before/after evidence for the workspace, branch, external-link and+workspace-mode chip icons. `before-*` was served from main (product source+identical to `79abd32d8`); `after-*` from this branch.++## Commands++```sh+export OH_VERIFY_RUN=$(control-openhands launch --new --print-run) # once per checkout+control-openhands doctor+# <run>/private/home/.config/uv/uv.toml pins litellm (SDK#6088), then:+control-openhands restart+control-openhands llm preset deepseek && control-openhands onboard --skip+control-openhands fixture git-repo --name qa-repo+control-openhands fixture git-repo --name qa-gh --remote https://github.com/qa-example/qa-gh.git+control-openhands conversation start --workspace qa-repo --prompt "Reply with only the word OK. Do not run any tools." --wait+control-openhands conversation start --workspace qa-gh --prompt "Reply with only the word OK. Do not run any tools." --wait+# For each of Light+, Solarized Light, OpenHands-Neutral (default):+control-openhands browser goto /settings/app+control-openhands browser choose 'testid=color-theme-input' "<theme>"+control-openhands browser goto /conversations/<id> # desktop and `viewport phone` (390x844)+control-openhands browser eval "<getComputedStyle(svg).color vs nearest opaque background, WCAG ratio>"+control-openhands browser screenshot --feature F07.git-control-bar --name <tag>-<theme>-<viewport>+# GitHub-origin chip: hover the repo link so the external-link icon shows.+# Home composer: `workspace open <run>/workspace/qa-repo` shows the workspace-mode chip.+```++## Measured icon contrast++| Chip icon | Theme | Before | After |+|---|---|---|---|+| workspace + branch (conversation, desktop and 390x844) | Light+ | `#FFF` on `#FFF`, 1.00:1 | `rgb(31,31,31)` on `#FFF`, 16.48:1 |+| workspace + branch (conversation, desktop and 390x844) | Solarized Light | `#FFF` on `rgb(253,246,227)`, 1.08:1 | `rgb(0,43,54)`, 13.92:1 |+| workspace + branch (conversation, desktop and 390x844) | Default dark | `#FFF` on `rgb(24,24,24)`, 17.76:1 | unchanged, 17.76:1 |+| external link (GitHub chip, hover gradient end) | Light+ | `#FFF` on `rgb(229,229,229)`, 1.26:1 | 13.08:1 |+| external link (GitHub chip, hover gradient end) | Solarized Light | `#FFF` on `rgb(230,223,204)`, 1.33:1 | 11.29:1 |+| external link (GitHub chip, hover gradient end) | Default dark | `#FFF` on `rgb(49,49,49)`, 13.01:1 | unchanged, 13.01:1 |+| workspace-mode "Local Repo" (home composer) | Light+ | 1.00:1 | 16.48:1 |+| workspace-mode "Local Repo" (home composer) | Solarized Light | 1.08:1 | 13.92:1 |+| workspace-mode "Local Repo" (home composer) | Default dark | 17.76:1 | unchanged, 17.76:1 |++No chip icon in `chat-git-control-bar` or `home-git-control-bar-preview` has a+`color` attribute after the fix.diff --git a/.pr/git-chip-icons/after-default-desktop.png b/.pr/git-chip-icons/after-default-desktop.pngnew file mode 100644index 0000000000..0622e516a6Binary files /dev/null and b/.pr/git-chip-icons/after-default-desktop.png differdiff --git a/.pr/git-chip-icons/after-default-github-hover.png b/.pr/git-chip-icons/after-default-github-hover.pngnew file mode 100644index 0000000000..74874f8201Binary files /dev/null and b/.pr/git-chip-icons/after-default-github-hover.png differdiff --git a/.pr/git-chip-icons/after-default-home-chips.png b/.pr/git-chip-icons/after-default-home-chips.pngnew file mode 100644index 0000000000..f944f345a5Binary files /dev/null and b/.pr/git-chip-icons/after-default-home-chips.png differdiff --git a/.pr/git-chip-icons/after-default-phone.png b/.pr/git-chip-icons/after-default-phone.pngnew file mode 100644index 0000000000..791ad642ddBinary files /dev/null and b/.pr/git-chip-icons/after-default-phone.png differdiff --git a/.pr/git-chip-icons/after-lightplus-desktop.png b/.pr/git-chip-icons/after-lightplus-desktop.pngnew file mode 100644index 0000000000..82e22f4505Binary files /dev/null and b/.pr/git-chip-icons/after-lightplus-desktop.png differdiff --git a/.pr/git-chip-icons/after-lightplus-github-hover.png b/.pr/git-chip-icons/after-lightplus-github-hover.pngnew file mode 100644index 0000000000..706287b7a8Binary files /dev/null and b/.pr/git-chip-icons/after-lightplus-github-hover.png differdiff --git a/.pr/git-chip-icons/after-lightplus-home-chips.png b/.pr/git-chip-icons/after-lightplus-home-chips.pngnew file mode 100644index 0000000000..d8fbb81c1aBinary files /dev/null and b/.pr/git-chip-icons/after-lightplus-home-chips.png differdiff --git a/.pr/git-chip-icons/after-lightplus-phone.png b/.pr/git-chip-icons/after-lightplus-phone.pngnew file mode 100644index 0000000000..a03760162bBinary files /dev/null and b/.pr/git-chip-icons/after-lightplus-phone.png differdiff --git a/.pr/git-chip-icons/after-solarized-desktop.png b/.pr/git-chip-icons/after-solarized-desktop.pngnew file mode 100644index 0000000000..f1486312d2Binary files /dev/null and b/.pr/git-chip-icons/after-solarized-desktop.png differdiff --git a/.pr/git-chip-icons/after-solarized-github-hover.png b/.pr/git-chip-icons/after-solarized-github-hover.pngnew file mode 100644index 0000000000..4e5577543dBinary files /dev/null and b/.pr/git-chip-icons/after-solarized-github-hover.png differdiff --git a/.pr/git-chip-icons/after-solarized-home-chips.png b/.pr/git-chip-icons/after-solarized-home-chips.pngnew file mode 100644index 0000000000..80935ad54cBinary files /dev/null and b/.pr/git-chip-icons/after-solarized-home-chips.png differdiff --git a/.pr/git-chip-icons/after-solarized-phone.png b/.pr/git-chip-icons/after-solarized-phone.pngnew file mode 100644index 0000000000..0d15a36a68Binary files /dev/null and b/.pr/git-chip-icons/after-solarized-phone.png differdiff --git a/.pr/git-chip-icons/before-default-desktop.png b/.pr/git-chip-icons/before-default-desktop.pngnew file mode 100644index 0000000000..37f95e1e67Binary files /dev/null and b/.pr/git-chip-icons/before-default-desktop.png differdiff --git a/.pr/git-chip-icons/before-default-github-hover.png b/.pr/git-chip-icons/before-default-github-hover.pngnew file mode 100644index 0000000000..c89c545693Binary files /dev/null and b/.pr/git-chip-icons/before-default-github-hover.png differdiff --git a/.pr/git-chip-icons/before-default-home-chips.png b/.pr/git-chip-icons/before-default-home-chips.pngnew file mode 100644index 0000000000..f944f345a5Binary files /dev/null and b/.pr/git-chip-icons/before-default-home-chips.png differdiff --git a/.pr/git-chip-icons/before-default-phone.png b/.pr/git-chip-icons/before-default-phone.pngnew file mode 100644index 0000000000..9e69df8909Binary files /dev/null and b/.pr/git-chip-icons/before-default-phone.png differdiff --git a/.pr/git-chip-icons/before-lightplus-desktop.png b/.pr/git-chip-icons/before-lightplus-desktop.pngnew file mode 100644index 0000000000..7de51ae7ffBinary files /dev/null and b/.pr/git-chip-icons/before-lightplus-desktop.png differdiff --git a/.pr/git-chip-icons/before-lightplus-github-hover.png b/.pr/git-chip-icons/before-lightplus-github-hover.pngnew file mode 100644index 0000000000..c9fee6cfbcBinary files /dev/null and b/.pr/git-chip-icons/before-lightplus-github-hover.png differdiff --git a/.pr/git-chip-icons/before-lightplus-home-chips.png b/.pr/git-chip-icons/before-lightplus-home-chips.pngnew file mode 100644index 0000000000..ca4b261168Binary files /dev/null and b/.pr/git-chip-icons/before-lightplus-home-chips.png differdiff --git a/.pr/git-chip-icons/before-lightplus-phone.png b/.pr/git-chip-icons/before-lightplus-phone.pngnew file mode 100644index 0000000000..38e4294947Binary files /dev/null and b/.pr/git-chip-icons/before-lightplus-phone.png differdiff --git a/.pr/git-chip-icons/before-solarized-desktop.png b/.pr/git-chip-icons/before-solarized-desktop.pngnew file mode 100644index 0000000000..6a2a339024Binary files /dev/null and b/.pr/git-chip-icons/before-solarized-desktop.png differdiff --git a/.pr/git-chip-icons/before-solarized-github-hover.png b/.pr/git-chip-icons/before-solarized-github-hover.pngnew file mode 100644index 0000000000..5268211128Binary files /dev/null and b/.pr/git-chip-icons/before-solarized-github-hover.png differdiff --git a/.pr/git-chip-icons/before-solarized-home-chips.png b/.pr/git-chip-icons/before-solarized-home-chips.pngnew file mode 100644index 0000000000..55b4261f8eBinary files /dev/null and b/.pr/git-chip-icons/before-solarized-home-chips.png differdiff --git a/.pr/git-chip-icons/before-solarized-phone.png b/.pr/git-chip-icons/before-solarized-phone.pngnew file mode 100644index 0000000000..d48d413407Binary files /dev/null and b/.pr/git-chip-icons/before-solarized-phone.png differdiff --git a/__tests__/components/features/chat/git-chip-icons.test.tsx b/__tests__/components/features/chat/git-chip-icons.test.tsxnew file mode 100644index 0000000000..92386ca9e9--- /dev/null+++ b/__tests__/components/features/chat/git-chip-icons.test.tsx@@ -0,0 +1,107 @@+import type { ReactElement } from "react";+import { render } from "@testing-library/react";+import { describe, it, expect, vi } from "vitest";+import { GitControlBarBranchButton } from "#/components/features/chat/git-control-bar-branch-button";+import { GitControlBarRepoButton } from "#/components/features/chat/git-control-bar-repo-button";+import { WorkspaceModeSelector } from "#/components/features/chat/workspace-mode-selector";++vi.mock("react-i18next", () => ({+ useTranslation: () => ({ t: (key: string) => key }),+}));++vi.mock("#/hooks/query/use-settings", () => ({+ useSettings: () => ({ data: { provider_tokens_set: {} } }),+}));++// Chip icons must take the theme's ink through `currentColor`, from the same+// colour class as the chip label. A fixed `color` (or fill/stroke) on the SVG+// overrides that inheritance and made the icons white-on-white in light themes+// (#18657).+const INK_CLASS =+ /^text-(contrast|muted|white|black|current|foreground|feedback-[a-z-]+|status-[a-z-]+|\[[^\]]+\])$/;++// The colour class an element's text and `currentColor` resolve from: the+// nearest ancestor-or-self class that sets the text colour.+function inkClass(element: Element): string | null {+ for (let node: Element | null = element; node; node = node.parentElement) {+ const ink = Array.from(node.classList).find((name) => INK_CLASS.test(name));+ if (ink) return ink;+ }+ return null;+}++function expectNoFixedColour(icon: SVGSVGElement) {+ expect(icon).not.toHaveAttribute("color");+ for (const node of [icon, ...Array.from(icon.querySelectorAll("*"))]) {+ for (const attribute of ["fill", "stroke"]) {+ const value = node.getAttribute(attribute);+ if (value !== null) expect(["none", "currentColor"]).toContain(value);+ }+ }+}++describe("git control bar chip icons", () => {+ it.each<[string, () => ReactElement, string]>([+ [+ "linked branch chip (branch and external-link icons)",+ () => (+ <GitControlBarBranchButton+ selectedBranch="main"+ selectedRepository="owner/repo"+ gitProvider="github"+ />+ ),+ "main",+ ],+ [+ "unlinked branch chip",+ () => (+ <GitControlBarBranchButton+ selectedBranch="main"+ selectedRepository={null}+ gitProvider={null}+ />+ ),+ "main",+ ],+ [+ "local workspace chip",+ () => (+ <GitControlBarRepoButton+ selectedRepository={null}+ gitProvider={null}+ workspaceName="qa-repo"+ />+ ),+ "qa-repo",+ ],+ [+ "workspace mode chip",+ () => (+ <WorkspaceModeSelector+ value="local_repo"+ backendKind="local"+ onChange={() => {}}+ />+ ),+ "",+ ],+ ])(+ "%s icons take the same theme ink as the label",+ (_name, renderChip, labelText) => {+ const { container, getByText } = render(renderChip());+ const label = labelText+ ? getByText(labelText)+ : container.querySelector("button span.truncate")!;+ const labelInk = inkClass(label);+ expect(labelInk).toBe("text-contrast");++ const icons = Array.from(container.querySelectorAll("svg"));+ expect(icons.length).toBeGreaterThan(0);+ for (const icon of icons) {+ expectNoFixedColour(icon);+ expect(inkClass(icon)).toBe(labelInk);+ }+ },+ );+});diff --git a/src/components/features/chat/git-control-bar-branch-button.tsx b/src/components/features/chat/git-control-bar-branch-button.tsxindex 47fc80d5e9..314af0ad96 100644--- a/src/components/features/chat/git-control-bar-branch-button.tsx+++ b/src/components/features/chat/git-control-bar-branch-button.tsx@@ -52,8 +52,8 @@ export function GitControlBarBranchButton({: "border border-[rgba(71,74,84,0.50)] bg-transparent cursor-not-allowed min-w-27",)}>- <div className="w-3 h-3 flex items-center justify-center flex-shrink-0">- <BranchIcon width={12} height={12} color="white" />+ <div className="w-3 h-3 flex items-center justify-center flex-shrink-0 text-contrast">+ <BranchIcon width={12} height={12} /></div><divclassName="font-normal text-contrast text-sm leading-5 truncate"diff --git a/src/components/features/chat/git-control-bar-repo-button.tsx b/src/components/features/chat/git-control-bar-repo-button.tsxindex 07e2a772bd..15b9aa557d 100644--- a/src/components/features/chat/git-control-bar-repo-button.tsx+++ b/src/components/features/chat/git-control-bar-repo-button.tsx@@ -97,7 +97,7 @@ export function GitControlBarRepoButton({data-testid="git-control-bar-connect-repo-icon"/>) : (- <RepoForkedIcon width={12} height={12} color="white" />+ <RepoForkedIcon width={12} height={12} />)}</div><divdiff --git a/src/components/features/chat/git-external-link-icon.tsx b/src/components/features/chat/git-external-link-icon.tsxindex c6d4ed2ea3..45b0e9461d 100644--- a/src/components/features/chat/git-external-link-icon.tsx+++ b/src/components/features/chat/git-external-link-icon.tsx@@ -9,11 +9,11 @@ export function GitExternalLinkIcon({ className }: GitExternalLinkIconProps) {return (<divclassName={cn(- "w-3 h-3 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity duration-300 absolute right-0 top-1/2 -translate-y-1/2 h-full w-10.5 pr-2.5 justify-end git-external-link-icon",+ "w-3 h-3 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity duration-300 absolute right-0 top-1/2 -translate-y-1/2 h-full w-10.5 pr-2.5 justify-end text-contrast git-external-link-icon",className,)}>- <LinkExternalIcon width={12} height={12} color="white" />+ <LinkExternalIcon width={12} height={12} /></div>);}diff --git a/src/components/features/chat/workspace-mode-icon.tsx b/src/components/features/chat/workspace-mode-icon.tsxindex 56bc9bc2f4..c40d3c9db5 100644--- a/src/components/features/chat/workspace-mode-icon.tsx+++ b/src/components/features/chat/workspace-mode-icon.tsx@@ -7,5 +7,5 @@ export function WorkspaceModeIcon({ mode }: { mode: WorkspaceMode }) {return <GitBranch className="size-3" strokeWidth={2} aria-hidden />;}- return <RepoForkedIcon width={12} height={12} color="white" aria-hidden />;+ return <RepoForkedIcon width={12} height={12} aria-hidden />;}