Skip to content

Commit 135d5cd

Browse files
author
John
authored
Merge pull request #1 from react-component/master
merga
2 parents 8f04a8c + 7b5e1a6 commit 135d5cd

File tree

4 files changed

+42
-42
lines changed

4 files changed

+42
-42
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rc-table",
3-
"version": "5.4.0",
3+
"version": "5.4.2",
44
"description": "table ui component for react",
55
"keywords": [
66
"react",

src/Table.jsx

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -508,9 +508,7 @@ export default class Table extends React.Component {
508508
className={`${prefixCls}-header`}
509509
ref={fixed ? null : 'headTable'}
510510
style={headStyle}
511-
onMouseOver={this.detectScrollTarget}
512-
onTouchStart={this.detectScrollTarget}
513-
onScroll={this.handleBodyScroll}
511+
onScroll={this.handleBodyScrollLeft}
514512
>
515513
{renderTable(true, false)}
516514
</div>
@@ -523,8 +521,6 @@ export default class Table extends React.Component {
523521
className={`${prefixCls}-body`}
524522
style={bodyStyle}
525523
ref="bodyTable"
526-
onMouseOver={this.detectScrollTarget}
527-
onTouchStart={this.detectScrollTarget}
528524
onScroll={this.handleBodyScroll}
529525
>
530526
{renderTable(!useFixedHeader)}
@@ -550,8 +546,6 @@ export default class Table extends React.Component {
550546
className={`${prefixCls}-body-inner`}
551547
style={innerBodyStyle}
552548
ref={refName}
553-
onMouseOver={this.detectScrollTarget}
554-
onTouchStart={this.detectScrollTarget}
555549
onScroll={this.handleBodyScroll}
556550
>
557551
{renderTable(!useFixedHeader)}
@@ -686,46 +680,50 @@ export default class Table extends React.Component {
686680
return typeof this.findExpandedRow(record, index) !== 'undefined';
687681
}
688682

689-
detectScrollTarget = (e) => {
690-
if (this.scrollTarget !== e.currentTarget) {
691-
this.scrollTarget = e.currentTarget;
692-
}
693-
}
694-
695683
hasScrollX() {
696684
const { scroll = {} } = this.props;
697685
return 'x' in scroll;
698686
}
699687

700-
handleBodyScroll = (e) => {
701-
// Prevent scrollTop setter trigger onScroll event
702-
// http://stackoverflow.com/q/1386696
703-
if (e.target !== this.scrollTarget) {
704-
return;
705-
}
688+
handleBodyScrollLeft = (e) => {
689+
const target = e.target;
706690
const { scroll = {} } = this.props;
707-
const { headTable, bodyTable, fixedColumnsBodyLeft, fixedColumnsBodyRight } = this.refs;
708-
if (scroll.x && e.target.scrollLeft !== this.lastScrollLeft) {
709-
if (e.target === bodyTable && headTable) {
710-
headTable.scrollLeft = e.target.scrollLeft;
711-
} else if (e.target === headTable && bodyTable) {
712-
bodyTable.scrollLeft = e.target.scrollLeft;
691+
const { headTable, bodyTable } = this.refs;
692+
if (target.scrollLeft !== this.lastScrollLeft && scroll.x) {
693+
if (target === bodyTable && headTable) {
694+
headTable.scrollLeft = target.scrollLeft;
695+
} else if (target === headTable && bodyTable) {
696+
bodyTable.scrollLeft = target.scrollLeft;
713697
}
714-
this.setScrollPositionClassName(e.target);
698+
this.setScrollPositionClassName(target);
715699
}
716-
if (scroll.y) {
717-
if (fixedColumnsBodyLeft && e.target !== fixedColumnsBodyLeft) {
718-
fixedColumnsBodyLeft.scrollTop = e.target.scrollTop;
700+
// Remember last scrollLeft for scroll direction detecting.
701+
this.lastScrollLeft = target.scrollLeft;
702+
}
703+
704+
handleBodyScrollTop = (e) => {
705+
const target = e.target;
706+
const { scroll = {} } = this.props;
707+
const { headTable, bodyTable, fixedColumnsBodyLeft, fixedColumnsBodyRight } = this.refs;
708+
if (target.scrollTop !== this.lastScrollTop && scroll.y && target !== headTable) {
709+
const scrollTop = target.scrollTop;
710+
if (fixedColumnsBodyLeft && target !== fixedColumnsBodyLeft) {
711+
fixedColumnsBodyLeft.scrollTop = scrollTop;
719712
}
720-
if (fixedColumnsBodyRight && e.target !== fixedColumnsBodyRight) {
721-
fixedColumnsBodyRight.scrollTop = e.target.scrollTop;
713+
if (fixedColumnsBodyRight && target !== fixedColumnsBodyRight) {
714+
fixedColumnsBodyRight.scrollTop = scrollTop;
722715
}
723-
if (bodyTable && e.target !== bodyTable) {
724-
bodyTable.scrollTop = e.target.scrollTop;
716+
if (bodyTable && target !== bodyTable) {
717+
bodyTable.scrollTop = scrollTop;
725718
}
726719
}
727-
// Remember last scrollLeft for scroll direction detecting.
728-
this.lastScrollLeft = e.target.scrollLeft;
720+
// Remember last scrollTop for scroll direction detecting.
721+
this.lastScrollTop = target.scrollTop;
722+
}
723+
724+
handleBodyScroll = (e) => {
725+
this.handleBodyScrollLeft(e);
726+
this.handleBodyScrollTop(e);
729727
}
730728

731729
handleRowHover = (isHover, key) => {

src/TableRow.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ export default class TableRow extends React.Component {
4141
static defaultProps = {
4242
onRowClick() {},
4343
onRowDoubleClick() {},
44+
onRowMouseEnter() {},
45+
onRowMouseLeave() {},
4446
onDestroy() {},
4547
expandIconColumnIndex: 0,
4648
expandRowByClick: false,

tests/__snapshots__/Table.expandRow.spec.js.snap

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ exports[`Table.expand controlled by expandedRowKeys 1`] = `
6767
className="rc-table-content">
6868
<div
6969
className="rc-table-body"
70-
onMouseOver={[Function]}
7170
onScroll={[Function]}
72-
onTouchStart={[Function]}
7371
style={Object {}}>
7472
<table
7573
className=""
@@ -300,6 +298,8 @@ exports[`Table.expand controlled by expandedRowKeys 1`] = `
300298
onHover={[Function]}
301299
onRowClick={[Function]}
302300
onRowDoubleClick={[Function]}
301+
onRowMouseEnter={[Function]}
302+
onRowMouseLeave={[Function]}
303303
prefixCls="rc-table-expanded-row"
304304
rowKey="0-extra-row"
305305
store={
@@ -591,9 +591,7 @@ exports[`Table.expand controlled by expandedRowKeys 2`] = `
591591
className="rc-table-content">
592592
<div
593593
className="rc-table-body"
594-
onMouseOver={[Function]}
595594
onScroll={[Function]}
596-
onTouchStart={[Function]}
597595
style={Object {}}>
598596
<table
599597
className=""
@@ -978,6 +976,8 @@ exports[`Table.expand controlled by expandedRowKeys 2`] = `
978976
onHover={[Function]}
979977
onRowClick={[Function]}
980978
onRowDoubleClick={[Function]}
979+
onRowMouseEnter={[Function]}
980+
onRowMouseLeave={[Function]}
981981
prefixCls="rc-table-expanded-row"
982982
rowKey="1-extra-row"
983983
store={
@@ -1203,9 +1203,7 @@ exports[`Table.expand expand row by click 1`] = `
12031203
className="rc-table-content">
12041204
<div
12051205
className="rc-table-body"
1206-
onMouseOver={[Function]}
12071206
onScroll={[Function]}
1208-
onTouchStart={[Function]}
12091207
style={Object {}}>
12101208
<table
12111209
className=""
@@ -1436,6 +1434,8 @@ exports[`Table.expand expand row by click 1`] = `
14361434
onHover={[Function]}
14371435
onRowClick={[Function]}
14381436
onRowDoubleClick={[Function]}
1437+
onRowMouseEnter={[Function]}
1438+
onRowMouseLeave={[Function]}
14391439
prefixCls="rc-table-expanded-row"
14401440
rowKey="0-extra-row"
14411441
store={

0 commit comments

Comments
 (0)