Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(select): keep dropdown options readable in dark mode (#4226)

Aditya Umalee2dde06a62b1
diff --git a/src/components/Select.test.ts b/src/components/Select.test.ts
new file mode 100644
index 0000000000..177730ede5
--- /dev/null
+++ b/src/components/Select.test.ts
@@ -0,0 +1,13 @@
+import { createElement } from "react";
+import { renderToStaticMarkup } from "react-dom/server";
+import { describe, expect, it } from "vitest";
+import { Select } from "./Select";
+
+describe("Select", () => {
+ it("opens its list in the skin's light or dark scheme, so options stay readable in dark mode", () => {
+ const html = renderToStaticMarkup(createElement(Select, { "aria-label": "Effort", defaultValue: "low" },
+ createElement("option", { value: "low" }, "Low"), createElement("option", { value: "high" }, "High")));
+ const select = (/<select[^>]*class="([^"]*)"/.exec(html)?.[1] ?? "").replaceAll("&amp;", "&");
+ expect(select.split(/\s+/)).toEqual(expect.arrayContaining(["[color-scheme:var(--code-color-scheme)]", "[&_option]:bg-menu", "[&_option]:text-ink"]));
+ });
+});
diff --git a/src/components/Select.tsx b/src/components/Select.tsx
index 922aa75349..78a65fb1c8 100644
--- a/src/components/Select.tsx
+++ b/src/components/Select.tsx
@@ -26,10 +26,11 @@ export function Select({
}: Omit<ComponentProps<"select">, "size"> & { variant?: keyof typeof VARIANTS; size?: keyof typeof SIZES }) {
return (
<div className={cn("relative inline-flex min-w-0", className)}>
+ {/* The platform draws the open list (white by default) while the options inherit the skin's ink, so they get the menu colour. */}
<select
{...props}
className={cn(
- "peer w-full min-w-0 cursor-pointer appearance-none truncate disabled:cursor-default disabled:opacity-50",
+ "peer w-full min-w-0 cursor-pointer appearance-none truncate [color-scheme:var(--code-color-scheme)] [&_option]:bg-menu [&_option]:text-ink disabled:cursor-default disabled:opacity-50",
VARIANTS[variant],
variant === "ghost" ? GHOST.select : SIZES[size].select,
)}