OverlayScrollbars icon indicating copy to clipboard operation
OverlayScrollbars copied to clipboard

Support react-window library

Open Media-Evil opened this issue 5 years ago • 11 comments

this does not work

import { OverlayScrollbarsComponent } from 'overlayscrollbars-react'
import  { FixedSizeList } from 'react-window'

//oversimplified!
<OverlayScrollbarsComponent>
  <FixedSizeList>
    //content
  </FixedSizeList>
</OverlayScrollbarsComponent>

Media-Evil avatar Oct 10 '19 14:10 Media-Evil

Good day!

I'm aware of a bug which prevents the usage of structural directives like v-for in Vue. I've also tested this with React and could confirm the same bug here. It's possible this bug is also prevent your solution from working. Luckily I've already fixed this bug and made some general improvements to the component wrappers.

This update (v1.10.0) should come very soon (maybe today in fact). In the meantime you could try to create a simple example on StackBlitz or CodeSandbox in case the new release won't fix your problem.

KingSora avatar Oct 10 '19 16:10 KingSora

@Media-Evil The new version is now here. Please test it!

KingSora avatar Oct 11 '19 09:10 KingSora

Tested with lists. Native scrollbars still persist if component is passed as a child to <OverlayScrollbarsComponent>. There are no problems with html tagnames though.

Do component wrappers now support textareas?

Media-Evil avatar Oct 11 '19 14:10 Media-Evil

@Media-Evil no they arent yet!

Could you create a example on one of the pages mentioned above, so I could take a look and identify the issue, else I cant really help you out.

KingSora avatar Oct 11 '19 14:10 KingSora

https://stackblitz.com/edit/react-rqbfe8

Media-Evil avatar Oct 11 '19 15:10 Media-Evil

Thanks!

Thats no bug, since react-window is a library which already provides its own viewport and therefore scrollcontainer. But theres a possibility to support it, but I'm not quite sure how to implement it yet.

KingSora avatar Oct 12 '19 21:10 KingSora

I managed to make it work with react-window. You can set an outerElementType and pass the scroll event to the corresponding element. This is how:

const Overflow = ({ children, onScroll }) => {
  const ofRef = useRef(null);

  useEffect(() => {
    const el = ofRef.current.osInstance().getElements().viewport;

    if (onScroll) el.addEventListener('scroll', onScroll);

    return () => {
      if (onScroll) el.removeEventListener('scroll', onScroll);
    };
  }, [onScroll]);

  return (
    <OverlayScrollbarsComponent
      options={options}
      ref={ofRef}
    >
      {children}
    </OverlayScrollbarsComponent>
  );
};

And then, in your virtualized component:

<FixedSizeGrid
  {...props}
   outerElementType={Overflow}
>

I'm using this with FixedSizeGrid but it should work the same for lists.

Hope it helps.

joa-queen avatar Jun 26 '20 13:06 joa-queen

Is there the possibility to make it work also with react-virtualized? here is a sandbox with a non working example: https://codesandbox.io/s/peaceful-swirles-c61w0?file=/src/App.js

ndanzi avatar Jan 26 '21 09:01 ndanzi

I managed to make it work with react-window. You can set an outerElementType and pass the scroll event to the corresponding element. This is how:

const Overflow = ({ children, onScroll }) => {
  const ofRef = useRef(null);

  useEffect(() => {
    const el = ofRef.current.osInstance().getElements().viewport;

    if (onScroll) el.addEventListener('scroll', onScroll);

    return () => {
      if (onScroll) el.removeEventListener('scroll', onScroll);
    };
  }, [onScroll]);

  return (
    <OverlayScrollbarsComponent
      options={options}
      ref={ofRef}
    >
      {children}
    </OverlayScrollbarsComponent>
  );
};

And then, in your virtualized component:

<FixedSizeGrid
  {...props}
   outerElementType={Overflow}
>

I'm using this with FixedSizeGrid but it should work the same for lists.

Hope it helps.

is this working?

partha-0103 avatar Mar 09 '22 09:03 partha-0103

@joa-queen please check this sandbox

partha-0103 avatar Mar 09 '22 09:03 partha-0103

@partha-0103 wrap the scrollbar children with a div with fixed height.

<OverlayScrollbarsComponent options={options} ref={ofRef}>
   <div style={{ maxHeight: "100px" }}>
      {children}
   </div>
</OverlayScrollbarsComponent>

nfmshow avatar Jun 03 '22 20:06 nfmshow

It took a bit of time, but with v2 OverlayScrollbars should work with all virtual scroll libraries. I've created a small example for FixedSizeList here: https://stackblitz.com/edit/react-8glpkm?file=index.js and also an example with horizontal layout: https://stackblitz.com/edit/react-wdbggw?file=index.js

You can use this approach also for VariableSizeList, FixedSizeGrid and FixedSizeGrid.

KingSora avatar Mar 08 '23 00:03 KingSora

@KingSora please add example for VariableSizeList.outerElementType with useOverlayScrollbars. It is working code without useOverlayScrollbars:

const outerElementType = React.forwardRef(({ children, onScroll, style }, ref) => {
  return <div {...{ ref, style, onScroll }}>{children}</div>
})

other example: https://codesandbox.io/s/bvaughnreact-window-fixed-size-list-vertical-wqmeo?file=/index.js:323-339

comerc avatar Apr 25 '23 10:04 comerc

It took a bit of time, but with v2 OverlayScrollbars should work with all virtual scroll libraries. I've created a small example for FixedSizeList here: https://stackblitz.com/edit/react-8glpkm?file=index.js and also an example with horizontal layout: https://stackblitz.com/edit/react-wdbggw?file=index.js

You can use this approach also for VariableSizeList, FixedSizeGrid and FixedSizeGrid.

Hello, thank you for the library, and sorry for the silly question but, how could I remove the flicker at the start? tried to add data-overlay scrollbars-initialize in https://stackblitz.com/edit/react-8glpkm?file=index.js but there are still a few frames where the initial scrollbar is visible

codingedgar avatar Dec 12 '23 19:12 codingedgar

It took a bit of time, but with v2 OverlayScrollbars should work with all virtual scroll libraries. I've created a small example for FixedSizeList here: https://stackblitz.com/edit/react-8glpkm?file=index.js and also an example with horizontal layout: https://stackblitz.com/edit/react-wdbggw?file=index.js

You can use this approach also for VariableSizeList, FixedSizeGrid and FixedSizeGrid.

@KingSora v2.4.7 is the last one that works correctly with this example. From v2.5.0 it breaks. Could you please update your example for the newest version?

Rychu-Pawel avatar Mar 11 '24 12:03 Rychu-Pawel

@Rychu-Pawel I'm looking into it!

KingSora avatar Mar 11 '24 22:03 KingSora

@Rychu-Pawel Alright, sorry for the trouble... The problem was that remaining IE11 compatibility code was overwriting the height style set by the react-window library. I've now properly removed the remaining code and published a new version v2.6.1 which should work again without problems: https://stackblitz.com/edit/react-2heqyv?file=index.js

KingSora avatar Mar 11 '24 23:03 KingSora

@KingSora, wow, that was blazing fast 💪 I can confirm the newest version is working as expected. Thank you so much for your quick fix! Best package maintenance ever 🎉

Rychu-Pawel avatar Mar 12 '24 08:03 Rychu-Pawel