Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,17 @@ class List<T = any> extends React.Component<ListProps<T>, ListState<T>> {
const diff = findListDiffIndex(prevData, data, this.getItemKey);
changedItemIndex = diff ? diff.index : null;
}
/** check if height changed */
if (this.cachedProps.height < height) {
const scrollPtg = getElementScrollPercentage(this.listRef.current);
const visibleCount = Math.ceil(height / itemHeight);

const { startIndex, endIndex } = getRangeIndex(scrollPtg, data.length, visibleCount);
this.setState({
startIndex,
endIndex,
});
}
if (disabled) {
// Should trigger `onSkipRender` to tell that diff component is not render in the list
if (data.length > prevData.length) {
Expand Down
10 changes: 10 additions & 0 deletions tests/list.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@ describe('List', () => {
wrapper.setProps({ data, disabled: true });
expect(onSkipRender).toHaveBeenCalled();
});

it('should rerender rows when current height > previous height', () => {
scrollTop = 0;
const data = genData(100);
const wrapper = genList({ itemHeight: 20, height: 100, data, virtual: true });

wrapper.setProps({ height: 200 });
wrapper.update();
expect(wrapper.find('li').length).toEqual(11);
});
});

describe('status switch', () => {
Expand Down