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: add allowMobileScroll prop to allow for clicks to optionally pass through on mobile #760

Merged
merged 4 commits into from
Aug 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ on itself and thus must have callbacks attached to be useful.
cancel: string,
disabled: boolean,
enableUserSelectHack: boolean,
allowMobileScroll: boolean,
offsetParent: HTMLElement,
grid: [number, number],
handle: string,
Expand Down
2 changes: 1 addition & 1 deletion lib/DraggableCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ export default class DraggableCore extends React.Component<DraggableCoreProps> {

// Prevent scrolling on mobile devices, like ipad/iphone.
// Important that this is after handle/cancel.
if (e.type === 'touchstart') e.preventDefault();
if (e.type === 'touchstart' && !this.props.allowMobileScroll) e.preventDefault();

// Set touch identifier in component state if this is a touch event. This allows us to
// distinguish between individual touches on multitouch screens by identifying which
Expand Down
1 change: 1 addition & 0 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ declare module 'react-draggable' {
children?: React.ReactNode,
disabled: boolean,
enableUserSelectHack: boolean,
allowMobileScroll: boolean,
offsetParent: HTMLElement,
grid: [number, number],
handle: string,
Expand Down
4 changes: 3 additions & 1 deletion typings/test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ReactDOM.render(
onMouseDown={handleMouseDown}
disabled={true}
enableUserSelectHack={false}
allowMobileScroll={false}
bounds={false}
defaultClassName={'draggable'}
defaultClassNameDragging={'dragging'}
Expand Down Expand Up @@ -54,7 +55,8 @@ ReactDOM.render(
onDrag={handleDrag}
onStop={handleStop}
offsetParent={document.body}
enableUserSelectHack={false}>
enableUserSelectHack={false}
allowMobileScroll={false}>
<div className="foo bar" ref={nodeRefCore}>
<div className="handle"/>
<div className="cancel"/>
Expand Down