Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix touch action classes overriding each other incorrectly #313

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')
})
Loading