Skip to content

Commit 03f9de9

Browse files
authored
Add combinable touch-action support (#6115)
* add combinable `touch-action` support * update changelog
1 parent ef325ea commit 03f9de9

File tree

4 files changed

+71
-9
lines changed

4 files changed

+71
-9
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515

1616
- Add `placeholder` variant ([#6106](https://github.com/tailwindlabs/tailwindcss/pull/6106))
1717
- Add tuple syntax for configuring screens while guaranteeing order ([#5956](https://github.com/tailwindlabs/tailwindcss/pull/5956))
18+
- Add combinable `touch-action` support ([#6115](https://github.com/tailwindlabs/tailwindcss/pull/6115))
1819

1920
## [3.0.0-alpha.2] - 2021-11-08
2021

src/corePlugins.js

+45-8
Original file line numberDiff line numberDiff line change
@@ -602,17 +602,54 @@ 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-y': 'var(--tw-empty,/*!*/ /*!*/)',
610+
'--tw-pinch-zoom': 'var(--tw-empty,/*!*/ /*!*/)',
611+
'--tw-touch-action': 'var(--tw-pan-x) var(--tw-pan-y) var(--tw-pinch-zoom)',
612+
},
613+
})
614+
606615
addUtilities({
607616
'.touch-auto': { 'touch-action': 'auto' },
608617
'.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' },
618+
'.touch-pan-x': {
619+
'@defaults touch-action': {},
620+
'--tw-pan-x': 'pan-x',
621+
'touch-action': 'var(--tw-touch-action)',
622+
},
623+
'.touch-pan-left': {
624+
'@defaults touch-action': {},
625+
'--tw-pan-x': 'pan-left',
626+
'touch-action': 'var(--tw-touch-action)',
627+
},
628+
'.touch-pan-right': {
629+
'@defaults touch-action': {},
630+
'--tw-pan-x': 'pan-right',
631+
'touch-action': 'var(--tw-touch-action)',
632+
},
633+
'.touch-pan-y': {
634+
'@defaults touch-action': {},
635+
'--tw-pan-y': 'pan-y',
636+
'touch-action': 'var(--tw-touch-action)',
637+
},
638+
'.touch-pan-up': {
639+
'@defaults touch-action': {},
640+
'--tw-pan-y': 'pan-up',
641+
'touch-action': 'var(--tw-touch-action)',
642+
},
643+
'.touch-pan-down': {
644+
'@defaults touch-action': {},
645+
'--tw-pan-y': 'pan-down',
646+
'touch-action': 'var(--tw-touch-action)',
647+
},
648+
'.touch-pinch-zoom': {
649+
'@defaults touch-action': {},
650+
'--tw-pinch-zoom': 'pinch-zoom',
651+
'touch-action': 'var(--tw-touch-action)',
652+
},
616653
'.touch-manipulation': { 'touch-action': 'manipulation' },
617654
})
618655
},

tests/basic-usage.test.css

+24-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@
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+
--tw-pan-x: var(--tw-empty, /*!*/ /*!*/);
27+
--tw-pan-y: var(--tw-empty, /*!*/ /*!*/);
28+
--tw-pinch-zoom: var(--tw-empty, /*!*/ /*!*/);
29+
--tw-touch-action: var(--tw-pan-x) var(--tw-pan-y) var(--tw-pinch-zoom);
30+
}
31+
2232
.snap-x {
2333
--tw-scroll-snap-strictness: proximity;
2434
}
@@ -374,8 +384,21 @@
374384
.cursor-pointer {
375385
cursor: pointer;
376386
}
387+
.touch-pan-x {
388+
--tw-pan-x: pan-x;
389+
touch-action: var(--tw-touch-action);
390+
}
377391
.touch-pan-y {
378-
touch-action: pan-y;
392+
--tw-pan-y: pan-y;
393+
touch-action: var(--tw-touch-action);
394+
}
395+
.touch-pan-up {
396+
--tw-pan-y: pan-up;
397+
touch-action: var(--tw-touch-action);
398+
}
399+
.touch-pinch-zoom {
400+
--tw-pinch-zoom: pinch-zoom;
401+
touch-action: var(--tw-touch-action);
379402
}
380403
.touch-manipulation {
381404
touch-action: manipulation;

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)