Skip to content

Commit

Permalink
Add typeArg to MouseEvent constructor as per spec; fixes #164
Browse files Browse the repository at this point in the history
  • Loading branch information
STRML committed Jun 6, 2016
1 parent 72e14ec commit 3e69b8b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/DraggableCore.es6
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,17 @@ export default class DraggableCore extends React.Component {
// Call event handler. If it returns explicit false, trigger end.
const shouldUpdate = this.props.onDrag(e, coreEvent);
if (shouldUpdate === false) {
this.handleDragStop(new MouseEvent());
try {
this.handleDragStop(new MouseEvent('mouseup'));
} catch (err) {
// Old browsers
const event = document.createEvent('MouseEvents');
// I see why this insanity was deprecated
// $FlowIgnore
event.initMouseEvent('mouseup', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
// $FlowIgnore
this.handleDragStop(event);
}
return;
}

Expand Down
16 changes: 16 additions & 0 deletions specs/draggable.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,22 @@ describe('react-draggable', function () {
assert(called === false);
});

it('should immediately call onStop if onDrag returns false', function () {
var called = false;
drag = TestUtils.renderIntoDocument(
<Draggable onDrag={function () { return false; }} onStop={function () { called = true; }}>
<div/>
</Draggable>
);

TestUtils.Simulate.mouseDown(ReactDOM.findDOMNode(drag));
assert(called === false);
mouseMove(10, 10);
assert(called === true);
assert(drag.state.x === 0);
assert(drag.state.y === 0);
});

it('should render with style translate() for DOM nodes', function () {
var dragged = false;
drag = TestUtils.renderIntoDocument(
Expand Down

0 comments on commit 3e69b8b

Please sign in to comment.