Skip to content

Commit fa17b48

Browse files
authored
Merge pull request #911 from tailwindcss/fix-global-variants
Fix global variants not working when configs are merged
2 parents 7e7b6d9 + 0183b86 commit fa17b48

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

__tests__/resolveConfig.test.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,70 @@ test('variants key is merged instead of replaced', () => {
261261
})
262262
})
263263

264+
test('a global variants list replaces the default', () => {
265+
const userConfig = {
266+
variants: ['responsive', 'hover', 'focus', 'active'],
267+
}
268+
269+
const defaultConfig = {
270+
prefix: '-',
271+
important: false,
272+
separator: ':',
273+
theme: {
274+
colors: {
275+
'grey-darker': '#606f7b',
276+
'grey-dark': '#8795a1',
277+
grey: '#b8c2cc',
278+
'grey-light': '#dae1e7',
279+
'grey-lighter': '#f1f5f8',
280+
},
281+
fonts: {
282+
sans: ['system-ui', 'BlinkMacSystemFont', '-apple-system', 'Roboto', 'sans-serif'],
283+
serif: ['Constantia', 'Lucida Bright', 'Georgia', 'serif'],
284+
},
285+
screens: {
286+
sm: '500px',
287+
md: '750px',
288+
lg: '1000px',
289+
},
290+
},
291+
variants: {
292+
appearance: ['responsive'],
293+
backgroundAttachment: ['responsive'],
294+
borderCollapse: [],
295+
borderColors: ['responsive', 'hover', 'focus'],
296+
borderRadius: ['responsive'],
297+
},
298+
}
299+
300+
const result = resolveConfig([userConfig, defaultConfig])
301+
302+
expect(result).toEqual({
303+
prefix: '-',
304+
important: false,
305+
separator: ':',
306+
theme: {
307+
colors: {
308+
'grey-darker': '#606f7b',
309+
'grey-dark': '#8795a1',
310+
grey: '#b8c2cc',
311+
'grey-light': '#dae1e7',
312+
'grey-lighter': '#f1f5f8',
313+
},
314+
fonts: {
315+
sans: ['system-ui', 'BlinkMacSystemFont', '-apple-system', 'Roboto', 'sans-serif'],
316+
serif: ['Constantia', 'Lucida Bright', 'Georgia', 'serif'],
317+
},
318+
screens: {
319+
sm: '500px',
320+
md: '750px',
321+
lg: '1000px',
322+
},
323+
},
324+
variants: ['responsive', 'hover', 'focus', 'active'],
325+
})
326+
})
327+
264328
test('missing top level keys are pulled from the default config', () => {
265329
const userConfig = {}
266330

src/util/resolveConfig.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ export default function resolveConfig(configs) {
6565
return defaults(
6666
{
6767
theme: resolveFunctionKeys(mergeExtensions(defaults({}, ...map(configs, 'theme')))),
68-
variants: defaults({}, ...map(configs, 'variants')),
68+
variants: (firstVariants => {
69+
return Array.isArray(firstVariants)
70+
? firstVariants
71+
: defaults({}, ...map(configs, 'variants'))
72+
})(defaults({}, ...map(configs)).variants),
6973
},
7074
...configs
7175
)

0 commit comments

Comments
 (0)