react-infinite-tree icon indicating copy to clipboard operation
react-infinite-tree copied to clipboard

InfiniteTree nodes/height not calculated correctly with flexbox

Open frankvdb7 opened this issue 7 years ago • 4 comments

When I try to use flexbox with the InfiniteTree component like this:

render() {
    return (
        <div style={{ display: "flex", flexDirection:"column" }}>
          <InfiniteTree
              width="100%"
              height="100%"
              style={{ flex: "1 1 auto" }}
              rowHeight={30}
              data={someData}
           />
        </div>
    )
}

The div and InfiniteTree container correctly expand to height 100% in the inspector, but the InfiniteTree component only shows 5 nodes instead of filling in rows until the 100% height. So lets say we have room for 10 nodes of 30 pixels (100% height = 300px), it only show 4 nodes of 30 pixels (120px), so there is 180px of empty space.

Is there a way to solve this?

Thanks

frankvdb7 avatar Nov 25 '17 19:11 frankvdb7

Hi, i faced the same issue today. Looks like react-tiny-virtual-list does not really support passing percentages to it.

screen shot 2018-01-15 at 11 15 50

According to this screenshot it treats it as a regular item and trying to add offset to it :) Not sure what could be a solution to this though.

aalbul avatar Jan 15 '18 10:01 aalbul

As an alternative way, you may use the ref attribute and the ReactDOM.findDOMNode() function to get the offsetHeight of its container element, and then call this.setState({ height: containerElement.offsetHeight }) to trigger the second render.

cheton avatar Jan 16 '18 02:01 cheton

True. However:

  1. it will cause double rendering. I suppose it will be more visible if you have a big tree, but still
  2. react-infinite-tree states that it's possible to use string or number. Does it make sense to change documentation? :)

aalbul avatar Jan 19 '18 12:01 aalbul

I found a statement from react-tiny-virtual-list's documentation:

* Width may only be a string when scrollDirection is 'vertical'. Similarly, Height may only be a string if scrollDirection is 'horizontal'

Since react-infinite-tree's scroll direction is vertical, the "width" prop can either be a number or string like "100%" or "auto", but the "height" prop must be a number in this case.

I will update documentation accordingly. Also, I see some issues (https://github.com/clauderic/react-tiny-virtual-list/issues/25, https://github.com/clauderic/react-tiny-virtual-list/issues/37) and PRs there (https://github.com/clauderic/react-tiny-virtual-list/pull/30, ), hope it can be merged soon.

cheton avatar Jan 20 '18 03:01 cheton