Skip to content

Fix negation of theme() in arbitrary values - #19928

Merged
RobinMalfait merged 4 commits into
tailwindlabs:v3from
snaptopixel:fix/negate-theme-arbitrary-value
Aug 3, 2026
Merged

RobinMalfait merged 4 commits into
tailwindlabs:v3from
snaptopixel:fix/negate-theme-arbitrary-value

Conversation

@snaptopixel

Copy link
Copy Markdown

Problem

Using a negative modifier with theme() inside an arbitrary value produces no CSS output.

  • ✅ ms-[theme(margin.1)] — works
  • ✅ -ms-[10px] — works
  • ❌ -ms-[theme(margin.1)] — no output

Cause

negateValue() in src/util/negateValue.js doesn't recognize theme() as a negatable function. It falls through all conditions and returns undefined, causing the utility to be silently dropped.

Fix

Added 'theme' to the numericFunctions list so theme() values get wrapped in calc(... * -1), which the PostCSS theme() resolver then processes downstream.

Tests

  • Unit test (negateValue.test.js): negateValue('theme(margin.1)') returns calc(theme(margin.1) * -1)
  • Integration test (arbitrary-values.test.js): -mt-[theme(spacing.1)] produces margin-top: -0.25rem

When using a negative modifier with theme() inside an arbitrary value
(e.g. `-ms-[theme(margin.1)]`), no CSS was generated because
`negateValue` did not recognize `theme()` as a negatable function.

Added `theme` to the list of numeric functions in `negateValue` so
that `theme()` values are wrapped in `calc(... * -1)` and then
resolved by the PostCSS theme() plugin downstream.
@snaptopixel
snaptopixel requested a review from a team as a code owner April 13, 2026 18:12
@RobinMalfait

RobinMalfait commented Apr 13, 2026 •

Copy link
Copy Markdown
Contributor

Edit: This is for Tailwind CSS v3.

Hey! Thanks for the PR, but where do you see this issue? This should work as-is today already:
image
https://play.tailwindcss.com/bGXXIU9Wai

@RobinMalfait
RobinMalfait enabled auto-merge (squash) August 3, 2026 14:11

@RobinMalfait RobinMalfait left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks!

Will be available in the next v3 release.

@RobinMalfait
RobinMalfait merged commit 7a836d8 into tailwindlabs:v3 Aug 3, 2026
29 checks passed
@greptile-apps

greptile-apps Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

The PR appears safe to merge, with focused implementation and end-to-end coverage for the reported failure.

The changed function now preserves theme() through negation as a valid calc expression, after which the existing resolver substitutes the configured numeric value; no concrete valid input was found that regresses because of this change.

Reviews (1): Last reviewed commit: "update changelog" | Re-trigger Greptile

@snaptopixel

Copy link
Copy Markdown
Author

Thanks for merging @RobinMalfait!

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.

2 participants