Skip to content
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
22 changes: 11 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@
"parcel-bundler": "1.12.3",
"parcel-plugin-css-to-string": "^2.5.2",
"prettier": "^2.2.1",
"react": "^17.0.0",
"react-dom": "^17.0.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"size-limit": "^4.10.1",
"ts-jest": "^26.5.3",
"typescript": "^4.2.3",
Expand Down
19 changes: 13 additions & 6 deletions src/components/common/Interactive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface Interaction {
}

// Check if an event was triggered by touch
const isTouch = (e: MouseEvent | TouchEvent): e is TouchEvent => "touches" in e;
const isTouch = (event: MouseEvent | TouchEvent): event is TouchEvent => "touches" in event;

// Returns a relative position of the pointer inside the node's bounding box
const getRelativePosition = (node: HTMLDivElement, event: MouseEvent | TouchEvent): Interaction => {
Expand All @@ -25,6 +25,13 @@ const getRelativePosition = (node: HTMLDivElement, event: MouseEvent | TouchEven
};
};

// Browsers introduced an intervention, making touch events passive by default.
// This workaround removes `preventDefault` call from the touch handlers.
// https://github.com/facebook/react/issues/19651
const preventDefaultMove = (event: MouseEvent | TouchEvent): void => {
!isTouch(event) && event.preventDefault();
};

interface Props {
onMove: (interaction: Interaction) => void;
onKey: (offset: Interaction) => void;
Expand All @@ -48,7 +55,7 @@ const InteractiveBase = ({ onMove, onKey, ...rest }: Props) => {

const handleMove = useCallback(
(event: MouseEvent | TouchEvent) => {
event.preventDefault();
preventDefaultMove(event);

// If user moves the pointer outside of the window or iframe bounds and release it there,
// `mouseup`/`touchend` won't be fired. In order to stop the picker from following the cursor
Expand All @@ -67,14 +74,14 @@ const InteractiveBase = ({ onMove, onKey, ...rest }: Props) => {
);

const handleMoveStart = useCallback(
({ nativeEvent: event }: React.MouseEvent | React.TouchEvent) => {
event.preventDefault();
({ nativeEvent }: React.MouseEvent | React.TouchEvent) => {
preventDefaultMove(nativeEvent);

if (!isValid(event)) return;
if (!isValid(nativeEvent)) return;

// The node/ref must actually exist when user start an interaction.
// We won't suppress the ESLint warning though, as it should probably be something to be aware of.
onMoveCallback(getRelativePosition(container.current!, event));
onMoveCallback(getRelativePosition(container.current!, nativeEvent));
setDragging(true);
},
[onMoveCallback]
Expand Down