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', () => {