Skip to content

Commit

Permalink
Make TableRow's style stable
Browse files Browse the repository at this point in the history
  • Loading branch information
yesmeck committed Oct 25, 2017
1 parent 3e5ad89 commit 0a9207b
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/TableRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class TableRow extends React.Component {
super(props);

this.shouldRender = props.visible;

// avoid creating new object which may fail the sCU.
this.style = {};
}

componentWillReceiveProps(nextProps) {
Expand Down Expand Up @@ -99,6 +102,20 @@ class TableRow extends React.Component {
store.setState({ expandedRowsHeight });
}

getStyle() {
const { height, visible } = this.props;

if (height && height !== this.style.height) {
this.style = { ...this.style, height };
}

if (!visible && !this.style.display) {
this.style = { ...this.style, display: 'none' };
}

return this.style;
}

saveRowRef = (node) => {
this.rowRef = node;
if (node) {
Expand All @@ -120,8 +137,6 @@ class TableRow extends React.Component {
index,
indent,
indentSize,
visible,
height,
hovered,
hasExpandIcon,
renderExpandIcon,
Expand Down Expand Up @@ -153,12 +168,6 @@ class TableRow extends React.Component {
);
}

const style = { height };

if (!visible) {
style.display = 'none';
}

const rowClassName =
`${prefixCls} ${className} ${prefixCls}-level-${indent}`.trim();

Expand All @@ -171,7 +180,7 @@ class TableRow extends React.Component {
onMouseLeave={this.onMouseLeave}
onContextMenu={this.onContextMenu}
className={rowClassName}
style={style}
style={this.getStyle()}
>
{cells}
</tr>
Expand Down

0 comments on commit 0a9207b

Please sign in to comment.