Skip to content

Commit

Permalink
fix: handle NaN itemCount in scroll lists
Browse files Browse the repository at this point in the history
  • Loading branch information
marbemac committed Apr 17, 2020
1 parent 75016a3 commit 34b2f5c
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/ScrollList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ const FixedSizeList: React.FunctionComponent<IFixedSizeListProps> = React.forwar
ReactWindow.FixedSizeList,
IFixedSizeListProps
>(function FixedSizeList(props, ref) {
const { className, children, itemSize, itemCount, instanceRef, maxRows, style, autoSize, ...rest } = props;
let { className, children, itemSize, itemCount, instanceRef, maxRows, style, autoSize, ...rest } = props;
if (isNaN(itemCount)) {
itemCount = 0;
}

const listHeight = Math.min(itemCount, maxRows || Infinity) * itemSize;

const renderList = ({ height, width }: { height?: number; width?: number } = {}) => {
Expand All @@ -52,7 +56,7 @@ const FixedSizeList: React.FunctionComponent<IFixedSizeListProps> = React.forwar
ref={instanceRef}
itemSize={itemSize}
itemCount={itemCount}
height={height ? Math.min(height, listHeight) : listHeight}
height={(height ? Math.min(height, listHeight) : listHeight) || 0}
width={width || '100%'}
// className gets passed to ScrollList-Content
className={className}
Expand Down Expand Up @@ -87,7 +91,11 @@ const VariableSizeList: React.FunctionComponent<IVariableSizeListProps> = React.
ReactWindow.VariableSizeList,
IVariableSizeListProps
>(function VariableSizeList(props, ref) {
const { children, instanceRef, ...rest } = props;
let { children, instanceRef, itemCount, ...rest } = props;

if (isNaN(itemCount)) {
itemCount = 0;
}

return (
<AutoSizer>
Expand All @@ -97,6 +105,7 @@ const VariableSizeList: React.FunctionComponent<IVariableSizeListProps> = React.
ref={instanceRef}
height={height}
width={width}
itemCount={itemCount}
outerRef={ref}
outerElementType={CustomScrollContainer}
>
Expand Down

0 comments on commit 34b2f5c

Please sign in to comment.