Skip to content

chore(Label): migrate to CSS Modules with visual regression baseline#1047

Open
DreaminDani wants to merge 6 commits into
mainfrom
chore/migrate-label-css-modules
Open

chore(Label): migrate to CSS Modules with visual regression baseline#1047
DreaminDani wants to merge 6 commits into
mainfrom
chore/migrate-label-css-modules

Conversation

@DreaminDani
Copy link
Copy Markdown
Contributor

@DreaminDani DreaminDani commented May 27, 2026

Commits

  • test(Label): add visual regression baseline before CSS Modules migration — adds stories, Playwright spec, and fresh PNG snapshots that capture the current rendering.
  • chore(Label): migrate styling from styled-components to CSS Modules — replaces styled-components with .module.css + cva/cn. DOM-identical, byte-for-byte visual parity verified.

Verification

  • yarn test:visual tests/utils/label.spec.ts passes with zero snapshot regenerations
  • yarn test Label, yarn lint:css, yarn lint:code, yarn build all green
  • grep -r 'styled-components' src/components/Label/ empty

Closes CUI-40


Note

Low Risk
Styling refactor with explicit specificity safeguards and new visual tests; no auth, data, or API surface changes.

Overview
Label styling moves from styled-components to CSS Modules (Label.module.css) with cva/cn for error and disabled, plus optional className. Design tokens are expressed as CSS variables; :where() on hover/focus rules keeps specificity aligned with the old setup so InputWrapper’s labelColor override still wins when it should.

Storybook adds a label-harness and Default / Disabled / Error stories. Playwright snapshots cover light/dark variants and hover/focus-within. TextField label-color tests no longer assert computed theme colors in jsdom (CSS modules aren’t loaded there); they still check labelColor inline override behavior.

Patch changeset only; intended no visual/behavior change.

Reviewed by Cursor Bugbot for commit 63b414a. Bugbot is set up for automated code reviews on this repo. Configure here.

@DreaminDani DreaminDani self-assigned this May 27, 2026
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 27, 2026

🦋 Changeset detected

Latest commit: 63b414a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@clickhouse/click-ui Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

The previous assertion relied on styled-components injecting the
default label color (rgb(179, 182, 189)) into the jsdom stylesheet at
render time. Now that Label uses CSS Modules, jsdom does not load the
`.label { color: var(--click-field-color-label-default) }` rule, and
the computed color falls back to canvastext.

The test's actual intent is to verify that no `labelColor` override is
applied when the prop is unset. Assert that directly via the absence of
an inline color style. Default-color rendering is covered by visual
regression in tests/display/label.spec.ts.

The second test (custom labelColor) is unchanged: the InputWrapper's
StyledLabel wrapper is still styled-components and continues to inject
its color rule into jsdom.
Comment thread src/components/TextField/TextField.test.tsx Outdated
…ilures

- Prettier wants the Label component destructure on one line; reformat
  to match.
- The earlier `getAttribute('style')` assertion returned `null` when no
  style attribute was present, which `.not.toContain('color')` rejected.
  Use `element.style.color` instead, which returns `''` for "no inline
  color set" — the actual semantic we want to verify.
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit ea67c42. Configure here.

Comment thread src/components/Label/Label.module.css
…olor still wins

Bugbot flagged that the new .label.label_error and .label.label_disabled
compound selectors raised modifier specificity to 0-2-0, while the
original styled-components emitted state rules at single-class 0-1-0.
InputWrapper's StyledLabel applies the `labelColor` override via a
styled-components-generated single-class selector (0-1-0). In the
original, `labelColor` won by cascade order; with the compound
selectors it was silently overridden whenever error or disabled was
active.

Refactor the pseudo-class rules to use :where(), which contributes
zero specificity, and drop the .label.label_modifier compound form for
single-class .label_error / .label_disabled. The modifiers now sit at
0-1-0 — tied with StyledLabel's labelColor but losing on source order,
which restores the original behavior where labelColor always wins.

Label-in-isolation rendering is unchanged: 10/10 visual snapshots
match byte-for-byte. The fix is observable only in combination with
InputWrapper, which isn't covered by Label's own spec.
Match the convention established in PRs #1045, #1046, #1048, and
#1050 and codified in the migration skill: tests/utils/ is reserved
for shared helpers like getStoryUrl, primitives go in tests/display/.

Visual regression remains byte-for-byte: 10/10 snapshots match without
regeneration.
@workflow-authentication-public
Copy link
Copy Markdown
Contributor

Storybook Preview Deployed

✅ Preview URL: https://click-p68wuoht6-clickhouse.vercel.app

Built from commit: 35d8940088f2c3206d6fd94a4904e7297676f9d3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant