Skip to content

Commit

Permalink
fixing drag handle
Browse files Browse the repository at this point in the history
  • Loading branch information
alexreardon committed Jun 21, 2018
1 parent b514662 commit dd1910d
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 245 deletions.
4 changes: 2 additions & 2 deletions src/view/drag-handle/drag-handle.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ export default class DragHandle extends Component<Props> {
}

onKeyDown = (event: KeyboardEvent) => {
// let the mouse sensor deal with it
if (this.mouseSensor.isCapturing()) {
// let the other sensors deal with it
if (this.mouseSensor.isCapturing() || this.touchSensor.isCapturing()) {
return;
}

Expand Down
6 changes: 2 additions & 4 deletions src/view/drag-handle/sensor/create-keyboard-sensor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @flow
/* eslint-disable no-use-before-define */
import invariant from 'tiny-invariant';
import { type Position } from 'css-box-model';
import createScheduler from '../util/create-scheduler';
import preventStandardKeyEvents from '../util/prevent-standard-key-events';
Expand Down Expand Up @@ -82,10 +83,7 @@ export default ({

const ref: ?HTMLElement = getDraggableRef();

if (!ref) {
console.error('cannot start a keyboard drag without a draggable ref');
return;
}
invariant(ref, 'Cannot start a keyboard drag without a draggable ref');

// using center position as selection
const center: Position = getBorderBoxCenterPosition(ref);
Expand Down
13 changes: 7 additions & 6 deletions src/view/drag-handle/sensor/create-mouse-sensor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @flow
/* eslint-disable no-use-before-define */
import invariant from 'tiny-invariant';
import { type Position } from 'css-box-model';
import createScheduler from '../util/create-scheduler';
import isSloppyClickThresholdExceeded from '../util/is-sloppy-click-threshold-exceeded';
Expand Down Expand Up @@ -247,13 +248,13 @@ export default ({
return;
}

if (!canStartCapturing(event)) {
return;
}
invariant(!isCapturing(), 'Should not be able to perform a mouse down while a drag or pending drag is occurring');

if (isCapturing()) {
console.error('should not be able to perform a mouse down while a drag or pending drag is occurring');
cancel();
if (!canStartCapturing(event)) {
// blocking the event as we want to opt out of the standard browser behaviour
// this *could* occur during a drop - although it should not thanks to pointer-events: none
// this is just being really safe
event.preventDefault();
return;
}

Expand Down
10 changes: 3 additions & 7 deletions src/view/drag-handle/sensor/create-touch-sensor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @flow
/* eslint-disable no-use-before-define */
import invariant from 'tiny-invariant';
import { type Position } from 'css-box-model';
import createScheduler from '../util/create-scheduler';
import createPostDragEventPreventer, { type EventPreventer } from '../util/create-post-drag-event-preventer';
Expand Down Expand Up @@ -368,14 +369,9 @@ export default ({
return;
}

// TODO: call prevent default here?
if (!canStartCapturing(event)) {
return;
}
invariant(!isCapturing(), 'Should not be able to perform a touch start while a drag or pending drag is occurring');

if (isCapturing()) {
console.error('should not be able to perform a touch start while a drag or pending drag is occurring');
cancel();
if (!canStartCapturing(event)) {
return;
}

Expand Down
Loading

0 comments on commit dd1910d

Please sign in to comment.