react-component / react-component/virtual-list

嵌套滚动内容时,内部滚动效果会直接穿透到外层虚拟列表不生效

Open
#292 0 comments 0 reactions 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.