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: draggable resizing col jumps to right #1421

Merged
merged 3 commits into from
Dec 6, 2018
Merged
Changes from all 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
13 changes: 8 additions & 5 deletions packages/react-data-grid/src/HeaderCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class HeaderCell extends React.Component {

state = {resizing: false};

headerCellRef = (node) => this.headerCell = node;

onDragStart = (e) => {
this.setState({resizing: true});
// need to set dummy data for FF
Expand All @@ -56,8 +58,8 @@ class HeaderCell extends React.Component {
};

getWidthFromMouseEvent = (e) => {
let right = e.pageX || (e.touches && e.touches[0] && e.touches[0].pageX) || (e.changedTouches && e.changedTouches[e.changedTouches.length - 1].pageX);
let left = ReactDOM.findDOMNode(this).getBoundingClientRect().left;
const right = e.pageX || (e.touches && e.touches[0] && e.touches[0].pageX) || (e.changedTouches && e.changedTouches[e.changedTouches.length - 1].pageX);
const left = this.headerCell ? this.headerCell.getBoundingClientRect().left : 0;
return right - left;
};

Expand Down Expand Up @@ -118,7 +120,7 @@ class HeaderCell extends React.Component {
'react-grid-HeaderCell--frozen': columnUtils.isFrozen(column)
}, this.props.className, column.cellClass);
const cell = (
<div className={className} style={this.getStyle()}>
<div ref={this.headerCellRef} className={className} style={this.getStyle()}>
{this.getCell()}
{resizeHandle}
</div>
Expand All @@ -129,8 +131,9 @@ class HeaderCell extends React.Component {
return (
<DraggableHeaderCell
column={column}
onHeaderDrop={this.props.onHeaderDrop}>
{cell}
onHeaderDrop={this.props.onHeaderDrop}
>
{cell}
</DraggableHeaderCell>
);
}
Expand Down