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

Add options to hide MultiGrid top-right and bottom-left grid scrollbars but still make the scroll events work on those grids #1040

Merged
merged 10 commits into from
May 15, 2018
Merged
2 changes: 2 additions & 0 deletions source/MultiGrid/MultiGrid.example.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ export default class MultiGridExample extends React.PureComponent {
styleTopLeftGrid={STYLE_TOP_LEFT_GRID}
styleTopRightGrid={STYLE_TOP_RIGHT_GRID}
width={width}
hideTopRightGridScrollbar
hideBottomLeftGridScrollbar
/>
)}
</AutoSizer>
Expand Down
74 changes: 65 additions & 9 deletions source/MultiGrid/MultiGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export default class MultiGrid extends React.PureComponent {
styleBottomRightGrid: PropTypes.object.isRequired,
styleTopLeftGrid: PropTypes.object.isRequired,
styleTopRightGrid: PropTypes.object.isRequired,
hideTopRightGridScrollbar: PropTypes.bool,
hideBottomLeftGridScrollbar: PropTypes.bool,
};

static defaultProps = {
Expand All @@ -47,6 +49,8 @@ export default class MultiGrid extends React.PureComponent {
styleBottomRightGrid: {},
styleTopLeftGrid: {},
styleTopRightGrid: {},
hideTopRightGridScrollbar: false,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I don't think there is a need to specify defaultProps for these. Since it would be undefined if not passed in. Which is a falsey value

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added because there was an existing pattern for enableFixedColumnScroll and enableFixedRowScroll. So followed it.

hideBottomLeftGridScrollbar: false,
};

constructor(props, context) {
Expand Down Expand Up @@ -82,6 +86,8 @@ export default class MultiGrid extends React.PureComponent {
this._rowHeightBottomGrid = this._rowHeightBottomGrid.bind(this);
this._topLeftGridRef = this._topLeftGridRef.bind(this);
this._topRightGridRef = this._topRightGridRef.bind(this);
this._renderBottomLeftGrid = this._renderBottomLeftGrid.bind(this);
this._renderTopRightGrid = this._renderTopRightGrid.bind(this);
}

forceUpdateGrids() {
Expand Down Expand Up @@ -623,33 +629,52 @@ export default class MultiGrid extends React.PureComponent {
fixedRowCount,
rowCount,
scrollTop,
hideBottomLeftGridScrollbar,
} = props;
const {showVerticalScrollbar} = this.state;

if (!fixedColumnCount) {
return null;
}

const additionalRowCount = showVerticalScrollbar ? 1 : 0;
const additionalRowCount = showVerticalScrollbar ? 1 : 0,
height = this._getBottomGridHeight(props),
width = this._getLeftGridWidth(props),
scrollbarSize = this.state.showVerticalScrollbar ? this.state.scrollbarSize : 0,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scrollbarSize is now in state.instanceProps.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think state structure change in Grid but not in MutliGrid so it is working fine.
Also, I ran yarn lint and it seem to be all good too.

So we are good here?

gridWidth = hideBottomLeftGridScrollbar ? width + scrollbarSize : width;

return (
const bottomLeftGrid = (
<Grid
{...props}
cellRenderer={this._cellRendererBottomLeftGrid}
className={this.props.classNameBottomLeftGrid}
columnCount={fixedColumnCount}
deferredMeasurementCache={this._deferredMeasurementCacheBottomLeftGrid}
height={this._getBottomGridHeight(props)}
height={height}
onScroll={enableFixedColumnScroll ? this._onScrollTop : undefined}
ref={this._bottomLeftGridRef}
rowCount={Math.max(0, rowCount - fixedRowCount) + additionalRowCount}
rowHeight={this._rowHeightBottomGrid}
scrollTop={scrollTop}
style={this._bottomLeftGridStyle}
tabIndex={null}
width={this._getLeftGridWidth(props)}
width={gridWidth}
/>
);

if (hideBottomLeftGridScrollbar) {
return (
<div
style={{
...this._bottomLeftGridStyle,
height,
width,
}}>
{bottomLeftGrid}
</div>
);
}
return bottomLeftGrid;
}

_renderBottomRightGrid(props) {
Expand Down Expand Up @@ -713,16 +738,32 @@ export default class MultiGrid extends React.PureComponent {
fixedColumnCount,
fixedRowCount,
scrollLeft,
hideTopRightGridScrollbar,
} = props;
const {showHorizontalScrollbar} = this.state;

if (!fixedRowCount) {
return null;
}

const additionalColumnCount = showHorizontalScrollbar ? 1 : 0;
const additionalColumnCount = showHorizontalScrollbar ? 1 : 0,
height = this._getTopGridHeight(props),
width = this._getRightGridWidth(props),
scrollbarSize = this.state.showHorizontalScrollbar ? this.state.scrollbarSize : 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: showHorizontalScrollbar is already deconstructed above. scrollbarSize can also be put there.


return (
let gridHeight = height,
style = this._topRightGridStyle;

if (hideTopRightGridScrollbar) {
gridHeight = height + scrollbarSize;
style = {
...this._topRightGridStyle,
position: 'relative',
left: 0,
};
}

const topRightGrid = (
<Grid
{...props}
cellRenderer={this._cellRendererTopRightGrid}
Expand All @@ -732,16 +773,31 @@ export default class MultiGrid extends React.PureComponent {
}
columnWidth={this._columnWidthRightGrid}
deferredMeasurementCache={this._deferredMeasurementCacheTopRightGrid}
height={this._getTopGridHeight(props)}
height={gridHeight}
onScroll={enableFixedRowScroll ? this._onScrollLeft : undefined}
ref={this._topRightGridRef}
rowCount={fixedRowCount}
scrollLeft={scrollLeft}
style={this._topRightGridStyle}
style={style}
tabIndex={null}
width={this._getRightGridWidth(props)}
width={width}
/>
);

if (hideTopRightGridScrollbar) {
return (
<div
style={{
...this._topRightGridStyle,
height,
width,
overflowX: 'hidden',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need to wrap it in another div

If you need to. you can just modify this._topRightGridStyle

this._topRightGridStyle = {
   ...this._topRightGridStyle,
   height,
   width, 
   overflowX: 'hidden'
}

Unless Im misunderstanding something :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. We need this extra wrapper so we can hide the scrollbar with a hack.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wuweiweiwu , are you waiting for some change here?

}}>
{topRightGrid}
</div>
);
}
return topRightGrid;
}

_rowHeightBottomGrid({index}) {
Expand Down