React-sortable-tree: Auto height without losing style

Created on 4 Oct 2018  路  3Comments  路  Source: frontend-collective/react-sortable-tree

Hi,

I want to make SortableTree height fit its content, without the need to explicity set the height and without the scroll, making it auto. The problem is, the only way according to the documentation to accomplish this is by setting the isVirtualized prop, but by doing so I lost all the nice styling that happens when dragging a node. So, how can i make it full height without losing the styling?

Most helpful comment

import SortableTree, { getVisibleNodeCount } from "react-sortable-tree"
...
const count = getVisibleNodeCount({treeData:this.props.treeData})
style={{height: count * 62}} // height of each node

All 3 comments

I've used generateNodeProps to dynamically set styles. It may be worth exploring. You could potentially use code to determine the amount of content you have and extrapolate the height size accordingly. Example:

            generateNodeProps={({ node, path, treeIndex }) => ({
                title: node.title != 'someValue' ? (
                    <div 
                        style={{ fontSize: '.6rem' }}
                    ...
            ) : (
                    <div
                        style={{ fontSize: '.9rem' }}
                    ...

import SortableTree, { getVisibleNodeCount } from "react-sortable-tree"
...
const count = getVisibleNodeCount({treeData:this.props.treeData})
style={{height: count * 62}} // height of each node

@Imagine-F yeah that :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

LogicMonsters picture LogicMonsters  路  5Comments

kaueDM picture kaueDM  路  3Comments

vladimirsvsv77 picture vladimirsvsv77  路  5Comments

NickEmpetvee picture NickEmpetvee  路  3Comments

anushkadoyan picture anushkadoyan  路  4Comments