Skip to content

Commit a7e26a8

Browse files
authored
Merge pull request #360 from dcastil/feature/359/add-support-for-tailwind-css-v3.4
Add support for Tailwind CSS v3.4
2 parents 381f117 + f283c08 commit a7e26a8

File tree

5 files changed

+96
-15
lines changed

5 files changed

+96
-15
lines changed

docs/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ twMerge('px-2 py-1 bg-red hover:bg-dark-red', 'p-3 bg-[#B91C1C]')
1616
// → 'hover:bg-dark-red p-3 bg-[#B91C1C]'
1717
```
1818

19-
- Supports Tailwind v3.0 up to v3.3 (if you use Tailwind v2, use [tailwind-merge v0.9.0](https://github.com/dcastil/tailwind-merge/tree/v0.9.0))
20-
- Works in all modern browsers and Node >=12
19+
- Supports Tailwind v3.0 up to v3.4 (if you use Tailwind v2, use [tailwind-merge v0.9.0](https://github.com/dcastil/tailwind-merge/tree/v0.9.0))
20+
- Works in all modern browsers and maintained Node versions
2121
- Fully typed
2222
- [Check bundle size on Bundlephobia](https://bundlephobia.com/package/tailwind-merge)
2323

src/lib/default-config.ts

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,12 @@ export function getDefaultConfig() {
193193
* Floats
194194
* @see https://tailwindcss.com/docs/float
195195
*/
196-
float: [{ float: ['right', 'left', 'none'] }],
196+
float: [{ float: ['right', 'left', 'none', 'start', 'end'] }],
197197
/**
198198
* Clear
199199
* @see https://tailwindcss.com/docs/clear
200200
*/
201-
clear: [{ clear: ['left', 'right', 'both', 'none'] }],
201+
clear: [{ clear: ['left', 'right', 'both', 'none', 'start', 'end'] }],
202202
/**
203203
* Isolation
204204
* @see https://tailwindcss.com/docs/isolation
@@ -581,20 +581,35 @@ export function getDefaultConfig() {
581581
* Width
582582
* @see https://tailwindcss.com/docs/width
583583
*/
584-
w: [{ w: ['auto', 'min', 'max', 'fit', isArbitraryValue, spacing] }],
584+
w: [
585+
{
586+
w: [
587+
'auto',
588+
'min',
589+
'max',
590+
'fit',
591+
'svw',
592+
'lvw',
593+
'dvw',
594+
isArbitraryValue,
595+
spacing,
596+
],
597+
},
598+
],
585599
/**
586600
* Min-Width
587601
* @see https://tailwindcss.com/docs/min-width
588602
*/
589-
'min-w': [{ 'min-w': ['min', 'max', 'fit', isArbitraryValue, isLength] }],
603+
'min-w': [{ 'min-w': [isArbitraryValue, spacing, 'min', 'max', 'fit'] }],
590604
/**
591605
* Max-Width
592606
* @see https://tailwindcss.com/docs/max-width
593607
*/
594608
'max-w': [
595609
{
596610
'max-w': [
597-
'0',
611+
isArbitraryValue,
612+
spacing,
598613
'none',
599614
'full',
600615
'min',
@@ -603,25 +618,47 @@ export function getDefaultConfig() {
603618
'prose',
604619
{ screen: [isTshirtSize] },
605620
isTshirtSize,
606-
isArbitraryValue,
607621
],
608622
},
609623
],
610624
/**
611625
* Height
612626
* @see https://tailwindcss.com/docs/height
613627
*/
614-
h: [{ h: [isArbitraryValue, spacing, 'auto', 'min', 'max', 'fit'] }],
628+
h: [
629+
{
630+
h: [
631+
isArbitraryValue,
632+
spacing,
633+
'auto',
634+
'min',
635+
'max',
636+
'fit',
637+
'svh',
638+
'lvh',
639+
'dvh',
640+
],
641+
},
642+
],
615643
/**
616644
* Min-Height
617645
* @see https://tailwindcss.com/docs/min-height
618646
*/
619-
'min-h': [{ 'min-h': ['min', 'max', 'fit', isLength, isArbitraryValue] }],
647+
'min-h': [
648+
{ 'min-h': [isArbitraryValue, spacing, 'min', 'max', 'fit', 'svh', 'lvh', 'dvh'] },
649+
],
620650
/**
621651
* Max-Height
622652
* @see https://tailwindcss.com/docs/max-height
623653
*/
624-
'max-h': [{ 'max-h': [isArbitraryValue, spacing, 'min', 'max', 'fit'] }],
654+
'max-h': [
655+
{ 'max-h': [isArbitraryValue, spacing, 'min', 'max', 'fit', 'svh', 'lvh', 'dvh'] },
656+
],
657+
/**
658+
* Size
659+
* @see https://tailwindcss.com/docs/size
660+
*/
661+
size: [{ size: [isArbitraryValue, spacing, 'auto', 'min', 'max', 'fit'] }],
625662
// Typography
626663
/**
627664
* Font Size
@@ -811,6 +848,11 @@ export function getDefaultConfig() {
811848
* @see https://tailwindcss.com/docs/text-overflow
812849
*/
813850
'text-overflow': ['truncate', 'text-ellipsis', 'text-clip'],
851+
/**
852+
* Text Wrap
853+
* @see https://tailwindcss.com/docs/text-wrap
854+
*/
855+
'text-wrap': [{ text: ['wrap', 'nowrap', 'balance', 'pretty'] }],
814856
/**
815857
* Text Indent
816858
* @see https://tailwindcss.com/docs/text-indent
@@ -1468,7 +1510,7 @@ export function getDefaultConfig() {
14681510
* Appearance
14691511
* @see https://tailwindcss.com/docs/appearance
14701512
*/
1471-
appearance: ['appearance-none'],
1513+
appearance: [{ appearance: ['none', 'auto'] }],
14721514
/**
14731515
* Cursor
14741516
* @see https://tailwindcss.com/docs/cursor
@@ -1712,6 +1754,11 @@ export function getDefaultConfig() {
17121754
* @see https://tailwindcss.com/docs/screen-readers
17131755
*/
17141756
sr: ['sr-only', 'not-sr-only'],
1757+
/**
1758+
* Forced Color Adjust
1759+
* @see https://tailwindcss.com/docs/forced-color-adjust
1760+
*/
1761+
'forced-color-adjust': [{ 'forced-color-adjust': ['auto', 'none'] }],
17151762
},
17161763
conflictingClassGroups: {
17171764
overflow: ['overflow-x', 'overflow-y'],
@@ -1727,6 +1774,7 @@ export function getDefaultConfig() {
17271774
m: ['mx', 'my', 'ms', 'me', 'mt', 'mr', 'mb', 'ml'],
17281775
mx: ['mr', 'ml'],
17291776
my: ['mt', 'mb'],
1777+
size: ['w', 'h'],
17301778
'font-size': ['leading'],
17311779
'fvn-normal': [
17321780
'fvn-ordinal',

src/lib/types.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ export type DefaultClassGroupIds =
223223
| 'font-smoothing'
224224
| 'font-style'
225225
| 'font-weight'
226+
| 'forced-color-adjust'
226227
| 'fvn-figure'
227228
| 'fvn-fraction'
228229
| 'fvn-normal'
@@ -360,6 +361,7 @@ export type DefaultClassGroupIds =
360361
| 'shadow-color'
361362
| 'shadow'
362363
| 'shrink'
364+
| 'size'
363365
| 'skew-x'
364366
| 'skew-y'
365367
| 'snap-align'
@@ -384,11 +386,12 @@ export type DefaultClassGroupIds =
384386
| 'text-opacity'
385387
| 'text-overflow'
386388
| 'text-transform'
389+
| 'text-wrap'
387390
| 'top'
388-
| 'touch'
391+
| 'touch-pz'
389392
| 'touch-x'
390393
| 'touch-y'
391-
| 'touch-pz'
394+
| 'touch'
392395
| 'tracking'
393396
| 'transform-origin'
394397
| 'transform'

tests/class-map.test.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ test('class map has correct class groups at first part', () => {
112112
float: ['float'],
113113
flow: ['display'],
114114
font: ['font-family', 'font-weight'],
115+
forced: ['forced-color-adjust'],
115116
from: ['gradient-from', 'gradient-from-pos'],
116117
gap: ['gap', 'gap-x', 'gap-y'],
117118
grayscale: ['grayscale'],
@@ -233,6 +234,7 @@ test('class map has correct class groups at first part', () => {
233234
sepia: ['sepia'],
234235
shadow: ['shadow', 'shadow-color'],
235236
shrink: ['shrink'],
237+
size: ['size'],
236238
skew: ['skew-x', 'skew-y'],
237239
slashed: ['fvn-slashed-zero'],
238240
snap: ['snap-align', 'snap-stop', 'snap-strictness', 'snap-type'],
@@ -246,7 +248,14 @@ test('class map has correct class groups at first part', () => {
246248
subpixel: ['font-smoothing'],
247249
table: ['display', 'table-layout'],
248250
tabular: ['fvn-spacing'],
249-
text: ['font-size', 'text-alignment', 'text-color', 'text-opacity', 'text-overflow'],
251+
text: [
252+
'font-size',
253+
'text-alignment',
254+
'text-color',
255+
'text-opacity',
256+
'text-overflow',
257+
'text-wrap',
258+
],
250259
to: ['gradient-to', 'gradient-to-pos'],
251260
top: ['top'],
252261
touch: ['touch', 'touch-pz', 'touch-x', 'touch-y'],

tests/tailwind-css-versions.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,24 @@ test('supports Tailwind CSS v3.3 features', () => {
3434
expect(twMerge('content-normal content-center content-stretch')).toBe('content-stretch')
3535
expect(twMerge('whitespace-nowrap whitespace-break-spaces')).toBe('whitespace-break-spaces')
3636
})
37+
38+
test('supports Tailwind CSS v3.4 features', () => {
39+
expect(twMerge('h-svh h-dvh w-svw w-dvw')).toBe('h-dvh w-dvw')
40+
expect(
41+
twMerge(
42+
'has-[[data-potato]]:p-1 has-[[data-potato]]:p-2 group-has-[:checked]:grid group-has-[:checked]:flex',
43+
),
44+
).toBe('has-[[data-potato]]:p-2 group-has-[:checked]:flex')
45+
expect(twMerge('text-wrap text-pretty')).toBe('text-pretty')
46+
expect(twMerge('w-5 h-3 size-10 w-12')).toBe('size-10 w-12')
47+
expect(twMerge('grid-cols-2 grid-cols-subgrid grid-rows-5 grid-rows-subgrid')).toBe(
48+
'grid-cols-subgrid grid-rows-subgrid',
49+
)
50+
expect(twMerge('min-w-0 min-w-50 min-w-px max-w-0 max-w-50 max-w-px')).toBe('min-w-px max-w-px')
51+
expect(twMerge('forced-color-adjust-none forced-color-adjust-auto')).toBe(
52+
'forced-color-adjust-auto',
53+
)
54+
expect(twMerge('appearance-none appearance-auto')).toBe('appearance-auto')
55+
expect(twMerge('float-start float-end clear-start clear-end')).toBe('float-end clear-end')
56+
expect(twMerge('*:p-10 *:p-20 hover:*:p-10 hover:*:p-20')).toBe('*:p-20 hover:*:p-20')
57+
})

0 commit comments

Comments
 (0)