Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Ensure classes are extracted when a variant precedes an arbitrary variant containing a quoted attribute selector (e.g. `focus-visible:[&:not([aria-selected="true"])]:bg-red-500`) ([#20374](https://github.com/tailwindlabs/tailwindcss/pull/20374))
- Fix negation of `theme()` in arbitrary values (e.g. `-m-[theme(margin.1)]`) ([#19928](https://github.com/tailwindlabs/tailwindcss/pull/19928))

## [3.4.19] - 2025-12-10

Expand Down
12 changes: 7 additions & 5 deletions src/util/negateValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ export default function negateValue(value) {
return value.replace(/^[+-]?/, (sign) => (sign === '-' ? '' : '-'))
}

// What functions we support negating numeric values for
// var() isn't inherently a numeric function but we support it anyway
// The trigonometric functions are omitted because you'll need to use calc(…) with them _anyway_
// to produce generally useful results and that will be covered already
let numericFunctions = ['var', 'calc', 'min', 'max', 'clamp']
// What functions we support negating numeric values for var() and theme()
// aren't inherently a numeric function but we support it anyway
//
// The trigonometric functions are omitted because you'll need to use calc(…)
// with them _anyway_ to produce generally useful results and that will be
// covered already
let numericFunctions = ['var', 'theme', 'calc', 'min', 'max', 'clamp']

for (const fn of numericFunctions) {
if (value.includes(`${fn}(`)) {
Expand Down
19 changes: 19 additions & 0 deletions tests/arbitrary-values.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,25 @@ it('should be possible to read theme values in arbitrary values (without quotes)
})
})

it('should be possible to negate theme values in arbitrary values with negative modifier', () => {
let config = {
content: [{ raw: html`<div class="-mt-[theme(spacing.1)]"></div>` }],
theme: {
spacing: {
1: '0.25rem',
},
},
}

return run('@tailwind utilities', config).then((result) => {
return expect(result.css).toMatchFormattedCss(css`
.-mt-\[theme\(spacing\.1\)\] {
margin-top: -0.25rem;
}
`)
})
})

it('should be possible to read theme values in arbitrary values (with quotes)', () => {
let config = {
content: [{ raw: html`<div class="w-[theme('spacing.1')] w-[theme('spacing[0.5]')]"></div>` }],
Expand Down
4 changes: 4 additions & 0 deletions tests/negateValue.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ test('values that cannot be negated become undefined', () => {
expect(negateValue('auto')).toBeUndefined()
expect(negateValue('cover')).toBeUndefined()
})

test('it negates theme() function calls', () => {
expect(negateValue('theme(margin.1)')).toEqual('calc(theme(margin.1) * -1)')
})
Loading