I am using react-transition-group
to help with managing transitions between elements. I am trying to implement a quiz where the questions slide over the other question after a user answers one question. However my transition makes it so that the the divs are stacked vertically. I would like it to slide over kinda like a card. I have this codesandbox of what i've done.
relevant code:
transition group
renderQuestion = () => {
const question = this.questionsToAnswer[this.state.currentQuestionIndex];
return (
<div
style={{
display: "flex",
flexDirection: "row"
}}
>
<TransitionGroup className="slide-group">
<CSSTransition
classNames="slide"
timeout={{ enter: 500, exit: 500 }}
key={`${this.state.currentQuestionIndex}`}
>
<div>
<div
style={{
fontFamily: "Oswald",
fontStyle: "normal",
fontWeight: 500,
fontSize: "28px",
letterSpacing: "0.05em",
color: "#003E4C",
marginBottom: "10px",
width: "700px"
}}
>
{question["description"]}
</div>
<div>{this.renderRadioQuestion(question["answers"])}</div>
</div>
</CSSTransition>
</TransitionGroup>
</div>
);
};
styles.css
/* ANIMATIONS */
.slide-enter {
transform: translateX(100%);
}
.slide-enter-active {
transform: translateX(0%);
transition: transform 500ms ease-in-out;
}
.slide-exit {
transform: translateX(0%);
}
.slide-exit-active {
transform: translateX(-100%);
transition: transform 500ms ease-in-out;
}
/* not sure how to style this so that i can transition divs nicely*/
.slide-group {
/* display: flex;
flex-wrap: nowrap; */
}