Skip to content

Shared shadcn Button variants use alpha hovers and lose contrast on hover in every variant #2689

Closed

Description

@malibio

Overview

packages/desktop-app/src/lib/components/ui/button/types.ts:12-14 still uses the alpha-hover idiom that DESIGN.md now forbids, and every variant loses contrast on hover — the opposite of the rule adopted in #2673:

default:     'bg-primary text-primary-foreground shadow-xs hover:bg-primary/90'
destructive: 'bg-destructive shadow-xs hover:bg-destructive/90 dark:bg-destructive/60 text-white'

Measured (WCAG relative luminance, alpha composited against --background):

Variant Theme Rest Hover
destructive dark 5.97:1 3.39:1 below AA
destructive light 5.36:1 4.76:1 degrades
default light 3.51:1 3.05:1 below AA
default dark 4.47:1 3.81:1 below AA

The dark destructive case is the sharp one: hovering "Remove database" makes the label less readable at the exact moment of a destructive commitment.

Why this is not just a token swap

hover:bg-primary-hover / hover:bg-destructive-hover is the obvious fix, but the destructive variant has two coupled problems that need a decision first:

  1. dark:bg-destructive/60 makes the dark REST state translucent. Changing only the hover leaves a translucent rest state under an opaque hover, which is incoherent. Is the muted /60 dark treatment deliberate, or stock shadcn carried over?
  2. text-white bypasses --destructive-foreground. Success token is below WCAG AA as text on light surfaces; *-foreground tokens are white in both themes #2668 gave that token real per-theme values precisely because white fails on dark-mode fills (2.00-2.86:1). This variant hardcodes the value that issue removed.

tailwind.config.js also needs --primary-hover / --destructive-hover registered under theme.extend.colors before the classes resolve.

Context

This file has not been touched since the repository-flattening commit — it is stock shadcn boilerplate that predates NodeSpace's token work and was never reconciled with the design system. That is why it is filed separately rather than folded into #2673, which added the tokens and migrated the four hand-written call sites.

Blast radius: Button is imported by ~18 files; variant="destructive" is used at settings/sections/database-settings.svelte:226.

Acceptance Criteria

  • --primary-hover / --destructive-hover registered in tailwind.config.js
  • default and destructive variants use the hover tokens; zero /90 alpha hovers remain in buttonVariants
  • A decision recorded on dark:bg-destructive/60: keep the muted dark treatment (and give it a token) or drop it for the solid fill
  • destructive uses --destructive-foreground rather than text-white
  • Every variant's hover contrast is >= AA and >= its rest-state contrast, both themes
  • Spot-check the ~18 consumers for visual regressions

Related

Activity

  1. malibio commented on Sep 17, 2026

    @malibio
    CollaboratorAuthor

    Baseline on a fresh worktree — Frontend: 249 test files / 5134 tests passed.

  2. self-assigned this
    on Sep 17, 2026
  3. malibio commented on Sep 17, 2026

    @malibio
    CollaboratorAuthor

    Implementation notes

    All eight contrast figures in the issue reproduce exactly. After the fix:

    Variant Theme Rest Hover (before) Hover (after)
    default light 3.51:1 3.05:1 4.86:1
    default dark 4.47:1 3.81:1 5.79:1
    destructive light 5.36:1 4.76:1 6.66:1
    destructive dark 5.97 → 6.95:1 3.39:1 8.45:1

    Decision on dark:bg-destructive/60 — dropped

    The issue asked whether the muted dark treatment was deliberate. It resolves as a symptom of text-white, not a design choice, and the two had to be decided together:

    • Against the solid dark --destructive fill, text-white is 2.86:1.
    • /60 lightened that fill toward the page, which is the only thing that made white survive there at all.

    So removing /60 while keeping text-white would have made it worse, and keeping /60 under an opaque hover would have been incoherent. Both go: the variant is solid in both themes and labels with --destructive-foreground, taking dark rest from 2.86:1 to 6.95:1.

    Light mode is visually unchanged — light --destructive-foreground is 0 0% 100%, identical to the text-white it replaces. Only dark mode moves, which is where the defect was.

    Tailwind registration

    Registered without an <alpha-value> placeholder, deliberately, so hover:bg-destructive-hover/90 does not resolve — a hover fill is opaque by definition, and an alpha channel would reopen the idiom this removes. Only --primary-hover and --destructive-hover are registered; --success/--warning have no Tailwind color entry at all today and no utility usage, so registering only their hovers would have been incoherent.

    Test

    The existing filled-button-hover.test.ts passed throughout the entire period this bug was live — it proves the token values obey the rule, which is necessary but not sufficient. The gap between correct tokens and a component that ignores them is exactly how this shipped, so filled-button-variants.test.ts (14 tests) asserts consumption instead.

    Verified by mutation rather than assumed:

    Mutation Result
    Variants reverted to the original stock strings 5 tests fail
    <alpha-value> re-added to the config entry 2 tests fail
    dark --destructive-hover 76% → 64% — wrong direction, still 7.3:1 1 test fails

    The third is the case an AA floor alone would miss, and is why the load-bearing assertion compares hover contrast to rest contrast rather than to a constant.

    Also compiled the real emitted class strings through PostCSS to confirm they resolve to opaque hsl(var(--*-hover)) rules and that zero alpha hover rules remain — a class-name assertion alone cannot prove the build emits anything.

    Deliberately not addressed

    A rest-state AA floor. --primary is 3.51:1 light / 4.47:1 dark against its own foreground at rest — both under AA, both pre-existing properties of the brand color, and unreachable by any hover change. My first draft asserted a rest floor and failed on exactly this; asserting it would make the suite fail on a defect it does not own. Worth its own issue if the brand color is up for revision.

    Filed separately

    Verification

    • bun run test — 250 files / 5148 tests passed (baseline 249 / 5134)
    • bun run quality:fix — clean; design-token baseline unchanged at 137; svelte-check 2540 files, 0 errors, 0 warnings
    • All 18 consumers audited: none overrides the button background or label color; the only external buttonVariants users are the calendar prev/next buttons on the untouched outline variant
    • app.css untouched — scope is the component and its Tailwind registration
  4. added a commit that references this issue on Sep 17, 2026
    c7d102e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions