Skip to content

Commit

Permalink
Calculate bounds *before* firing events
Browse files Browse the repository at this point in the history
  • Loading branch information
STRML committed Feb 10, 2016
1 parent 6163ad2 commit 72cab9c
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/Draggable.es6
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
};

Expand Down

0 comments on commit 72cab9c

Please sign in to comment.