{
{ height: this.getHeight() }
}
onTransitionEnd={ this.handleTransitionEnd }
- ref={ (slideDown) => {
- this.slideDown = slideDown;
- } }
+ ref={ this.slideDown }
data-test-id={ this.props['data-test-id'] }
>
{
- this.slideDownContent = slideDownContent;
- } }
+ ref={ this.slideDownContent }
>
{ this.props.children }
@@ -105,7 +109,7 @@ export class SlideDown extends React.PureComponent {
);
}
- private handleTransitionEnd = (event) => {
+ private handleTransitionEnd = (event: React.TransitionEvent) => {
if (event.propertyName === 'height' && this.props.isExpanded) {
this.setAutoHeight();
}
@@ -121,10 +125,12 @@ export class SlideDown extends React.PureComponent {
}
private setHeightToContentHeight() {
- this.setState({
- isHeightAuto: false,
- height: this.slideDownContent.offsetHeight
- });
+ if (this.slideDownContent.current) {
+ this.setState({
+ isHeightAuto: false,
+ height: this.slideDownContent.current.offsetHeight
+ });
+ }
}
private setHeightToNull() {
@@ -133,10 +139,11 @@ export class SlideDown extends React.PureComponent {
// Заставляем React перерисовать элемент
this.forceUpdate(() => {
// Заставляем браузер сделать reflow
- this.slideDown.getBoundingClientRect();
- this.setState({
- height: 0
- });
+ if (this.slideDown.current) {
+ this.slideDown.current.getBoundingClientRect();
+ }
+
+ this.setState({ height: 0 });
});
}