Skip to content

Commit 4a123b3

Browse files
committed
fix: Firefox should prevent scroll
1 parent a4cb1c4 commit 4a123b3

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

examples/basic.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const Demo = () => {
5656

5757
return (
5858
<React.StrictMode>
59-
<div>
59+
<div style={{ height: '200vh' }}>
6060
<h2>Basic</h2>
6161
{TYPES.map(({ name, type: nType }) => (
6262
<label key={nType}>

src/List.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,19 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
247247
});
248248

249249
React.useEffect(() => {
250+
// Firefox only
251+
function onMozMousePixelScroll(e: Event) {
252+
e.preventDefault();
253+
}
254+
250255
componentRef.current.addEventListener('wheel', onRawWheel);
251256
componentRef.current.addEventListener('DOMMouseScroll', onFireFoxScroll as any);
257+
componentRef.current.addEventListener('MozMousePixelScroll', onMozMousePixelScroll);
258+
252259
return () => {
253260
componentRef.current.removeEventListener('wheel', onRawWheel);
254261
componentRef.current.removeEventListener('DOMMouseScroll', onFireFoxScroll as any);
262+
componentRef.current.removeEventListener('MozMousePixelScroll', onMozMousePixelScroll as any);
255263
};
256264
}, [inVirtual]);
257265

src/hooks/useFrameWheel.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ export default function useFrameWheel(
5454
function onFireFoxScroll(event: FireFoxDOMMouseScrollEvent) {
5555
if (!inVirtual) return;
5656

57-
// Firefox level stop
58-
event.preventDefault();
59-
6057
isMouseScrollRef.current = event.detail === wheelValueRef.current;
6158
}
6259

tests/scroll-Firefox.test.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ describe('List.Firefox-Scroll', () => {
6868
wheelEvent.preventDefault = wheelPreventDefault;
6969
ulElement.dispatchEvent(wheelEvent);
7070

71+
const firefoxPixelScrollEvent = new Event('MozMousePixelScroll');
72+
firefoxPixelScrollEvent.detail = 6;
73+
firefoxPixelScrollEvent.preventDefault = firefoxPreventDefault;
74+
ulElement.dispatchEvent(firefoxPixelScrollEvent);
75+
7176
const firefoxScrollEvent = new Event('DOMMouseScroll');
7277
firefoxScrollEvent.detail = 3;
7378
firefoxScrollEvent.preventDefault = firefoxPreventDefault;
@@ -77,6 +82,6 @@ describe('List.Firefox-Scroll', () => {
7782
});
7883

7984
expect(wheelPreventDefault).not.toHaveBeenCalled();
80-
expect(firefoxPreventDefault).toHaveBeenCalled();
85+
expect(firefoxPreventDefault).toHaveBeenCalledTimes(1);
8186
});
8287
});

0 commit comments

Comments
 (0)