fix: replace deprecated CSS custom properties with new names + old as fallback#7758
fix: replace deprecated CSS custom properties with new names + old as fallback#7758
Conversation
|
…s and fallbacks Agent-Logs-Url: https://github.com/primer/react/sessions/de27d8ab-284e-42bb-824a-0320a7dcf3fa Co-authored-by: lukasoppermann <813754+lukasoppermann@users.noreply.github.com>
Agent-Logs-Url: https://github.com/primer/react/sessions/de27d8ab-284e-42bb-824a-0320a7dcf3fa Co-authored-by: lukasoppermann <813754+lukasoppermann@users.noreply.github.com>
lukasoppermann
left a comment
There was a problem hiding this comment.
Makes sense from my side, @eng please verify this.
|
There was a problem hiding this comment.
Pull request overview
Updates deprecated focus-related CSS custom property usages across Primer React, the PostCSS preset mixins, and MCP token guidance text to prefer the new token names while retaining the deprecated names as fallbacks for backwards compatibility.
Changes:
- Replace
var(--focus-outlineColor)withvar(--focus-outline-color, var(--focus-outlineColor))in React CSS Modules and PostCSS mixin defaults. - Replace
var(--outline-focus-offset)withvar(--focus-outline-offset, var(--outline-focus-offset))in MCP token rules and example snippets. - Update
postcss-preset-primersnapshots to reflect the newly compiled fallback chain output.
Show a summary per file
| File | Description |
|---|---|
| packages/react/src/ToggleSwitch/ToggleSwitch.module.css | Updates focus-visible outline color to use the new token with deprecated fallback. |
| packages/react/src/SelectPanel/SelectPanel.examples.stories.module.css | Updates example outline color to use the new token with deprecated fallback. |
| packages/postcss-preset-primer/src/mixins/focusOutlineOnEmphasis.css | Updates mixin default outline color to new token with deprecated fallback. |
| packages/postcss-preset-primer/src/mixins/focusOutline.css | Updates mixin default outline color to new token with deprecated fallback. |
| packages/postcss-preset-primer/src/tests/snapshots/preset.test.ts.snap | Updates compiled mixin output snapshots to include the new fallback chain. |
| packages/mcp/src/primitives.ts | Updates MCP token usage rules/examples to use new outline offset token with deprecated fallback. |
Copilot's findings
- Files reviewed: 6/6 changed files
- Comments generated: 2
| @define-mixin focusOutlineOnEmphasis $outlineOffset: -2px, | ||
| $outlineColor: var(--focus-outline-color, var(--focus-outlineColor)) { |
There was a problem hiding this comment.
For consistency with the other mixins in this directory (e.g. focusOutline), keep the @define-mixin signature on a single line unless there’s a strong reason to wrap it. This makes future diffs smaller and keeps these small mixin files easier to scan.
| @define-mixin focusOutlineOnEmphasis $outlineOffset: -2px, | |
| $outlineColor: var(--focus-outline-color, var(--focus-outlineColor)) { | |
| @define-mixin focusOutlineOnEmphasis $outlineOffset: -2px, $outlineColor: var(--focus-outline-color, var(--focus-outlineColor)) { |
|
|
||
| exports[`postcss-preset-primer > mixins > @mixin buttonReset 1`] = `".selector{align-items:center;appearance:none;background:none;border:0;color:inherit;cursor:pointer;display:inline-flex;font:inherit;margin:0;padding:0;text-align:start}.selector::-moz-focus-inner{border:0}"`; | ||
| exports[`postcss-preset-primer > mixins > @mixin buttonReset 1`] = | ||
| `".selector{align-items:center;appearance:none;background:none;border:0;color:inherit;cursor:pointer;display:inline-flex;font:inherit;margin:0;padding:0;text-align:start}.selector::-moz-focus-inner{border:0}"` |
There was a problem hiding this comment.
The snapshot update includes unrelated formatting churn (line wrapping / semicolon removal) for snapshots whose CSS output didn’t change. To keep diffs focused and reduce merge conflicts, consider reverting those purely-formatting changes and only updating the snapshot strings that actually changed due to the new focus outline token chain.
| `".selector{align-items:center;appearance:none;background:none;border:0;color:inherit;cursor:pointer;display:inline-flex;font:inherit;margin:0;padding:0;text-align:start}.selector::-moz-focus-inner{border:0}"` | |
| `".selector{align-items:center;appearance:none;background:none;border:0;color:inherit;cursor:pointer;display:inline-flex;font:inherit;margin:0;padding:0;text-align:start;}.selector::-moz-focus-inner{border:0;}"` |
| /* Focus styles */ | ||
| &:focus-visible { | ||
| outline: 2px solid var(--focus-outlineColor); | ||
| outline: 2px solid var(--focus-outline-color, var(--focus-outlineColor)); |
There was a problem hiding this comment.
| outline: 2px solid var(--focus-outline-color, var(--focus-outlineColor)); | |
| outline: var(--focus-outline); |
| .CustomActionListItem[data-is-active-descendant='activated-directly'] { | ||
| background-color: transparent; | ||
| outline: 2px solid var(--focus-outlineColor, var(--color-accent-emphasis)); | ||
| outline: 2px solid var(--focus-outline-color, var(--focus-outlineColor)); |
There was a problem hiding this comment.
| outline: 2px solid var(--focus-outline-color, var(--focus-outlineColor)); | |
| outline: var(--focus-outline); |
Updates usages of three deprecated CSS custom properties to use the new token names while keeping the old names as fallbacks for backwards compatibility.
Replacements
var(--outline-focus-offset)var(--focus-outline-offset, var(--outline-focus-offset))var(--focus-outlineColor)var(--focus-outline-color, var(--focus-outlineColor))Files changed
packages/mcp/src/primitives.ts— golden example CSS snippet and inline rule description (2×--outline-focus-offset)packages/postcss-preset-primer/src/mixins/focusOutline.css— mixin default param$outlineColorpackages/postcss-preset-primer/src/mixins/focusOutlineOnEmphasis.css— samepackages/react/src/ToggleSwitch/ToggleSwitch.module.css—:focus-visibleoutlinepackages/react/src/SelectPanel/SelectPanel.examples.stories.module.css— drops the hard-coded--color-accent-emphasisfallback in favour of the chained old tokenSnapshot for
postcss-preset-primerupdated to reflect compiled mixin output:Changelog
New
Changed
--outline-focus-offsetand--focus-outlineColornow reference the new token names (--focus-outline-offset,--focus-outline-color) with the deprecated names retained as fallbacks.Removed
Rollout strategy
Testing & Reviewing
postcss-preset-primerunit tests cover the mixin output and pass with the updated snapshots. No visual or behavioural changes — fallback chain ensures the old tokens continue to resolve correctly until removed.Merge checklist
Original prompt
Goal
Replace deprecated CSS custom property names with their new equivalents, using the old name as a fallback for backwards compatibility.
Replacements to make
var(--outline-focus-offset)var(--focus-outline-offset, var(--outline-focus-offset))var(--outline-focus-width)var(--focus-outline-width, var(--outline-focus-width))var(--focus-outlineColor)var(--focus-outline-color, var(--focus-outlineColor))Files to update
The following files have been identified as needing changes:
packages/mcp/src/primitives.ts— Line 511 containsvar(--outline-focus-offset)inside a template string (the golden example CSS snippet):Also line 440 contains
var(--outline-focus-offset)in a comment/rule string:Update both occurrences.
packages/postcss-preset-primer/src/mixins/focusOutline.css— Containsvar(--focus-outlineColor)as a default parameter value:packages/postcss-preset-primer/src/mixins/focusOutlineOnEmphasis.css— Containsvar(--focus-outlineColor)as a default parameter value:packages/react/src/ToggleSwitch/ToggleSwitch.module.css— Containsvar(--focus-outlineColor)in the:focus-visiblerule:packages/react/src/SelectPanel/SelectPanel.examples.stories.module.css— Containsvar(--focus-outlineColor, ...)— already has a fallback but with the wrong new token name; update the first argument:This should become:
Wait — on reflection, if it already has a non-token fallback value, just prepend the new token name as the primary:
(The
var(--color-accent-emphasis)fallback can be dropped in favour of the chained old token as fallback.)Snapshot update
The file
packages/postcss-preset-primer/src/__tests__/__snapshots__/preset.test.ts.snapcontains hardcoded snapshots of the compiled mixin output. After changing the mixin files, run the test suite to regenerate snapshots, or manually update the relevant snapshot strings to reflect the newvar(--focus-outline-color, var(--focus-outlineColor, ...))output.Important
var(--outline-focus-offset)→var(--focus-outline-offset, var(--outline-focus-offset)), every barevar(--outline-focus-width)→var(--focus-outline-width, var(--outline-focus-width)), every barevar(--focus-outlineColor)→var(--focus-outline-color, var(--focus-outlineColor)).The following is the prior conversation context from the user's chat exploration (may be truncated):
User: search for
outline-focus-offsetandoutline-focus-widthcss variables in any repo within the primer or github org.Lists of the existing usages per repo and a link to the search query. Include count of usage and in how many files.
Assistant: Here's a breakdown of all findings for
--outline-focus-offsetand--outline-focus-widthacross theprimerandgithuborgs:org:primer🔗 View search in GitHub
primer/primitivesDESIGN_TOKENS_GUIDE.md(docs example),ColorTokenSwatch.css(--outline-focus-widthusage)primer/reactpackages/mcp/src/primitives.ts(docs/example string referencing--outline-focus-offset)primer/primitives-vscode-extensionsrc/data/rules.ts(token matcher config),src/data/properties-generated.ts(generated token definitions)primer/tailwind-configpackages/tailwind-config/src/border.css— maps both tokens to Tailwind CSS theme varsorg:github🔗 View search in GitHub
github/github-ui](https://github....This pull request was created from Copilot chat.