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

How to add private scrollbar in list? #154

Closed
NickJiangDev opened this issue Aug 8, 2023 · 4 comments
Closed

How to add private scrollbar in list? #154

NickJiangDev opened this issue Aug 8, 2023 · 4 comments

Comments

@NickJiangDev
Copy link

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

@inokawa
Copy link
Owner

inokawa commented Aug 8, 2023

Hi, what does private scrollbar mean?

@NickJiangDev
Copy link
Author

Hi, what does private scrollbar mean?

Hi, when I use VList, I would like to style the scrollbar. However, instead of overriding it with CSS styles, I would like to provide a React component or class to wrap the scroll area. I found that I can only access it through "ref". Is there a way to achieve a similar effect as shown in the image below?
image

@inokawa
Copy link
Owner

inokawa commented Aug 9, 2023

If you want to customize component, you can use components.Root prop to override default root component.

The default root component is here. Copy paste it and customize by yourself.

export const Viewport = forwardRef<any, CustomViewportComponentProps>(
({ children, attrs, width, height, scrolling }, ref): ReactElement => {
return (
<div ref={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>
</div>
);
}
);

And here is an example overriding root component with ul.

<VList
style={{
flex: 1,
background: "#fff",
}}
components={{ Root: UlList, Item: Li }}
overscan={20}
>

https://inokawa.github.io/virtua/?path=/story/basics-vlist--ul

@NickJiangDev
Copy link
Author

If you want to customize component, you can use components.Root prop to override default root component.

The default root component is here. Copy paste it and customize by yourself.

export const Viewport = forwardRef<any, CustomViewportComponentProps>(
({ children, attrs, width, height, scrolling }, ref): ReactElement => {
return (
<div ref={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>
</div>
);
}
);

And here is an example overriding root component with ul.

<VList
style={{
flex: 1,
background: "#fff",
}}
components={{ Root: UlList, Item: Li }}
overscan={20}
>

https://inokawa.github.io/virtua/?path=/story/basics-vlist--ul

Thanks a lot, it works on me.

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