react-split-pane icon indicating copy to clipboard operation
react-split-pane copied to clipboard

Initial size based on content?

Open dkozar opened this issue 3 years ago • 2 comments

Hi,

I'd like to use the split pane in horizontal mode (first panel above, second one below).

When the split pane is mounted, I'd like to determine the top/bottom section sizes based on their contents (so there are no individual scrollbars apart from the page scrollbar).

Is this possible to do?

Thanks!

dkozar avatar Nov 25 '21 12:11 dkozar

It's possible.

  • React.useRef to get a ref which you associate with your element you want to measure.
  • React.useEffect to run some code after your component renders for the first time
  • In the useEffect, read the properties of the HTML element e.g. its clientHeight
  • Use that height, now that you know it, to set/reset the size of the pane
  • And maybe [once, setOnce = React.useState(false) which you use to ensure that you do the above only once/initially

cwellsx avatar Feb 09 '24 07:02 cwellsx