From 6d0f920c2a475afcc7bba229a0a28c47891b6c3b Mon Sep 17 00:00:00 2001 From: lrnselfreliance <33263708+lrnselfreliance@users.noreply.github.com> Date: Tue, 11 Aug 2026 20:31:37 -0600 Subject: [PATCH] ui: an icon button that was given a color, and never used it (#659) `IconButton` resolved `variant={props.variant ?? fromRole?.variant ?? 'default'}`, so any call site that named a color without also naming a role or a variant landed on Mantine's `default` variant. That variant draws its background, hover, text and border from `--mantine-color-default*` alone and never reads `color`, so the button rendered byte-identical to one with no props at all. The color was accepted, stored, and dropped. `Button` was never affected: it leaves `variant` undefined when there is no role and Mantine fills in `filled`, which is why the same `color='violet'` works there. Match it -- `filled` when a color is named, `default` when one is not, which is most of them. Eleven call sites were passing a color that could not reach a pixel: DonatePage:19, Files:421 the color the USER picked, thrown away Downloads:241,404,427,460 danger and blue on the download controls ControllerPage:326,408,1591 the service Open buttons FilePreview:71,541 The fallback is last, behind both `variant` and `role`, so `role='danger'` keeps its dashed night outline even when a color is also named; there is a test for that. Verified in the browser across all four themes: each icon button now matches the labelled button of the same color exactly, and an icon button with no color keeps the neutral default. In night and amber the hues collapse to brightnesses, as those themes intend. The gallery grows a color pair per hue, so a regression here is visible rather than silent. 68 suites / 1204 tests pass. --- app/src/components/ThemeSamplePage.js | 15 ++++++++++ app/src/components/ui/Button.tsx | 13 ++++++++- app/src/components/ui/ui.test.js | 42 +++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/app/src/components/ThemeSamplePage.js b/app/src/components/ThemeSamplePage.js index 156accdd..39e38bdd 100644 --- a/app/src/components/ThemeSamplePage.js +++ b/app/src/components/ThemeSamplePage.js @@ -356,6 +356,21 @@ export function ThemeSamplePage() { })}>Show a toast +
+ {/* An icon button takes a color the same way a labelled one does. It did + not used to: with no role it fell back to Mantine's `default` variant, + which reads only the default tokens, so a named color rendered exactly + like no color at all. The pair below is what says it still works -- + each row should read as one color, in every theme. */} + + {['violet', 'blue', 'yellow'].map(color =>
+ + +
)} + +
+
{['xs', 'sm', 'md', 'lg', 'xl'].map(size =>
(( aria-label={label} title={label} color={props.color ?? fromRole?.color} - variant={props.variant ?? fromRole?.variant ?? 'default'} + /* + * `default` only when nothing was asked for. + * + * Mantine's `default` variant draws itself entirely from `--mantine-color-default*` + * and never reads `color`, so `` rendered byte-identical + * to one with no props at all -- eleven call sites were passing a color that could + * not reach a pixel, two of them the color a user had picked. `Button` has no such + * fallback, which is why the same `color='violet'` works there: Mantine fills in + * `filled` on its own. Match it, and keep the neutral default for the icon buttons + * that name no color, which is most of them. + */ + variant={props.variant ?? fromRole?.variant ?? (props.color ? 'filled' : 'default')} className={[fromRole?.className, className].filter(Boolean).join(' ') || undefined} {...props} size={resolveSize(size)} diff --git a/app/src/components/ui/ui.test.js b/app/src/components/ui/ui.test.js index 26caf2a7..3d3f25e6 100644 --- a/app/src/components/ui/ui.test.js +++ b/app/src/components/ui/ui.test.js @@ -309,6 +309,48 @@ describe('Button', () => { expect(screen.getByRole('button', {name: 'Delete channel'})).toBeInTheDocument(); }); + + it('paints an icon button the color it was given', () => { + /* + * `IconButton` fell back to Mantine's `default` variant whenever no role was set, and + * that variant draws from `--mantine-color-default*` alone -- it never reads `color`. + * So a named color rendered byte-identical to no color at all, silently, at eleven + * call sites. `Button` was never affected: it leaves `variant` undefined and Mantine + * fills in `filled`, which is why the same `color='violet'` worked there. + */ + renderUI(<> + + + + ); + + const bg = (name, role = 'button') => + screen.getByRole(role, {name}).getAttribute('style') || ''; + + // The color reaches the background, and matches what the labelled Button already did. + expect(bg('Open it')).toContain('var(--mantine-color-violet-filled)'); + expect(bg('Labelled')).toContain('var(--mantine-color-violet-filled)'); + // An icon button that names no color keeps the neutral default -- most of them. + expect(bg('Plain')).toContain('var(--mantine-color-default)'); + expect(bg('Plain')).not.toContain('violet'); + }); + + it('lets a role and an explicit variant still win over a color', () => { + // The color fallback is the LAST resort: it must not outrank either of the two ways a + // call site already had to state a variant, or `role='danger'` would lose its dashed + // night outline the moment someone also named a color. + renderUI(<> + + + ); + + expect(screen.getByRole('button', {name: 'Roled'})) + .toHaveAttribute('data-variant', 'filled'); + expect(screen.getByRole('button', {name: 'Roled'})) + .toHaveClass('wrolpi-button-danger'); + expect(screen.getByRole('button', {name: 'Varianted'})) + .toHaveAttribute('data-variant', 'outline'); + }); }); describe('Message', () => {