Skip to content

Commit 20d7331

Browse files
committed
add combinable touch-action support
1 parent ef325ea commit 20d7331

File tree

3 files changed

+90
-11
lines changed

3 files changed

+90
-11
lines changed

src/corePlugins.js

+56-9
Original file line numberDiff line numberDiff line change
@@ -602,18 +602,65 @@ export let corePlugins = {
602602

603603
cursor: createUtilityPlugin('cursor'),
604604

605-
touchAction: ({ addUtilities }) => {
605+
touchAction: ({ addBase, addUtilities }) => {
606+
addBase({
607+
'@defaults touch-action': {
608+
'--tw-pan-x': 'var(--tw-empty,/*!*/ /*!*/)',
609+
'--tw-pan-left': 'var(--tw-empty,/*!*/ /*!*/)',
610+
'--tw-pan-right': 'var(--tw-empty,/*!*/ /*!*/)',
611+
'--tw-pan-y': 'var(--tw-empty,/*!*/ /*!*/)',
612+
'--tw-pan-up': 'var(--tw-empty,/*!*/ /*!*/)',
613+
'--tw-pan-down': 'var(--tw-empty,/*!*/ /*!*/)',
614+
'--tw-pinch-zoom': 'var(--tw-empty,/*!*/ /*!*/)',
615+
'--tw-manipulation': 'var(--tw-empty,/*!*/ /*!*/)',
616+
'--tw-touch-action':
617+
'var(--tw-pan-x) var(--tw-pan-left) var(--tw-pan-right) var(--tw-pan-y) var(--tw-pan-up) var(--tw-pan-down) var(--tw-pinch-zoom) var(--tw-manipulation)',
618+
},
619+
})
620+
606621
addUtilities({
607622
'.touch-auto': { 'touch-action': 'auto' },
608623
'.touch-none': { 'touch-action': 'none' },
609-
'.touch-pan-x': { 'touch-action': 'pan-x' },
610-
'.touch-pan-left': { 'touch-action': 'pan-left' },
611-
'.touch-pan-right': { 'touch-action': 'pan-right' },
612-
'.touch-pan-y': { 'touch-action': 'pan-y' },
613-
'.touch-pan-up': { 'touch-action': 'pan-up' },
614-
'.touch-pan-down': { 'touch-action': 'pan-down' },
615-
'.touch-pinch-zoom': { 'touch-action': 'pinch-zoom' },
616-
'.touch-manipulation': { 'touch-action': 'manipulation' },
624+
'.touch-pan-x': {
625+
'@defaults touch-action': {},
626+
'--tw-pan-x': 'pan-x',
627+
'touch-action': 'var(--tw-touch-action)',
628+
},
629+
'.touch-pan-left': {
630+
'@defaults touch-action': {},
631+
'--tw-pan-left': 'pan-left',
632+
'touch-action': 'var(--tw-touch-action)',
633+
},
634+
'.touch-pan-right': {
635+
'@defaults touch-action': {},
636+
'--tw-pan-right': 'pan-right',
637+
'touch-action': 'var(--tw-touch-action)',
638+
},
639+
'.touch-pan-y': {
640+
'@defaults touch-action': {},
641+
'--tw-pan-y': 'pan-y',
642+
'touch-action': 'var(--tw-touch-action)',
643+
},
644+
'.touch-pan-up': {
645+
'@defaults touch-action': {},
646+
'--tw-pan-up': 'pan-up',
647+
'touch-action': 'var(--tw-touch-action)',
648+
},
649+
'.touch-pan-down': {
650+
'@defaults touch-action': {},
651+
'--tw-pan-down': 'pan-down',
652+
'touch-action': 'var(--tw-touch-action)',
653+
},
654+
'.touch-pinch-zoom': {
655+
'@defaults touch-action': {},
656+
'--tw-pinch-zoom': 'pinch-zoom',
657+
'touch-action': 'var(--tw-touch-action)',
658+
},
659+
'.touch-manipulation': {
660+
'@defaults touch-action': {},
661+
'--tw-manipulation': 'manipulation',
662+
'touch-action': 'var(--tw-touch-action)',
663+
},
617664
})
618665
},
619666

tests/basic-usage.test.css

+33-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,23 @@
1919
scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
2020
}
2121

22+
.touch-pan-x,
23+
.touch-pan-y,
24+
.touch-pan-up,
25+
.touch-pinch-zoom,
26+
.touch-manipulation {
27+
--tw-pan-x: var(--tw-empty, /*!*/ /*!*/);
28+
--tw-pan-left: var(--tw-empty, /*!*/ /*!*/);
29+
--tw-pan-right: var(--tw-empty, /*!*/ /*!*/);
30+
--tw-pan-y: var(--tw-empty, /*!*/ /*!*/);
31+
--tw-pan-up: var(--tw-empty, /*!*/ /*!*/);
32+
--tw-pan-down: var(--tw-empty, /*!*/ /*!*/);
33+
--tw-pinch-zoom: var(--tw-empty, /*!*/ /*!*/);
34+
--tw-manipulation: var(--tw-empty, /*!*/ /*!*/);
35+
--tw-touch-action: var(--tw-pan-x) var(--tw-pan-left) var(--tw-pan-right) var(--tw-pan-y)
36+
var(--tw-pan-up) var(--tw-pan-down) var(--tw-pinch-zoom) var(--tw-manipulation);
37+
}
38+
2239
.snap-x {
2340
--tw-scroll-snap-strictness: proximity;
2441
}
@@ -374,11 +391,25 @@
374391
.cursor-pointer {
375392
cursor: pointer;
376393
}
394+
.touch-pan-x {
395+
--tw-pan-x: pan-x;
396+
touch-action: var(--tw-touch-action);
397+
}
377398
.touch-pan-y {
378-
touch-action: pan-y;
399+
--tw-pan-y: pan-y;
400+
touch-action: var(--tw-touch-action);
401+
}
402+
.touch-pan-up {
403+
--tw-pan-up: pan-up;
404+
touch-action: var(--tw-touch-action);
405+
}
406+
.touch-pinch-zoom {
407+
--tw-pinch-zoom: pinch-zoom;
408+
touch-action: var(--tw-touch-action);
379409
}
380410
.touch-manipulation {
381-
touch-action: manipulation;
411+
--tw-manipulation: manipulation;
412+
touch-action: var(--tw-touch-action);
382413
}
383414
.select-none {
384415
user-select: none;

tests/basic-usage.test.html

+1
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@
170170
<div class="transition transition-all"></div>
171171
<div class="ease-in-out"></div>
172172
<div class="translate-x-5 -translate-x-4 translate-y-6 -translate-x-3"></div>
173+
<div class="touch-pan-up touch-pan-x touch-pinch-zoom"></div>
173174
<div class="select-none"></div>
174175
<div class="align-middle"></div>
175176
<div class="invisible"></div>

0 commit comments

Comments
 (0)