From e20a2d31bec2cfdb816f3a9f609e417a95a3f395 Mon Sep 17 00:00:00 2001 From: Dany Castillo <31006608+dcastil@users.noreply.github.com> Date: Mon, 18 Sep 2023 20:50:42 +0200 Subject: [PATCH 1/2] split touch class group into touch, touch-x, touch-y and touch-pz with the correct conflicts between classes --- src/lib/default-config.ts | 35 ++++++++++++++++++++++++++++------- src/lib/types.ts | 3 +++ 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/lib/default-config.ts b/src/lib/default-config.ts index 8c48a964..451242c8 100644 --- a/src/lib/default-config.ts +++ b/src/lib/default-config.ts @@ -1652,15 +1652,32 @@ export function getDefaultConfig() { */ touch: [ { - touch: [ - 'auto', - 'none', - 'pinch-zoom', - 'manipulation', - { pan: ['x', 'left', 'right', 'y', 'up', 'down'] }, - ], + touch: ['auto', 'none', 'manipulation'], + }, + ], + /** + * Touch Action X + * @see https://tailwindcss.com/docs/touch-action + */ + 'touch-x': [ + { + 'touch-pan': ['x', 'left', 'right'], }, ], + /** + * Touch Action Y + * @see https://tailwindcss.com/docs/touch-action + */ + 'touch-y': [ + { + 'touch-pan': ['y', 'up', 'down'], + }, + ], + /** + * Touch Action Pinch Zoom + * @see https://tailwindcss.com/docs/touch-action + */ + 'touch-pz': ['touch-pinch-zoom'], /** * User Select * @see https://tailwindcss.com/docs/user-select @@ -1788,6 +1805,10 @@ export function getDefaultConfig() { ], 'scroll-px': ['scroll-pr', 'scroll-pl'], 'scroll-py': ['scroll-pt', 'scroll-pb'], + touch: ['touch-x', 'touch-y', 'touch-pz'], + 'touch-x': ['touch'], + 'touch-y': ['touch'], + 'touch-pz': ['touch'], }, conflictingClassGroupModifiers: { 'font-size': ['leading'], diff --git a/src/lib/types.ts b/src/lib/types.ts index a2c1be35..25eabaf5 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -386,6 +386,9 @@ export type DefaultClassGroupIds = | 'text-transform' | 'top' | 'touch' + | 'touch-x' + | 'touch-y' + | 'touch-pz' | 'tracking' | 'transform-origin' | 'transform' From 9cf0c4bfa5046ec3d593d0319a24eb83381b632a Mon Sep 17 00:00:00 2001 From: Dany Castillo <31006608+dcastil@users.noreply.github.com> Date: Mon, 18 Sep 2023 20:50:53 +0200 Subject: [PATCH 2/2] add tests for touch classes --- tests/class-map.test.ts | 2 +- tests/conflicts-across-class-groups.test.ts | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/class-map.test.ts b/tests/class-map.test.ts index 7e1d814c..b3340743 100644 --- a/tests/class-map.test.ts +++ b/tests/class-map.test.ts @@ -249,7 +249,7 @@ test('class map has correct class groups at first part', () => { text: ['font-size', 'text-alignment', 'text-color', 'text-opacity', 'text-overflow'], to: ['gradient-to', 'gradient-to-pos'], top: ['top'], - touch: ['touch'], + touch: ['touch', 'touch-pz', 'touch-x', 'touch-y'], tracking: ['tracking'], transform: ['transform'], transition: ['transition'], diff --git a/tests/conflicts-across-class-groups.test.ts b/tests/conflicts-across-class-groups.test.ts index 2971edda..5f1c2ef9 100644 --- a/tests/conflicts-across-class-groups.test.ts +++ b/tests/conflicts-across-class-groups.test.ts @@ -18,3 +18,16 @@ test('ring and shadow classes do not create conflict', () => { expect(twMerge('shadow ring')).toBe('shadow ring') expect(twMerge('shadow-md ring-2')).toBe('shadow-md ring-2') }) + +test('touch classes do create conflicts correctly', () => { + expect(twMerge('touch-pan-x touch-pan-right')).toBe('touch-pan-right') + expect(twMerge('touch-none touch-pan-x')).toBe('touch-pan-x') + expect(twMerge('touch-pan-x touch-none')).toBe('touch-none') + expect(twMerge('touch-pan-x touch-pan-y touch-pinch-zoom')).toBe( + 'touch-pan-x touch-pan-y touch-pinch-zoom', + ) + expect(twMerge('touch-manipulation touch-pan-x touch-pan-y touch-pinch-zoom')).toBe( + 'touch-pan-x touch-pan-y touch-pinch-zoom', + ) + expect(twMerge('touch-pan-x touch-pan-y touch-pinch-zoom touch-auto')).toBe('touch-auto') +})