react-custom-scrollbars-2 icon indicating copy to clipboard operation
react-custom-scrollbars-2 copied to clipboard

Inside iframe this component does not render a custom scrollbar but a native scrollbar

Open saxenarajat opened this issue 2 years ago • 2 comments

As soon as, I switch the tabs and come back to the original tab, the native scrollbar is replaced with the custom scrollbar. Can anybody tell me what this behavior is?

Thanks for this library.

saxenarajat avatar Aug 25 '22 11:08 saxenarajat

I had the same issue. My problem was that iframe was rendering content with style display:none, so scroll was not able to get the actual container height

alexaaaant avatar Sep 05 '22 09:09 alexaaaant

Thanks for the tip @alexaaaant. The following seems to work for loading my component within an iframe:

  const [windowWidth, setWindowWidth] = useState(window.innerWidth);
  const [windowHeight, setWindowHeight] = useState(window.innerHeight);

  const onResize = useCallback(() => {
    setWindowWidth(window.innerWidth);
    setWindowHeight(window.innerHeight);
  }, []);

  useEffect(() => {
    window.addEventListener('resize', onResize);
    return () => { window.removeEventListener('resize', onResize) };
  }, [onResize]);
{!!windowWidth && !!windowHeight && <Scrollbars>...</Scrollbars>}

d2r-app avatar Mar 31 '23 12:03 d2r-app