-
Notifications
You must be signed in to change notification settings - Fork 141
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
Dynamic height / scrollbars #86
Comments
I managed to solve this by calculating height based on number of nodes in the tree and adjusting the height of the Tree component accordingly. |
I usually make the height of the tree the same height as it's parent using a ResizeObserver on the parent, the passing the width/height to the tree. If you make the tree height the same height as all the nodes, you will loose the row virtualization that makes it render fast. For example, if you have 10,000 nodes and the tree height is set to 10,000 x rowHeight, you'll be rendering all 10,000 of them in the tree. Whereas if the height is only 500, you'll only be rendering 20-30. I would welcome an example where the scrollbar is custom styled though. |
Hi @jameskerr Could you please post some code example of how you achieve this? I've been wrestling with this for around 8 hours now, and see some strange results when I try to do this. I've written a few React hooks, tried native JavaScript, but I seem to be getting inconsistent results (using Here is a video is what happens when I calculate the height of the Treeviews container in my project (using ResizeObserver) ... treeview.movYou can see that more than 1 calculation is performed. The number next to The React hook I'm using is here:
And the use of this is super simple ...
If you could provide some help with this (via the provision of code for how you use ResizeObserver), that would be appreciated. (I'm using v3.0.2) Many thanks FYI, I've just stripped everything right back, to just your "The simplest tree" example from https://github.com/brimdata/react-arborist and with everything inline in a single page, and it's still the same effect. It's nothing to do with re-rendering, I checked that. It's a real odd one. Alas, if the treeview doesn't work Re: resizing, I think I'll have to revert to something like rc-tree. I do like using react-arborist though, so I'm hoping you can help. |
Debugging stuff like this is hard. Dang. I’ll give this a more thorough read and post and example, but I’ve had to make the parent component have styles like min-height: 0 and flex: 1 |
hey @jameskerr can you provide an example, better in documentation. |
I would also love some better documentation on this. |
It would be really nice to have the possibility to send a maxHeight and then for the table to be of height auto otherwise |
Is it posible to use the height of the parent. I am not setting any height but my issue is that there is a lot of space at the bottom of the tree. Example my parent height is 252 however the tree is 500. Yes I could set the heigh manually but my parent window is drainable and resizable. parent: PanelWindow.tsx
ScenePanel.tsx
The ScenePanel size is showing 500 while the parent is only 252. Screen.Recording.2023-07-27.at.10.34.46.AM.mov |
Yes, I usually make the parent expand to fill it's parent (either with flex: 1 or the css below). height: 100%;
min-height: 0; Then I add a ref to it with this package https://github.com/ZeeCoder/use-resize-observer That hook will return the height and width of the parent whenever it changes. You then pass these numbers to the Tree. const { ref, width, height } = useResizeObserver();
<div className="parent" ref={ref}>
<Tree height={height} width={width} />
</div> |
Also having some trouble getting this to work the way I want. Is it possible to disable scrolling for the tree and have another component take over that role? For example we have a ScrollArea implementation from Radix UI that we could use. Or would this screw with the virtualization? I have tried getting the same behavior as the Cities example, where horizontal scrolling is disabled and text has ellipsis overflow instead by using the FillFlexPanel, but I cannot get the horizontal scrollbar to be hidden with |
Ok so in that case, you'll need to set overflow hidden on your Node renderer. Handle the ellipses in the Node Renderer as well. The tree component should fill its container, and the tree wrapper should have overflow scroll, but then the nodes should be width: 100% with overflow: hidden. I've never used custom scrollbars in my app, so if you get it working and want to throw up an example, I could publish that in an FAQ somewhere. |
It looks like it could be possible to use custom scrollbars if the In the example they are using |
Cool! Thanks for researching that. |
I used your example as a solution to the problem, but the height of the tree is still 500px (I think this is the default)
|
You'll need to make sure that the parent is filling its container. It needs to have flex: 1; on it or grid-template-row 1fr or something to make it fill the container. |
Yes, I tried using flex, but it also doesn't give any result. I tried to reproduce this code in codesandbox to make sure on whose side the problem is. Maybe I don't understand correctly how flex works |
For those using Tailwind, I was able to apply custom styles to the scrollbar with this nifty Tailwind plugin: https://github.com/adoxography/tailwind-scrollbar Add the Tailwind classes to the Tree component. For example:
|
I had issues using useResizeObserver where it would resize the height down the way, but if you resized back up it wouldn't fire the resize events. Managed to fix it by setting height = {height -1 } in the tree component. the - 1 was just enough to stop the tree from locking the height! |
Has anyone managed to make the height of a Tree dynamic? Will there be any updates on this issue? |
I did get dynamic height working but it wasn't easy. The principal is that you want:
Essentially we want our tree height to be equal to One limitation that is difficult to get around is that we cannot access the calculated tree height easily without changing react-arborist's code. However we can get to it by polling for it within the Tree component - unfortunately there is no other good way to figure out WHEN this becomes available on the DOM. This would be a lot easier with code that let's you subscribe to changes on the total calculated tree height! I will extrapolate from my working version to show the principals at work: First set up the DOM & some refs.
Then let's introduce the polling code.
Finally, whenever the treeContentsHeight is updated, we can set the containerHeight, and make sure it's updated on resize as well.
|
@danielgormly, you are simply a genius! Thank you, your method helped me implement the dynamic height of the tree container. |
The scrollbar is a bit ugly. Is it possible to have the Tree adjust its height dynamically instead of having it fixed and let the parent container handle the scrollbars? Or alternatively be able to style the scrollbars so that it e.g. they are only visible on mouse hover?
The text was updated successfully, but these errors were encountered: