Skip to content

Commit

Permalink
Merge pull request #313 from dcastil/bugfix/312/fix-touch-action-clas…
Browse files Browse the repository at this point in the history
…ses-overriding-each-other-incorrectly

Fix touch action classes overriding each other incorrectly
  • Loading branch information
dcastil committed Sep 18, 2023
2 parents eb09d52 + 9cf0c4b commit fb1fc1f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
35 changes: 28 additions & 7 deletions src/lib/default-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'],
Expand Down
3 changes: 3 additions & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@ export type DefaultClassGroupIds =
| 'text-transform'
| 'top'
| 'touch'
| 'touch-x'
| 'touch-y'
| 'touch-pz'
| 'tracking'
| 'transform-origin'
| 'transform'
Expand Down
2 changes: 1 addition & 1 deletion tests/class-map.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
13 changes: 13 additions & 0 deletions tests/conflicts-across-class-groups.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})

0 comments on commit fb1fc1f

Please sign in to comment.