Skip to content

Commit edf47a0

Browse files
authored
Fix theme(fontFamily.*) when family contains fontFeatureSettings config (#9217)
1 parent 914a4b6 commit edf47a0

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

src/util/transformThemeValue.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import postcss from 'postcss'
2+
import isPlainObject from './isPlainObject'
23

34
export default function transformThemeValue(themeSection) {
45
if (['fontSize', 'outline'].includes(themeSection)) {
@@ -10,9 +11,16 @@ export default function transformThemeValue(themeSection) {
1011
}
1112
}
1213

14+
if (themeSection === 'fontFamily') {
15+
return (value) => {
16+
if (typeof value === 'function') value = value({})
17+
let families = Array.isArray(value) && isPlainObject(value[1]) ? value[0] : value
18+
return Array.isArray(families) ? families.join(', ') : families
19+
}
20+
}
21+
1322
if (
1423
[
15-
'fontFamily',
1624
'boxShadow',
1725
'transitionProperty',
1826
'transitionDuration',

tests/evaluateTailwindFunctions.test.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,45 @@ test('font-family values are joined when an array', () => {
610610
})
611611
})
612612

613+
test('font-family values are retrieved without font-feature-settings', () => {
614+
let input = css`
615+
.heading-1 {
616+
font-family: theme('fontFamily.sans');
617+
}
618+
.heading-2 {
619+
font-family: theme('fontFamily.serif');
620+
}
621+
.heading-3 {
622+
font-family: theme('fontFamily.mono');
623+
}
624+
`
625+
626+
let output = css`
627+
.heading-1 {
628+
font-family: Inter;
629+
}
630+
.heading-2 {
631+
font-family: Times, serif;
632+
}
633+
.heading-3 {
634+
font-family: Menlo, monospace;
635+
}
636+
`
637+
638+
return run(input, {
639+
theme: {
640+
fontFamily: {
641+
sans: ['Inter', { fontFeatureSettings: '"cv11"' }],
642+
serif: [['Times', 'serif'], { fontFeatureSettings: '"cv11"' }],
643+
mono: ['Menlo, monospace', { fontFeatureSettings: '"cv11"' }],
644+
},
645+
},
646+
}).then((result) => {
647+
expect(result.css).toMatchCss(output)
648+
expect(result.warnings().length).toBe(0)
649+
})
650+
})
651+
613652
test('box-shadow values are joined when an array', () => {
614653
let input = css`
615654
.element {

0 commit comments

Comments
 (0)