From 72cab9c95139b7f8959911a5c756bd7185d4a7d5 Mon Sep 17 00:00:00 2001 From: Samuel Reed Date: Wed, 10 Feb 2016 09:58:36 -0600 Subject: [PATCH] Calculate bounds *before* firing events --- lib/Draggable.es6 | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/Draggable.es6 b/lib/Draggable.es6 index e5d624bc..57d910eb 100644 --- a/lib/Draggable.es6 +++ b/lib/Draggable.es6 @@ -167,10 +167,6 @@ export default class Draggable extends DraggableCore { let uiEvent = createUIEvent(this, coreEvent); - // Short-circuit if user's callback killed it. - let shouldUpdate = this.props.onDrag(e, uiEvent); - if (shouldUpdate === false) return false; - let newState = { clientX: uiEvent.position.left, clientY: uiEvent.position.top @@ -193,8 +189,16 @@ export default class Draggable extends DraggableCore { // Recalculate slack by noting how much was shaved by the boundPosition handler. newState.slackX = this.state.slackX + (clientX - newState.clientX); newState.slackY = this.state.slackY + (clientY - newState.clientY); + + // Update the event we fire. + uiEvent.position.left = clientX; + uiEvent.position.top = clientY; } + // Short-circuit if user's callback killed it. + let shouldUpdate = this.props.onDrag(e, uiEvent); + if (shouldUpdate === false) return false; + this.setState(newState); };