Skip to content
Merged
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
9 changes: 6 additions & 3 deletions src/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,11 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {

useLayoutEffect(() => {
// Firefox only
function onMozMousePixelScroll(e: Event) {
if (useVirtual) {
function onMozMousePixelScroll(e: WheelEvent) {
// scrolling at top/bottom limit
const scrollingUpAtTop = isScrollAtTop && e.detail < 0;
const scrollingDownAtBottom = isScrollAtBottom && e.detail > 0;
if (useVirtual && !scrollingUpAtTop && !scrollingDownAtBottom) {
e.preventDefault();
}
}
Expand All @@ -441,7 +444,7 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
componentEle.removeEventListener('DOMMouseScroll', onFireFoxScroll as any);
componentEle.removeEventListener('MozMousePixelScroll', onMozMousePixelScroll as any);
};
}, [useVirtual]);
}, [useVirtual, isScrollAtTop, isScrollAtBottom]);

// Sync scroll left
useLayoutEffect(() => {
Expand Down
55 changes: 55 additions & 0 deletions tests/scroll-Firefox.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,59 @@ describe('List.Firefox-Scroll', () => {
expect(wheelPreventDefault).not.toHaveBeenCalled();
expect(firefoxPreventDefault).toHaveBeenCalledTimes(1);
});

it('should call preventDefault on MozMousePixelScroll', () => {
const preventDefault = jest.fn();
const wrapper = genList({ itemHeight: 20, height: 100, data: genData(100) });
const ulElement = wrapper.find('ul').instance();

act(() => {
const event = new Event('MozMousePixelScroll');
event.detail = 6;
event.preventDefault = preventDefault;
ulElement.dispatchEvent(event);

jest.runAllTimers();
});

expect(preventDefault).toHaveBeenCalled();
});

it('should not call preventDefault on MozMousePixelScroll when scrolling up at top boundary', () => {
const preventDefault = jest.fn();
const wrapper = genList({ itemHeight: 20, height: 100, data: genData(100) });
const ulElement = wrapper.find('ul').instance();

act(() => {
const event = new Event('MozMousePixelScroll');
event.detail = -6;
event.preventDefault = preventDefault;
ulElement.dispatchEvent(event);

jest.runAllTimers();
});

expect(preventDefault).not.toHaveBeenCalled();
});
it('should not call preventDefault on MozMousePixelScroll when scrolling down at bottom boundary', () => {
const preventDefault = jest.fn();
const listRef = React.createRef();
const wrapper = genList({ itemHeight: 20, height: 100, data: genData(100), ref: listRef });
const ulElement = wrapper.find('ul').instance();
// scroll to bottom
listRef.current.scrollTo(99999);
jest.runAllTimers();
expect(wrapper.find('ul').instance().scrollTop).toEqual(1900);

act(() => {
const event = new Event('MozMousePixelScroll');
event.detail = 6;
event.preventDefault = preventDefault;
ulElement.dispatchEvent(event);

jest.runAllTimers();
});

expect(preventDefault).not.toHaveBeenCalled();
});
});