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

#1803 feat: ✨ add containerStyle to List Component #1804

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/List.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ That means that `List` also accepts [`Grid` props](Grid.md) in addition to the p
| :---------------- | :----------------- | :-------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| autoHeight | Boolean | | Outer `height` of `List` is set to "auto". This property should only be used in conjunction with the `WindowScroller` HOC. |
| className | String | | Optional custom CSS class name to attach to root `List` element. |
| containerStyle | Object | | Optional custom inline style to attach to inner cell-container element. |
| estimatedRowSize | Number | | Used to estimate the total height of a `List` before all of its rows have actually been measured. The estimated total height is adjusted as rows are rendered. |
| height | Number | ✓ | Height constraint for list (determines how many actual rows are rendered) |
| id | String | | Optional custom id to attach to root `List` element. |
Expand Down
1 change: 0 additions & 1 deletion source/Grid/Grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,6 @@ class Grid extends React.PureComponent<Props, State> {
maxHeight: totalRowsHeight,
overflow: 'hidden',
pointerEvents: isScrolling ? 'none' : '',
position: 'relative',
...containerStyle,
}}>
{childrenToDisplay}
Expand Down
9 changes: 9 additions & 0 deletions source/List/List.jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,15 @@ describe('List', () => {
const cell = rendered.querySelector('.listItem');
expect(cell.style.width).toEqual('100%');
});

it('should use a custom :containerStyle if specified', () => {
const containerStyle = {backgroundColor: 'red'};
const rendered = findDOMNode(render(getMarkup({containerStyle})));
expect(
rendered.querySelector('.ReactVirtualized__Grid__innerScrollContainer')
.style.backgroundColor,
).toEqual('red');
});
});

describe('overscanRowCount', () => {
Expand Down
13 changes: 12 additions & 1 deletion source/List/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ type Props = {

/** Width of list */
width: number,

/** Optional inline style applied to inner cell-container */
containerStyle: Object,
};

export default class List extends React.PureComponent<Props> {
Expand All @@ -108,6 +111,7 @@ export default class List extends React.PureComponent<Props> {
scrollToAlignment: 'auto',
scrollToIndex: -1,
style: {},
containerStyle: {},
};

Grid: ?React.ElementRef<typeof Grid>;
Expand Down Expand Up @@ -187,7 +191,13 @@ export default class List extends React.PureComponent<Props> {
}

render() {
const {className, noRowsRenderer, scrollToIndex, width} = this.props;
const {
className,
noRowsRenderer,
scrollToIndex,
width,
containerStyle,
} = this.props;

const classNames = clsx('ReactVirtualized__List', className);

Expand All @@ -199,6 +209,7 @@ export default class List extends React.PureComponent<Props> {
className={classNames}
columnWidth={width}
columnCount={1}
containerStyle={containerStyle}
noContentRenderer={noRowsRenderer}
onScroll={this._onScroll}
onSectionRendered={this._onSectionRendered}
Expand Down