Skip to content

Commit

Permalink
Fix bug: Page has no vertical scrollbar at begin, but appears the scr…
Browse files Browse the repository at this point in the history
…ollbar after expanding A table, and B table width also displays horizontal scrollbar.
  • Loading branch information
Tina C Lin (RD-TW) committed May 26, 2017
1 parent 28d64fd commit f87ea4e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
34 changes: 30 additions & 4 deletions src/Table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,26 @@ class Table extends PureComponent {
const footerHeight = this.foot ? this.foot.getBoundingClientRect().height : 0;
const tableHeight = maxHeight - headerHeight - footerHeight - parseInt(tableTopBorder, 10) - parseInt(tableBottomBorder, 10);
this.setState({ tableHeight });
},
getTableWidth: () => {
const tableWidth = this.tableWrapper.getBoundingClientRect().width;
if (tableWidth !== this.state.tableWidth) {
this.setState({ tableWidth });
}
}
};

componentDidMount() {
const { getTableHeight } = this.actions;
const { getTableHeight, getTableWidth } = this.actions;
window.addEventListener('resize', getTableHeight);
window.addEventListener('checkWidth', getTableWidth);
getTableHeight();
}

componentWillUnmount() {
const { getTableHeight } = this.actions;
const { getTableHeight, getTableWidth } = this.actions;
window.removeEventListener('resize', getTableHeight);
window.removeEventListener('checkWidth', getTableWidth);
}

componentDidUpdate(prevProps, prevState) {
Expand All @@ -97,6 +105,10 @@ class Table extends PureComponent {
prevProps.expandedRowKeys !== this.props.expandedRowKeys) {
const { getTableHeight } = this.actions;
getTableHeight();
// Issue: Page has no vertical scrollbar at begin, but appears the scrollbar after expanding A table,
// and B table width also displays horizontal scrollbar.
// Solution: Add this action to check other tables size in the same page.
window.dispatchEvent(new Event('checkWidth'));
}
}

Expand All @@ -105,6 +117,7 @@ class Table extends PureComponent {
currentHoverKey: null,
scrollTop: 0,
tableHeight: 0,
tableWidth: 0,
thisColumns: this.columnsParser()
};
}
Expand Down Expand Up @@ -136,14 +149,15 @@ class Table extends PureComponent {

renderTable() {
const columns = this.state.thisColumns;
const { currentHoverKey, scrollTop, tableHeight } = this.state;
const { currentHoverKey, scrollTop, tableHeight, tableWidth } = this.state;
const { detectScrollTarget, handleBodyScroll, handleRowHover } = this.actions;
return (
<TableTemplate
{...this.props}
columns={columns}
currentHoverKey={currentHoverKey}
maxHeight={tableHeight}
maxWidth={tableWidth}
onMouseOver={detectScrollTarget}
onRowHover={handleRowHover}
onTouchStart={detectScrollTarget}
Expand All @@ -157,7 +171,7 @@ class Table extends PureComponent {
}

renderFixedLeftTable() {
const { currentHoverKey, scrollTop, tableHeight } = this.state;
const { currentHoverKey, scrollTop, tableHeight, tableWidth } = this.state;
const { detectScrollTarget, handleBodyScroll, handleRowHover } = this.actions;
let fixedColumns = this.leftColumns();
return (
Expand All @@ -167,6 +181,7 @@ class Table extends PureComponent {
currentHoverKey={currentHoverKey}
className={styles.tableFixedLeftContainer}
maxHeight={tableHeight}
maxWidth={tableWidth}
isFixed={true}
onMouseOver={detectScrollTarget}
onRowHover={handleRowHover}
Expand Down Expand Up @@ -223,6 +238,7 @@ class Table extends PureComponent {

render() {
const {
className,
loading,
bordered,
title,
Expand All @@ -234,9 +250,19 @@ class Table extends PureComponent {
...props
} = this.props;

delete props.rowKey;
delete props.columns;
delete props.expandedRowRender;
delete props.expandedRowKeys;
delete props.maxHeight;
delete props.rowClassName;
delete props.onRowClick;

return (
<div
{...props}
className={classNames(
className,
styles.tableWrapper,
{ [styles.tableMinimalism]: !bordered },
{ [styles.tableBordered]: bordered },
Expand Down
2 changes: 2 additions & 0 deletions src/TableTemplate.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class TableTemplate extends PureComponent {
isFixed: PropTypes.bool,
loading: PropTypes.bool,
maxHeight: PropTypes.number,
maxWidth: PropTypes.number,
onMouseOver: PropTypes.func,
onTouchStart: PropTypes.func,
onScroll: PropTypes.func,
Expand Down Expand Up @@ -374,6 +375,7 @@ class TableTemplate extends PureComponent {
componentDidUpdate(prevProps, prevState) {
if (prevProps.data !== this.props.data ||
prevProps.maxHeight !== this.props.maxHeight ||
prevProps.maxWidth !== this.props.maxWidth ||
prevProps.expandedRowKeys !== this.props.expandedRowKeys) {
const { getTableHeight } = this.actions;
getTableHeight();
Expand Down

0 comments on commit f87ea4e

Please sign in to comment.