From 6de0802155ac8d62b33b2f9f8ec40a87d5438cf4 Mon Sep 17 00:00:00 2001 From: joeyshi12 Date: Fri, 13 Nov 2026 18:28:10 -0700 Subject: [PATCH] fix: keep confirmation danger buttons solid in the dark theme Confirmation buttons combine the destructive Button variant with DANGER_BUTTON_CLASS. The variant sets dark:bg-destructive/20, which tailwind-merge keeps because DANGER_BUTTON_CLASS only sets the unprefixed bg-destructive. In the dark theme the button was a 20% red tint with the near-black --destructive-foreground label, so it looked disabled. DANGER_BUTTON_CLASS now sets the dark fill and hover fill too. --- components/danger-button.ts | 6 +++++- tests/lib/danger-button-dark.test.ts | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/lib/danger-button-dark.test.ts diff --git a/components/danger-button.ts b/components/danger-button.ts index 070c017a..d3413b76 100644 --- a/components/danger-button.ts +++ b/components/danger-button.ts @@ -9,6 +9,10 @@ * That token is a near-white on the light-theme red (4.6:1) and a near-black on * the lightened dark-theme red (6.9:1), so the label clears WCAG AA in both * themes. Override the fill or the label, never the two independently. + * + * The `dark:` fills repeat the solid fill because the `destructive` variant sets + * its own `dark:bg-destructive/20`, which would otherwise win in the dark theme + * and put the near-black label on a dark, mostly transparent fill. */ export const DANGER_BUTTON_CLASS = - "bg-destructive text-destructive-foreground hover:bg-destructive/95 focus-visible:border-destructive/40 focus-visible:ring-destructive/30" + "bg-destructive text-destructive-foreground hover:bg-destructive/95 focus-visible:border-destructive/40 focus-visible:ring-destructive/30 dark:bg-destructive dark:hover:bg-destructive/95" diff --git a/tests/lib/danger-button-dark.test.ts b/tests/lib/danger-button-dark.test.ts new file mode 100644 index 00000000..44f68380 --- /dev/null +++ b/tests/lib/danger-button-dark.test.ts @@ -0,0 +1,26 @@ +import test from "node:test" +import assert from "node:assert/strict" +import fs from "node:fs" + +import { DANGER_BUTTON_CLASS } from "../../components/danger-button" +import { cn } from "../../lib/utils" + +// Confirmation buttons combine the soft destructive Button variant with DANGER_BUTTON_CLASS. +// The test runner cannot import .tsx, so read the variant classes from the source. +const buttonSource = fs.readFileSync("components/ui/button.tsx", "utf8") +const destructiveVariant = buttonSource.match(/destructive:\s*"([^"]+)"/)?.[1] ?? "" +const merged = cn(destructiveVariant, DANGER_BUTTON_CLASS).split(" ") + +test("the soft destructive variant tints its fill in the dark theme", () => { + assert.ok(destructiveVariant.split(" ").includes("dark:bg-destructive/20")) +}) + +test("filled danger button keeps a solid fill in the dark theme", () => { + assert.ok(merged.includes("dark:bg-destructive")) + assert.ok(!merged.includes("dark:bg-destructive/20")) +}) + +test("filled danger button keeps a solid hover fill in the dark theme", () => { + assert.ok(merged.includes("dark:hover:bg-destructive/95")) + assert.ok(!merged.includes("dark:hover:bg-destructive/30")) +})