Skip to content

Commit c912434

Browse files
authored
Validate theme() works in arbitray values (#6852)
* add tests to ensure theme value inside arbitrary values work * update changelog
1 parent b341813 commit c912434

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Improve `DEBUG` flag ([#6797](https://github.com/tailwindlabs/tailwindcss/pull/6797), [#6804](https://github.com/tailwindlabs/tailwindcss/pull/6804))
1313
- Ensure we can use `<` and `>` characters in modifiers ([#6851](https://github.com/tailwindlabs/tailwindcss/pull/6851))
14+
- Validate `theme()` works in arbitrary values ([#6852](https://github.com/tailwindlabs/tailwindcss/pull/6852))
1415

1516
## [3.0.8] - 2021-12-28
1617

tests/arbitrary-values.test.js

+46
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,49 @@ it('should support unescaped underscores in URLs', () => {
293293
`)
294294
})
295295
})
296+
297+
it('should be possible to read theme values in arbitrary values (without quotes)', () => {
298+
let config = {
299+
content: [{ raw: html`<div class="w-[theme(spacing.1)] w-[theme(spacing[0.5])]"></div>` }],
300+
theme: {
301+
spacing: {
302+
0.5: 'calc(.5 * .25rem)',
303+
1: 'calc(1 * .25rem)',
304+
},
305+
},
306+
}
307+
308+
return run('@tailwind utilities', config).then((result) => {
309+
return expect(result.css).toMatchFormattedCss(css`
310+
.w-\[theme\(spacing\.1\)\] {
311+
width: calc(1 * 0.25rem);
312+
}
313+
.w-\[theme\(spacing\[0\.5\]\)\] {
314+
width: calc(0.5 * 0.25rem);
315+
}
316+
`)
317+
})
318+
})
319+
320+
it('should be possible to read theme values in arbitrary values (with quotes)', () => {
321+
let config = {
322+
content: [{ raw: html`<div class="w-[theme('spacing.1')] w-[theme('spacing[0.5]')]"></div>` }],
323+
theme: {
324+
spacing: {
325+
0.5: 'calc(.5 * .25rem)',
326+
1: 'calc(1 * .25rem)',
327+
},
328+
},
329+
}
330+
331+
return run('@tailwind utilities', config).then((result) => {
332+
return expect(result.css).toMatchFormattedCss(css`
333+
.w-\[theme\(\'spacing\.1\'\)\] {
334+
width: calc(1 * 0.25rem);
335+
}
336+
.w-\[theme\(\'spacing\[0\.5\]\'\)\] {
337+
width: calc(0.5 * 0.25rem);
338+
}
339+
`)
340+
})
341+
})

0 commit comments

Comments
 (0)