Skip to content

Commit 7fbaafe

Browse files
committed
Fix #82 (right-click starts drag)
1 parent a590c2b commit 7fbaafe

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ cancel: string,
9292
// Example: '.handle'
9393
handle: string,
9494

95+
// If set to `true`, will allow dragging on non left-button clicks.
96+
allowAnyClick: boolean,
97+
9598
// Determines which axis the draggable can move. Accepted values:
9699
// - `both` allows movement horizontally and vertically (default).
97100
// - `x` limits movement to horizontal axis.

lib/DraggableCore.es6

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ export default class DraggableCore extends React.Component {
3434
static displayName = 'DraggableCore';
3535

3636
static propTypes = {
37+
/**
38+
* `allowAnyClick` allows dragging using any mouse button.
39+
* By default, we only accept the left button.
40+
*
41+
* Defaults to `false`.
42+
*/
43+
allowAnyClick: PropTypes.bool,
44+
3745
/**
3846
* `disabled`, if true, stops the <Draggable> from dragging. All handlers,
3947
* with the exception of `onMouseDown`, will not fire.
@@ -182,6 +190,7 @@ export default class DraggableCore extends React.Component {
182190
};
183191

184192
static defaultProps = {
193+
allowAnyClick: false, // by default only accept left click
185194
cancel: null,
186195
disabled: false,
187196
enableUserSelectHack: true,
@@ -213,6 +222,9 @@ export default class DraggableCore extends React.Component {
213222
// Make it possible to attach event handlers on top of this one.
214223
this.props.onMouseDown(e);
215224

225+
// Only accept left-clicks.
226+
if (!this.props.allowAnyClick && typeof e.button === 'number' && e.button !== 0) return false;
227+
216228
// Short circuit if handle or cancel prop was provided and selector doesn't match.
217229
if (this.props.disabled ||
218230
(this.props.handle && !matchesSelector(e.target, this.props.handle)) ||

0 commit comments

Comments
 (0)