Skip to content

Commit 3e69b8b

Browse files
committed
Add typeArg to MouseEvent constructor as per spec; fixes #164
1 parent 72e14ec commit 3e69b8b

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

lib/DraggableCore.es6

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,17 @@ export default class DraggableCore extends React.Component {
259259
// Call event handler. If it returns explicit false, trigger end.
260260
const shouldUpdate = this.props.onDrag(e, coreEvent);
261261
if (shouldUpdate === false) {
262-
this.handleDragStop(new MouseEvent());
262+
try {
263+
this.handleDragStop(new MouseEvent('mouseup'));
264+
} catch (err) {
265+
// Old browsers
266+
const event = document.createEvent('MouseEvents');
267+
// I see why this insanity was deprecated
268+
// $FlowIgnore
269+
event.initMouseEvent('mouseup', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
270+
// $FlowIgnore
271+
this.handleDragStop(event);
272+
}
263273
return;
264274
}
265275

specs/draggable.spec.jsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,22 @@ describe('react-draggable', function () {
178178
assert(called === false);
179179
});
180180

181+
it('should immediately call onStop if onDrag returns false', function () {
182+
var called = false;
183+
drag = TestUtils.renderIntoDocument(
184+
<Draggable onDrag={function () { return false; }} onStop={function () { called = true; }}>
185+
<div/>
186+
</Draggable>
187+
);
188+
189+
TestUtils.Simulate.mouseDown(ReactDOM.findDOMNode(drag));
190+
assert(called === false);
191+
mouseMove(10, 10);
192+
assert(called === true);
193+
assert(drag.state.x === 0);
194+
assert(drag.state.y === 0);
195+
});
196+
181197
it('should render with style translate() for DOM nodes', function () {
182198
var dragged = false;
183199
drag = TestUtils.renderIntoDocument(

0 commit comments

Comments
 (0)