Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/util/negateValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function negateValue(value) {
// 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']
let numericFunctions = ['var', 'calc', 'min', 'max', 'clamp', 'theme']

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)')
})