Skip to content

Commit 262e99e

Browse files
authored
Support arrays in JS config values (#14343)
This PR fixes a small bug where theme values could not be defined as arrays in JS config files, for example: ```js export default { theme: { fontFamily: { sans: ['Inter', 'system-ui', 'sans-serif'], }, }, } ``` --------- Co-authored-by: Adam Wathan <[email protected]>
1 parent a3a16e6 commit 262e99e

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2222
- Ensure theme values overridden with `reference` values don't generate stale CSS variables ([#14327](https://github.com/tailwindlabs/tailwindcss/pull/14327))
2323
- Don’t suggest named opacity modifiers in intellisense ([#14339](https://github.com/tailwindlabs/tailwindcss/pull/14339))
2424
- Fix a crash with older Node.js versions ([#14342](https://github.com/tailwindlabs/tailwindcss/pull/14342))
25+
- Support defining theme values as arrays of strings in JS config files ([#14343](https://github.com/tailwindlabs/tailwindcss/pull/14343))
2526

2627
## [4.0.0-alpha.21] - 2024-09-02
2728

packages/tailwindcss/src/compat/apply-config-to-theme.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ test('Config values can be merged into the theme', ({ expect }) => {
1818
},
1919
},
2020

21+
fontFamily: {
22+
sans: ['Inter', 'system-ui', 'sans-serif'],
23+
mono: ['Potato Mono', { fontVariationSettings: '"XHGT" 0.7' }],
24+
},
25+
2126
fontSize: {
2227
sm: '0.875rem',
2328
base: [
@@ -34,6 +39,11 @@ test('Config values can be merged into the theme', ({ expect }) => {
3439

3540
expect(theme.resolve('primary', ['--color'])).toEqual('#c0ffee')
3641
expect(theme.resolve('red-500', ['--color'])).toEqual('red')
42+
expect(theme.resolve('sans', ['--font-family'])).toEqual('Inter, system-ui, sans-serif')
43+
expect(theme.resolveWith('mono', ['--font-family'], ['--font-variation-settings'])).toEqual([
44+
'Potato Mono',
45+
{ '--font-variation-settings': '"XHGT" 0.7' },
46+
])
3747
expect(theme.resolve('sm', ['--font-size'])).toEqual('0.875rem')
3848
expect(theme.resolve('base', ['--font-size'])).toEqual('1rem')
3949
expect(theme.resolveWith('base', ['--font-size'], ['--line-height'])).toEqual([

packages/tailwindcss/src/compat/apply-config-to-theme.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ function themeableValues(config: ResolvedConfig['theme']): [string[], unknown][]
3737

3838
return WalkAction.Skip
3939
}
40+
41+
if (Array.isArray(value) && value.every((v) => typeof v === 'string')) {
42+
toAdd.push([path, value.join(', ')])
43+
return WalkAction.Skip
44+
}
4045
})
4146

4247
return toAdd

0 commit comments

Comments
 (0)