Skip to content

Commit 977ec8c

Browse files
committed
added preventDefault prop
1 parent 22b0615 commit 977ec8c

File tree

4 files changed

+35
-21
lines changed

4 files changed

+35
-21
lines changed

Diff for: CHANGELOG.md

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
### 4.4.4 (July 4, 2021)
4+
5+
- Add `preventDefault` prop to allow touch scroll
6+
37
### 4.4.3 (June 8, 2020)
48

59
- Add `nodeRef` to TypeScript definitions
@@ -41,16 +45,16 @@
4145
`nodeRef` is also available on `<DraggableCore>`.
4246
- Remove "browser" field in "package.json":
4347
- There is nothing special in the browser build that is actually practical
44-
for modern use. The "browser" field, as defined in
48+
for modern use. The "browser" field, as defined in
4549
https://github.com/defunctzombie/package-browser-field-spec#overview,
4650
indicates that you should use it if you are directly accessing globals,
4751
using browser-specific features, dom manipulation, etc.
48-
52+
4953
React components like react-draggable are built to do minimal raw
5054
DOM manipulation, and to always gate this behind conditionals to ensure
5155
that server-side rendering still works. We don't make any changes
5256
to any of that for the "browser" build, so it's entirely redundant.
53-
57+
5458
This should also fix the "Super expression must either be null or
5559
a function" error (#472) that some users have experienced with particular
5660
bundler configurations.
@@ -61,7 +65,7 @@
6165
- The browser build will likely be removed entirely in 5.0.
6266
- Fix: Make `bounds` optional in TypeScript [#473](https://github.com/strml/react-draggable/pull/473)
6367

64-
### 4.3.1 (Apr 11, 2020)
68+
### 4.3.1 (Apr 11, 2020)
6569

6670
> This is a bugfix release.
6771

@@ -72,7 +76,7 @@
7276
return React.cloneElement(this.props.children, {style: this.props.children.props.style});
7377
```
7478
, `style` ends up undefined.
75-
- Fixed a bug that caused debug output to show up in the build.
79+
- Fixed a bug that caused debug output to show up in the build.
7680
- `babel-loader` cache does not invalidate when it should. I had modified webpack.config.js in the last version but it reused stale cache.
7781

7882
### 4.3.0 (Apr 10, 2020)
@@ -82,7 +86,7 @@
8286
- Thanks @schnerd, [#450](https://github.com/mzabriskie/react-draggable/pull/450)
8387
- Fix an issue where the insides of a `<Draggable>` were not scrollable on touch devices due to the outer container having `touch-action: none`.
8488
- This was a long-standing hack for mobile devices. Without it, the page will scroll while you drag the element.
85-
- The new solution will simply cancel the touch event `e.preventDefault()`. However, due to changes in Chrome >= 56, this is only possible on
89+
- The new solution will simply cancel the touch event `e.preventDefault()`. However, due to changes in Chrome >= 56, this is only possible on
8690
non-passive event handlers. To fix this, we now add/remove the touchEvent on lifecycle events rather than using React's event system.
8791
- [#465](https://github.com/mzabriskie/react-draggable/pull/465)
8892
- Upgrade devDeps and fix security warnings. None of them actually applied to this module.
@@ -106,7 +110,7 @@
106110
* **`"module"`**: ES6-compatible build using import/export.
107111

108112
This should fix issues like https://github.com/STRML/react-resizable/issues/113 while allowing modern bundlers to consume esm modules in the future.
109-
113+
110114
No compatibility changes are expected.
111115

112116
### 4.0.3 (Sep 10, 2019)

Diff for: example/example.js

+16-11
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ class App extends React.Component {
3030
};
3131
onDrop = (e) => {
3232
this.setState({activeDrags: --this.state.activeDrags});
33-
if (e.target.classList.contains("drop-target")) {
34-
alert("Dropped!");
33+
if (e.target.classList.contains('drop-target')) {
34+
alert('Dropped!');
3535
e.target.classList.remove('hovered');
3636
}
3737
};
@@ -134,7 +134,7 @@ class App extends React.Component {
134134
<div className="box drop-target" onMouseEnter={this.onDropAreaMouseEnter} onMouseLeave={this.onDropAreaMouseLeave}>I can detect drops from the next box.</div>
135135
</Draggable>
136136
<Draggable {...dragHandlers} onStop={this.onDrop}>
137-
<div className={`box ${this.state.activeDrags ? "no-pointer-events" : ""}`}>I can be dropped onto another box.</div>
137+
<div className={`box ${this.state.activeDrags ? 'no-pointer-events' : ''}`}>I can be dropped onto another box.</div>
138138
</Draggable>
139139
<div className="box" style={{height: '500px', width: '500px', position: 'relative', overflow: 'auto', padding: '0'}}>
140140
<div style={{height: '1000px', width: '1000px', padding: '10px'}}>
@@ -150,6 +150,11 @@ class App extends React.Component {
150150
Both parent padding and child margin work properly.
151151
</div>
152152
</Draggable>
153+
<Draggable bounds="parent" {...dragHandlers} preventDefault={false}>
154+
<div className="box">
155+
I don't prevent touches from scrolling the container.
156+
</div>
157+
</Draggable>
153158
</div>
154159
</div>
155160
<Draggable bounds="body" {...dragHandlers}>
@@ -174,7 +179,7 @@ class App extends React.Component {
174179
</Draggable>
175180
<Draggable defaultPosition={{x: 25, y: 25}} {...dragHandlers}>
176181
<div className="box">
177-
{"I have a default position of {x: 25, y: 25}, so I'm slightly offset."}
182+
{'I have a default position of {x: 25, y: 25}, so I\'m slightly offset.'}
178183
</div>
179184
</Draggable>
180185
<Draggable positionOffset={{x: '-10%', y: '-10%'}} {...dragHandlers}>
@@ -227,27 +232,27 @@ class RemWrapper extends React.Component {
227232
.split(',')
228233
.map(px => px.replace('px', ''))
229234
.map(px => parseInt(px, 10) / remBaseline)
230-
.map(x => `${x}rem`)
231-
const [x, y] = convertedValues
235+
.map(x => `${x}rem`);
236+
const [x, y] = convertedValues;
232237

233-
return `translate(${x}, ${y})`
238+
return `translate(${x}, ${y})`;
234239
}
235240

236241
render() {
237-
const { children, remBaseline = 16, style } = this.props
238-
const child = React.Children.only(children)
242+
const { children, remBaseline = 16, style } = this.props;
243+
const child = React.Children.only(children);
239244

240245
const editedStyle = {
241246
...child.props.style,
242247
...style,
243248
transform: this.translateTransformToRem(style.transform, remBaseline),
244-
}
249+
};
245250

246251
return React.cloneElement(child, {
247252
...child.props,
248253
...this.props,
249254
style: editedStyle
250-
})
255+
});
251256
}
252257
}
253258

Diff for: lib/DraggableCore.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export type DraggableCoreDefaultProps = {
5555
onDrag: DraggableEventHandler,
5656
onStop: DraggableEventHandler,
5757
onMouseDown: (e: MouseEvent) => void,
58+
preventDefault: true,
5859
scale: number,
5960
};
6061

@@ -65,6 +66,7 @@ export type DraggableCoreProps = {
6566
offsetParent: HTMLElement,
6667
grid: [number, number],
6768
handle: string,
69+
preventDefault: boolean,
6870
nodeRef?: ?React.ElementRef<any>,
6971
};
7072

@@ -208,6 +210,8 @@ export default class DraggableCore extends React.Component<DraggableCoreProps, D
208210
*/
209211
scale: PropTypes.number,
210212

213+
preventDefault: PropTypes.bool,
214+
211215
/**
212216
* These properties should be defined on the child, not here.
213217
*/
@@ -224,6 +228,7 @@ export default class DraggableCore extends React.Component<DraggableCoreProps, D
224228
onDrag: function(){},
225229
onStop: function(){},
226230
onMouseDown: function(){},
231+
preventDefault: true,
227232
scale: 1,
228233
};
229234

@@ -292,7 +297,7 @@ export default class DraggableCore extends React.Component<DraggableCoreProps, D
292297

293298
// Prevent scrolling on mobile devices, like ipad/iphone.
294299
// Important that this is after handle/cancel.
295-
if (e.type === 'touchstart') e.preventDefault();
300+
if (this.props.preventDefault && e.type === 'touchstart') e.preventDefault();
296301

297302
// Set touch identifier in component state if this is a touch event. This allows us to
298303
// distinguish between individual touches on multitouch screens by identifying which

Diff for: package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "react-draggable",
3-
"version": "4.4.3",
2+
"name": "@filkalny-thimble/react-draggable",
3+
"version": "4.4.4",
44
"description": "React draggable component",
55
"main": "build/cjs/cjs.js",
66
"unpkg": "build/web/react-draggable.min.js",

0 commit comments

Comments
 (0)