Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: "making things draggable blocks touch scrolling" #134

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
16 changes: 16 additions & 0 deletions docs/src/documentation/options/touchAction/+option.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
title: touchAction
type: 'string'
defaultValue: 'none'
---

import Code from '$components/options/OptionsCode.astro';
import Example from '$components/options/OptionsExample.astro';
import Examples from '$components/options/OptionsExamples.svelte';

export const shortDescription =
'Choose to set the initial touch-action of an element to a different value than "none"';

<p>{shortDescription}</p>

By default, the "touch-action" style is set to `none` upon initalizing the draggable on an element.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@types/react": "^18.0.28",
"@types/react-dom": "^18.0.11",
"brotli-size": "^4.0.0",
"csstype": "^3.1.2",
"fast-glob": "^3.2.12",
"jsdom": "^21.1.0",
"nx": "15.7.2",
Expand Down
12 changes: 11 additions & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { Property } from 'csstype';

export type DragBoundsCoords = {
/** Number of pixels from left of the document */
left: number;
Expand Down Expand Up @@ -182,6 +184,11 @@ export type DragOptions = {
*/
handle?: string | HTMLElement | HTMLElement[];

/**
* Choose to set the initial touch-action of an element to a different value than 'none'
*/
touchAction?: Property.TouchAction;

/**
* Class to apply on the element on which `use:draggable` is applied.
* Note that if `handle` is provided, it will still apply class on the element to which this action is applied, **NOT** the handle
Expand Down Expand Up @@ -258,6 +265,8 @@ export const draggable = (node: HTMLElement, options: DragOptions = {}) => {
cancel,
handle,

touchAction = 'none',

defaultClass = DEFAULT_CLASS.MAIN,
defaultClassDragging = DEFAULT_CLASS.DRAGGING,
defaultClassDragged = DEFAULT_CLASS.DRAGGED,
Expand Down Expand Up @@ -359,10 +368,11 @@ export const draggable = (node: HTMLElement, options: DragOptions = {}) => {

listen('pointerdown', dragStart, false);
listen('pointerup', dragEnd, false);
listen('touchend', dragEnd, false);
listen('pointermove', drag, false);

// On mobile, touch can become extremely janky without it
setStyle(node, 'touch-action', 'none');
setStyle(node, 'touch-action', touchAction);

const calculateInverseScale = () => {
// Calculate the current scale of the node
Expand Down
65 changes: 17 additions & 48 deletions pnpm-lock.yaml

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