0

I'm trying to have a component conditionally render in React and slide it when it does render

packages:

"react": "^16.8.6",
"react-transition-group": "^4.0.1",

code snippet:

{ expanded && (
    <CSSTransition in={expanded} timeout={500} classNames="slide">
        <div className="expandedDiv"></div>
    </CSSTransition>
)}

css:

.slide-enter {
    transform: translateX(-100%);
    transition: .3s linear;
}
.slide-enter-active {
    transform: translateX(0%);
}
.slide-exit {
    transform: translateX(0%);
    transition: .3s linear;
}
.slide-exit-active {
    transform: translateX(-100%);
}

structure:

+------------------------------+
|      |          |  header    |
|      |          |____________+
|      |          |  content   |
|      |          |            |
|      |          |            |
| nav  | expanded |            |
|      |          |            |
|      |          |            |
|      |          |            |
+------------------------------+

Expanded should slide in on true, and slide out on false, it is expandedDiv from the code snippet

The div just pops in with no animation. Expected behaviour is a linear transition from left to right

Thanks

Arthur
  • 2,622
  • 4
  • 28
  • 46

2 Answers2

0

I need to see a little bit more of your code to understand exactly what you're trying to do. But if I got it right, try doing it like this:

<CSSTransition
  in={expanded}
  appear={true}
  key = {this.props.location.key}
  timeout={500}
  classNames="slide">
            <div className='expandedDiv'> </div>
</CSSTransition>
0
               <CSSTransition
                    in={expanded}
                    timeout={300}
                    classNames="slide"
                    unmountOnExit
                    onEnter={() => this.toggleExpanded(true)}
                    onExited={() => this.toggleExpanded(false)}
                >
                    <div className="expandedDiv">
                    </div>
                </CSSTransition>
            </div>
Arthur
  • 2,622
  • 4
  • 28
  • 46