petyosi / react-virtuoso

The most powerful virtual list component for React
https://virtuoso.dev
MIT License
5.13k stars 299 forks source link

Suggestion - add onScrollbarPresenceChange event/callback #1051

Closed rzinnatullin closed 5 months ago

rzinnatullin commented 5 months ago

Not a question, or a bug, just improvement suggestion.

When styling rows adding bottom border, we usually need to know whether the row is the last row or not. It's needed because we already have the table's bottom border, and we don't want to show the last row's bottom border - 2 borders would be shown. Well, this is easy to handle with :last-child CSS selector.

However, when we have a table with a fixed height, and there are very few rows, we should show the last row's bottom border, because there's a free space between the last row and the bottom border of the table. Yeah, this is still achievable, but it requires some non-trivial solution.

It would be great if virtuoso supported this scenario somehow, for example, by adding onScrollbarPresenceChange event/callback allowing then simply adding a class like scrollbar-vertical once the scrollbar appears. Then in CSS we can hide the last row's bottom border when the scrollbar is in place, otherwise the border should show.

petyosi commented 5 months ago

Managing the border correctly is a legit enhancement - I believe that this is totally doable with the current context API, though. There are also several callback exposed that might do the job.