@@ -518,7 +518,7 @@ export default class Table extends React.Component {
key="bodyTable"
className={`${prefixCls}-body`}
style={bodyStyle}
- ref="bodyTable"
+ ref={this.saveRef('bodyTable')}
onScroll={this.handleBodyScroll}
>
{renderTable(!useFixedHeader)}
@@ -543,7 +543,7 @@ export default class Table extends React.Component {
{renderTable(!useFixedHeader)}
@@ -617,7 +617,7 @@ export default class Table extends React.Component {
}
setScrollPositionClassName(target) {
- const node = target || this.refs.bodyTable;
+ const node = target || this.bodyTable;
const scrollToLeft = node.scrollLeft === 0;
const scrollToRight = node.scrollLeft + 1 >=
node.children[0].getBoundingClientRect().width -
@@ -646,10 +646,10 @@ export default class Table extends React.Component {
return;
}
const { prefixCls } = this.props;
- const headRows = this.refs.headTable ?
- this.refs.headTable.querySelectorAll('thead') :
- this.refs.bodyTable.querySelectorAll('thead');
- const bodyRows = this.refs.bodyTable.querySelectorAll(`.${prefixCls}-row`) || [];
+ const headRows = this.headTable ?
+ this.headTable.querySelectorAll('thead') :
+ this.bodyTable.querySelectorAll('thead');
+ const bodyRows = this.bodyTable.querySelectorAll(`.${prefixCls}-row`) || [];
const fixedColumnsHeadRowsHeight = [].map.call(
headRows, row => row.getBoundingClientRect().height || 'auto'
);
@@ -667,11 +667,11 @@ export default class Table extends React.Component {
}
resetScrollX() {
- if (this.refs.headTable) {
- this.refs.headTable.scrollLeft = 0;
+ if (this.headTable) {
+ this.headTable.scrollLeft = 0;
}
- if (this.refs.bodyTable) {
- this.refs.bodyTable.scrollLeft = 0;
+ if (this.bodyTable) {
+ this.bodyTable.scrollLeft = 0;
}
}
@@ -692,7 +692,7 @@ export default class Table extends React.Component {
handleBodyScrollLeft = (e) => {
const target = e.target;
const { scroll = {} } = this.props;
- const { headTable, bodyTable } = this.refs;
+ const { headTable, bodyTable } = this;
if (target.scrollLeft !== this.lastScrollLeft && scroll.x) {
if (target === bodyTable && headTable) {
headTable.scrollLeft = target.scrollLeft;
@@ -708,7 +708,7 @@ export default class Table extends React.Component {
handleBodyScrollTop = (e) => {
const target = e.target;
const { scroll = {} } = this.props;
- const { headTable, bodyTable, fixedColumnsBodyLeft, fixedColumnsBodyRight } = this.refs;
+ const { headTable, bodyTable, fixedColumnsBodyLeft, fixedColumnsBodyRight } = this;
if (target.scrollTop !== this.lastScrollTop && scroll.y && target !== headTable) {
const scrollTop = target.scrollTop;
if (fixedColumnsBodyLeft && target !== fixedColumnsBodyLeft) {
@@ -736,6 +736,10 @@ export default class Table extends React.Component {
});
}
+ saveRef = (name) => (node) => {
+ this[name] = node;
+ }
+
render() {
const props = this.props;
const prefixCls = props.prefixCls;
@@ -767,7 +771,7 @@ export default class Table extends React.Component {
: content;
return (
-
(this.tableNode = node)} className={className} style={props.style}>
+
{this.getTitle()}
{scrollTable}
diff --git a/tests/Table.spec.js b/tests/Table.spec.js
index 0eb4c6a0b..8b2464892 100644
--- a/tests/Table.spec.js
+++ b/tests/Table.spec.js
@@ -132,10 +132,10 @@ describe('Table', () => {
/>
);
const inst = wrapper.instance();
- const headTable = wrapper.ref('headTable');
- const bodyTable = wrapper.ref('bodyTable');
- const fixedColumnsBodyLeft = wrapper.ref('fixedColumnsBodyLeft');
- const fixedColumnsBodyRight = wrapper.ref('fixedColumnsBodyRight');
+ const headTable = wrapper.wrap(inst.headTable);
+ const bodyTable = wrapper.wrap(inst.bodyTable);
+ const fixedColumnsBodyLeft = wrapper.wrap(inst.fixedColumnsBodyLeft);
+ const fixedColumnsBodyRight = wrapper.wrap(inst.fixedColumnsBodyRight);
expect(inst.lastScrollLeft).toBe(undefined);