Skip to content

Commit 911c390

Browse files
authored
feat(touch-action): adding touch action none to draggable components (#3656)
* feat(touch-action): adding touch action to draggable components * chore(touch-action): restoring some metadata files * chore(touch-action): token files * chore(touch-action): adding token files) * chore(touch-action): restoring token css files * chore(touch-action): removing token dist css files * feat(touch-action): adding touch action to slider handle * chore(touch-action): fix typos in changeset * feat(touch-action): adding user select none to color area
1 parent bfe2e2c commit 911c390

File tree

6 files changed

+30
-2
lines changed

6 files changed

+30
-2
lines changed

.changeset/thick-ears-win.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
"@spectrum-css/colorhandle": minor
3+
"@spectrum-css/colorslider": minor
4+
"@spectrum-css/colorarea": minor
5+
"@spectrum-css/colorwheel": minor
6+
"@spectrum-css/slider": minor
7+
---
8+
9+
### Including the touch action rule for draggable content
10+
11+
The slider, color slider, color area, color wheel, color handle all deserve to have their touch-action property managed so that trying to set the value of those interfaces doesn't cause page scrolling in touch context.
12+
13+
Adding `touch-action: none` to a slider or any draggable component is necessary to prevent the browser's default touch behaviors—such as scrolling, pinch-zooming, or double-tap zooming from interfering with the component's intended interaction.
14+
15+
These components also include `user-select: none` to prevent selection or highlighting of any text elements.

components/colorarea/index.css

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/* @TODO: leveraging the rgb token in this case to achieve the desired border color implementation as rgb + opacity are required by the `rgba` function. */
1818
--spectrum-colorarea-border-color-rgb: var(--spectrum-gray-1000-rgb);
19-
--spectrum-colorarea-border-color: rgba(var(--spectrum-colorarea-border-color-rgb), var(--spectrum-color-area-border-opacity));
19+
--spectrum-colorarea-border-color: rgb(var(--spectrum-colorarea-border-color-rgb), var(--spectrum-color-area-border-opacity));
2020
--spectrum-colorarea-border-width: var(--spectrum-color-area-border-width);
2121
--spectrum-colorarea-disabled-background-color: var(--spectrum-disabled-background-color);
2222
--spectrum-colorarea-height: var(--spectrum-color-area-height);
@@ -27,7 +27,6 @@
2727
position: relative;
2828
display: inline-block;
2929
cursor: default;
30-
user-select: none;
3130
min-inline-size: var(--mod-colorarea-min-width, var(--spectrum-colorarea-min-width));
3231
min-block-size: var(--mod-colorarea-min-height, var(--spectrum-colorarea-min-height));
3332
inline-size: var(--mod-colorarea-width, var(--spectrum-colorarea-width));
@@ -36,6 +35,9 @@
3635
border-radius: var(--mod-colorarea-border-radius, var(--spectrum-colorarea-border-radius));
3736
border: var(--mod-colorarea-border-width, var(--spectrum-colorarea-border-width)) solid var(--highcontrast-colorarea-border-color, var(--mod-colorarea-border-color, var(--spectrum-colorarea-border-color)));
3837

38+
touch-action: none; /* Disable touch scrolling on touch devices to allow for color picking */
39+
user-select: none;
40+
3941
&.is-focused {
4042
z-index: 2;
4143
}

components/colorhandle/index.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@
5555

5656
transition: all var(--mod-colorhandle-animation-duration, var(--spectrum-animation-duration-100)) var(--mod-colorhandle-animation-easing, ease-in-out);
5757

58+
touch-action: none; /* Disable touch scrolling on touch devices to allow for color picking */
59+
user-select: none; /* Prevent text selection when dragging the handle */
60+
5861
&::after {
5962
content: "";
6063
inset-inline: calc(50% - calc(var(--mod-colorhandle-hitarea-size, var(--spectrum-color-control-track-width)) / 2));

components/colorslider/index.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
inline-size: var(--mod-color-slider-length, var(--spectrum-color-slider-length));
3131
block-size: var(--mod-color-slider-control-track-width, var(--spectrum-color-slider-control-track-width));
3232

33+
touch-action: none; /* Disable touch scrolling on touch devices to allow for color picking */
34+
3335
/* Otherwise we randomly drag a file icon */
3436
user-select: none;
3537

components/colorwheel/index.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
min-inline-size: var(--mod-colorwheel-min-inline-size, var(--spectrum-colorwheel-min-inline-size));
3838
inline-size: var(--mod-colorwheel-inline-size, var(--spectrum-colorwheel-inline-size));
3939
block-size: var(--mod-colorwheel-block-size, var(--spectrum-colorwheel-block-size));
40+
touch-action: none; /* Disable touch scrolling on touch devices to allow for color picking */
4041
user-select: none;
4142
cursor: default;
4243

components/slider/index.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@
207207
padding-inline-end: var(--mod-slider-handle-gap, var(--spectrum-slider-handle-gap));
208208
margin-inline-start: var(--mod-slider-track-margin-offset, var(--spectrum-slider-track-margin-offset));
209209

210+
touch-action: none; /* Disable touch scrolling on touch devices to allow dragging slider */
211+
user-select: none;
212+
210213
&::before {
211214
content: "";
212215
display: block;
@@ -244,6 +247,8 @@
244247
padding-inline-end: 0;
245248
margin-inline-start: var(--mod-slider-range-track-reset, var(--spectrum-slider-range-track-reset));
246249
margin-inline-end: var(--mod-slider-track-margin-offset, var(--spectrum-slider-track-margin-offset));
250+
user-select: none;
251+
touch-action: none; /* Disable touch scrolling on touch devices to allow dragging slider handle */
247252
}
248253

249254
/* over-write for Range, without the LTR RTL post-css hack */

0 commit comments

Comments
 (0)