Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with child component having scrollable body #16

Open
ArunNGun opened this issue Nov 24, 2022 · 1 comment
Open

Issue with child component having scrollable body #16

ArunNGun opened this issue Nov 24, 2022 · 1 comment

Comments

@ArunNGun
Copy link

Unable to scroll child component when wrapped inside the

I may be wrong or missing out on something, If someone knows how to fix it please let me know

reproducible code
https://codesandbox.io/s/smooth-scrollbar-react-forked-m3kdvf?file=/src/App.tsx

@nghiepdev
Copy link
Owner

nghiepdev commented Nov 26, 2022

Hey @C4PT4INNULL This issue has been resolved in idiotWu/smooth-scrollbar#92 (comment)
In the real world, we can make a hook to enable a native scrollbar inside to stop events from propagating

import { useEffect, useRef } from "react";

const EventTypes = ["touchmove", "mousewheel", "wheel"] as const;

export function useStopWheel() {
  const ref = useRef<HTMLElement>(null);

  useEffect(() => {
    const handler = (e: Event) => e.stopPropagation();

    EventTypes.forEach((eventType) => {
      ref.current?.addEventListener(eventType, handler);
    });

    return () => {
      EventTypes.forEach((eventType) => {
        ref.current?.removeEventListener(eventType, handler);
      });
    };
  }, []);

  return ref;
}

And use in somewhere

const stopWheelRef = useStopWheel();
return (
  <div ref={stopWheelRef} className="dropdown-content">
     <div>item 1</div>
     <div>item 2</div>
     <div>item 3</div>
  </div>
)

Finally, this is a fork to implement https://codesandbox.io/s/smooth-scrollbar-react-forked-k7gz8o?file=/src/Select.jsx:317-329

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants