Skip to content

Commit 5d3f519

Browse files
Fix simulator Buttons module touch input (#985)
See #984. This will actually close it, but not from a user's point of view until we switch the beta over to the new staging deployment.
1 parent 12226ed commit 5d3f519

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/simulator/SensorInput.tsx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,31 @@ const SensorInput = ({
6060
}
6161
}
6262
};
63+
const mouseDownTouchStartAction = () => {
64+
setMouseDown(true);
65+
handleSensorChange(sensor.max);
66+
};
67+
const mouseUpTouchEndAction = () => {
68+
if (mouseDown) {
69+
setMouseDown(false);
70+
handleSensorChange(sensor.min);
71+
}
72+
};
6373
const mouseDownListener = (
6474
event: React.MouseEvent<HTMLButtonElement, MouseEvent>
6575
) => {
6676
event.preventDefault();
67-
setMouseDown(true);
68-
handleSensorChange(sensor.max);
77+
mouseDownTouchStartAction();
6978
};
7079
const mouseUpListener = (
7180
event: React.MouseEvent<HTMLButtonElement, MouseEvent>
7281
) => {
7382
event.preventDefault();
74-
if (mouseDown) {
75-
setMouseDown(false);
76-
handleSensorChange(sensor.min);
77-
}
83+
mouseUpTouchEndAction();
84+
};
85+
const touchEndListener = (event: React.TouchEvent) => {
86+
event.preventDefault();
87+
mouseUpTouchEndAction();
7888
};
7989
const mouseLeaveListener = () => {
8090
if (mouseDown) {
@@ -124,7 +134,9 @@ const SensorInput = ({
124134
onKeyDown={keyListener}
125135
onKeyUp={keyListener}
126136
onMouseDown={mouseDownListener}
137+
onTouchStart={mouseDownTouchStartAction}
127138
onMouseUp={mouseUpListener}
139+
onTouchEnd={touchEndListener}
128140
onMouseLeave={mouseLeaveListener}
129141
>
130142
{logo ? (

0 commit comments

Comments
 (0)