react-component / react-component/virtual-list
嵌套滚动内容时,内部滚动效果会直接穿透到外层虚拟列表不生效
Open
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 814
- Forks
- 171
- Avg merge
- 1h 3m
- Merged PRs (30d)
- 3
Description
目前只能用这种方法在内部滚动区域拦截 wheelCapture 事件,有没有什么更简洁的方法呢
import {UIEvent, useCallback, useEffect, useRef, WheelEvent} from 'react';
export const useProxyWheel = (ref: HTMLElement | null) => {
const canDeltaUp = useRef(false);
const canDeltaDown = useRef(false);
const onWheelCapture = (e: WheelEvent<HTMLElement>) => {
if (e.deltaY > 0 && !canDeltaDown.current) {
e.stopPropagation();
}
if (e.deltaY < 0 && !canDeltaUp.current) {
e.stopPropagation();
}
};
const calculate = (target: HTMLElement) => {
if (target.scrollTop + target.clientHeight >= target.scrollHeight - 2) {
canDeltaDown.current = true;
canDeltaUp.current = false;
} else if (target.scrollTop === 0) {
canDeltaDown.current = false;
canDeltaUp.current = true;
} else {
canDeltaDown.current = false;
canDeltaUp.current = false;
}
};
const onScroll = (e: UIEvent<HTMLElement>) => {
calculate(e.target as HTMLElement);
};
const resizeObserver = useRef<ResizeObserver>(
new ResizeObserver(() => {
ref && calculate(ref);
})
);
const cleanupFn = useCallback(() => {
ref && resizeObserver.current.unobserve(ref);
}, [ref]);
useEffect(() => {
if (ref) {
calculate(ref);
resizeObserver.current.observe(ref);
}
return cleanupFn;
}, [cleanupFn, ref]);
return {
onWheelCapture,
onScroll,
};
};
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing nested scrolling in the virtual list and review the provided useProxyWheel hook, especially its onWheelCapture and onScroll entry points. Done means inner scrolling no longer leaks to the outer virtual list at the inner boundary, while the outer list still responds when appropriate; no repository file or test is named.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100