glennflanagan / react-collapsible

React component to wrap content in Collapsible element with trigger to open and close.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pass height state into the onOpen, onOpening and other methods

emad-ms opened this issue · comments

Feature request

Since react-collapsible is calculating the scrollHeight of its children it can pass it through methods like onOpen, or onOpening to let the parent component be aware of that too.
This can be really helpful when height and positioning in parent component matters and developer needs to know the content height without using DOM selectors.

For example for onOpen:

this.setState(({ height: prevHeight }) => {
     this.props.onOpen({ height: prevHeight }); // or even just pass it using innerRef.scrollHeight
     return ({
        height: 'auto',
        overflow: this.props.overflowWhenOpen,
        inTransition: false,
     })
});