Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Ability to add custom scrollbar for VList #296

Closed
adventofryz opened this issue Dec 26, 2023 · 1 comment
Closed

Ability to add custom scrollbar for VList #296

adventofryz opened this issue Dec 26, 2023 · 1 comment

Comments

@adventofryz
Copy link

I am trying to use React simplebar with virtua but am not sure how to use this.

https://github.com/Grsmto/simplebar/tree/master/packages/simplebar-react

Typically we do something like this for third party virtualization libraries like react window:

<SimpleBar> {({ scrollableNodeRef, contentNodeRef }) => { return <div> Access to scrollable and content nodes </div>; }} </SimpleBar>

How do I use this with virtua?

I looked into the components for VList and thought of using component Root to pass the scrollbar through it but it doesn't work.

https://github.com/inokawa/virtua/blob/main/docs/interfaces/react.VListProps.md#components

@inokawa
Copy link
Owner

inokawa commented Dec 26, 2023

This looks working:

import SimpleBar from "simplebar-react";
import "simplebar-react/dist/simplebar.min.css";

const Root = forwardRef<HTMLDivElement, CustomViewportComponentProps>(
  ({ children, attrs, width, height, scrolling }, ref): ReactElement => {
    return (
      <SimpleBar scrollableNodeProps={{ref}} {...attrs}>
        <div
          style={useMemo((): CSSProperties => {
            return {
              position: "relative",
              visibility: "hidden",
              width: width ?? "100%",
              height: height ?? "100%",
              pointerEvents: scrolling ? "none" : "auto",
            };
          }, [width, height, scrolling])}
        >
          {children}
        </div>
      </SimpleBar>
    );
  }
);

const Comp = () => {
  return (
    <VList style={{ height: "100vh" }} components={{ Root }}>
      {createRows(1000)}
    </VList>
  );
}

Repository owner locked and limited conversation to collaborators Dec 26, 2023
@inokawa inokawa converted this issue into discussion #297 Dec 26, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants