Skip to content

Commit e87a915

Browse files
authored
fix: scroll issue (#103)
1 parent a723899 commit e87a915

File tree

2 files changed

+41
-22
lines changed

2 files changed

+41
-22
lines changed

src/List.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
211211
if (!Number.isNaN(maxScrollHeightRef.current)) {
212212
newTop = Math.min(newTop, maxScrollHeightRef.current);
213213
}
214-
newTop = Math.max(newScrollTop, 0);
214+
newTop = Math.max(newTop, 0);
215215
return newTop;
216216
}
217217

tests/scroll.test.js

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -223,32 +223,51 @@ describe('List.Scroll', () => {
223223
);
224224
});
225225

226-
it('scroll should in range', () => {
227-
const wrapper = genList({ itemHeight: 20, height: 100, data: genData(100) });
228-
const ulElement = wrapper.find('ul').instance();
226+
describe('scroll should in range', () => {
227+
it('less than 0', () => {
228+
const wrapper = genList({ itemHeight: 20, height: 100, data: genData(100) });
229+
const ulElement = wrapper.find('ul').instance();
229230

230-
act(() => {
231-
const wheelEvent = new Event('wheel');
232-
wheelEvent.deltaY = 9999999;
233-
ulElement.dispatchEvent(wheelEvent);
231+
act(() => {
232+
const wheelEvent = new Event('wheel');
233+
wheelEvent.deltaY = 9999999;
234+
ulElement.dispatchEvent(wheelEvent);
234235

235-
jest.runAllTimers();
236-
});
236+
jest.runAllTimers();
237+
});
237238

238-
wrapper.setProps({ data: genData(1) });
239-
act(() => {
240-
wrapper
241-
.find('.rc-virtual-list-holder')
242-
.props()
243-
.onScroll({
244-
currentTarget: {
245-
scrollTop: 0,
246-
},
247-
});
239+
wrapper.setProps({ data: genData(1) });
240+
act(() => {
241+
wrapper
242+
.find('.rc-virtual-list-holder')
243+
.props()
244+
.onScroll({
245+
currentTarget: {
246+
scrollTop: 0,
247+
},
248+
});
249+
});
250+
251+
wrapper.setProps({ data: genData(100) });
252+
253+
expect(wrapper.find('ScrollBar').props().scrollTop).toEqual(0);
248254
});
249255

250-
wrapper.setProps({ data: genData(100) });
256+
it('over max height', () => {
257+
const wrapper = genList({ itemHeight: 20, height: 100, data: genData(100) });
258+
const ulElement = wrapper.find('ul').instance();
251259

252-
expect(wrapper.find('ScrollBar').props().scrollTop).toEqual(0);
260+
act(() => {
261+
const wheelEvent = new Event('wheel');
262+
wheelEvent.deltaY = 9999999;
263+
ulElement.dispatchEvent(wheelEvent);
264+
265+
jest.runAllTimers();
266+
});
267+
268+
wrapper.update();
269+
270+
expect(wrapper.find('ScrollBar').props().scrollTop).toEqual(1900);
271+
});
253272
});
254273
});

0 commit comments

Comments
 (0)