Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix column reordering when mouse leaves the browser window. #105

Merged
merged 6 commits into from
Jan 16, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/FixedDataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -773,14 +773,17 @@ var FixedDataTable = React.createClass({
var columnBefore = this.state.columnReorderingData.columnBefore;
var columnAfter = this.state.columnReorderingData.columnAfter;
var reorderColumn = this.state.columnReorderingData.columnKey;
var cancelReorder = this.state.columnReorderingData.cancelReorder;

this.setState({
isColumnReordering: false,
columnReorderingData: {}
});
this.props.onColumnReorderEndCallback({
columnBefore, columnAfter, reorderColumn
});
if (!cancelReorder) {
this.props.onColumnReorderEndCallback({
columnBefore, columnAfter, reorderColumn
});
}

var onHorizontalScroll = this.props.onHorizontalScroll;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to run this onHorizontalScroll code here.
Can we just return early if cancelReorder is true?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. I only made sure that we want the stuff above the cancelReorder check, I didn't look below it to see if we want to skip anything.

I'll change the contents of the if block to return early and put the Callback after the if block.

if (this.state.columnReorderingData.scrollStart !== this.state.scrollX && onHorizontalScroll) {
Expand Down
3 changes: 2 additions & 1 deletion src/FixedDataTableColumnReorderHandle.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,12 @@ var FixedDataTableColumnReorderHandle = React.createClass({
this._distance = this.state.dragDistance + deltaX;
},

_onColumnReorderEnd() {
_onColumnReorderEnd(/*boolean*/ cancelReorder) {
this._animating = false;
cancelAnimationFrame(this.frameId);
this.frameId = null;
this._mouseMoveTracker.releaseMouseMoves();
this.props.columnReorderingData.cancelReorder = cancelReorder;
this.props.onColumnReorderEnd();
},

Expand Down
28 changes: 25 additions & 3 deletions src/vendor_upstream/dom/DOMMouseMoveTracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class DOMMouseMoveTracker {
this._domNode = domNode;
this._onMove = onMove;
this._onMoveEnd = onMoveEnd;
this._onMouseEnd = this._onMouseEnd.bind(this);
this._onMouseMove = this._onMouseMove.bind(this);
this._onMouseUp = this._onMouseUp.bind(this);
this._didMouseMove = this._didMouseMove.bind(this);
Expand All @@ -50,7 +51,7 @@ class DOMMouseMoveTracker {
* in order to grab inital state.
*/
captureMouseMoves(/*object*/ event) {
if (!this._eventMoveToken && !this._eventUpToken) {
if (!this._eventMoveToken && !this._eventUpToken && !this._eventLeaveToken && !this._eventOutToken) {
this._eventMoveToken = EventListener.listen(
this._domNode,
'mousemove',
Expand All @@ -61,6 +62,16 @@ class DOMMouseMoveTracker {
'mouseup',
this._onMouseUp
);
this._eventLeaveToken = EventListener.listen(
this._domNode,
'mouseleave',
this._onMouseEnd
);
this._eventOutToken = EventListener.listen(
this._domNode,
'mouseout',
this.onMouseEnd
);
}

if (!this._isDragging) {
Expand All @@ -77,11 +88,15 @@ class DOMMouseMoveTracker {
* These releases all of the listeners on document.body.
*/
releaseMouseMoves() {
if (this._eventMoveToken && this._eventUpToken) {
if (this._eventMoveToken && this._eventUpToken && this._eventLeaveToken && this._eventOutToken) {
this._eventMoveToken.remove();
this._eventMoveToken = null;
this._eventUpToken.remove();
this._eventUpToken = null;
this._eventLeaveToken.remove();
this._eventLeaveToken = null;
this._eventOutToken.remove();
this._eventOutToken = null;
}

if (this._animationFrameID !== null) {
Expand Down Expand Up @@ -139,7 +154,14 @@ class DOMMouseMoveTracker {
if (this._animationFrameID) {
this._didMouseMove();
}
this._onMoveEnd();
this._onMoveEnd(false);
}

/**
* Calls onMoveEnd passed into the constructor, updates internal state, and cancels the move.
*/
_onMouseEnd() {
this._onMoveEnd(true);
}
}

Expand Down