Skip to content

Commit e70b59a

Browse files
authored
fix: Cut content when size exceed (#186)
* fix: Cut content when size exceed * chore: comment
1 parent 14ee4db commit e70b59a

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

src/List.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,12 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
181181
itemTop = currentItemBottom;
182182
}
183183

184-
// Fallback to normal if not match. This code should never reach
185-
/* istanbul ignore next */
184+
// When scrollTop at the end but data cut to small count will reach this
186185
if (startIndex === undefined) {
187186
startIndex = 0;
188187
startOffset = 0;
188+
189+
endIndex = Math.ceil(height / itemHeight);
189190
}
190191
if (endIndex === undefined) {
191192
endIndex = mergedData.length - 1;

tests/scroll.test.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,18 +209,13 @@ describe('List.Scroll', () => {
209209
it('onScroll should trigger on correct target', () => {
210210
// Save in tmp variable since React will clean up this
211211
let currentTarget;
212-
const onScroll = jest.fn(e => {
212+
const onScroll = jest.fn((e) => {
213213
({ currentTarget } = e);
214214
});
215215
const wrapper = genList({ itemHeight: 20, height: 100, data: genData(100), onScroll });
216216
wrapper.find('.rc-virtual-list-holder').simulate('scroll');
217217

218-
expect(currentTarget).toBe(
219-
wrapper
220-
.find('.rc-virtual-list-holder')
221-
.hostNodes()
222-
.instance(),
223-
);
218+
expect(currentTarget).toBe(wrapper.find('.rc-virtual-list-holder').hostNodes().instance());
224219
});
225220

226221
describe('scroll should in range', () => {
@@ -269,5 +264,26 @@ describe('List.Scroll', () => {
269264

270265
expect(wrapper.find('ScrollBar').props().scrollTop).toEqual(1900);
271266
});
267+
268+
it('dynamic large to small', () => {
269+
const wrapper = genList({ itemHeight: 20, height: 100, data: genData(1000) });
270+
const ulElement = wrapper.find('ul').instance();
271+
272+
// To bottom
273+
act(() => {
274+
const wheelEvent = new Event('wheel');
275+
wheelEvent.deltaY = 9999999;
276+
ulElement.dispatchEvent(wheelEvent);
277+
278+
jest.runAllTimers();
279+
});
280+
281+
// Cut data len
282+
wrapper.setProps({
283+
data: genData(20),
284+
});
285+
286+
expect(wrapper.find('li').length).toBeLessThan(10);
287+
});
272288
});
273289
});

0 commit comments

Comments
 (0)