I'm using react-transition-group
for animations in my app.
I have a Popup where I want to animate between two contents. I want to make the first content fade out and the second content appear in its place.
So far I have a problem where while animating the second content appears below the first one while the first one is still visible. (See the screenshot)
Any help will be much appreciated.
My code
const [stage, setStage] = useState('register');
function changeStage(stageVal) {
setStage(stageVal);
}
...
<Popup togglePopupWindow={togglePopupWindow} setStage={setStage}>
<CSSTransitionGroup
transitionName="example"
transitionEnterTimeout={500}
transitionLeaveTimeout={300}
>
{stage === 'register' && (
<>
<Form>
<h2>Register</h2>
<Input type="text" placeholder="Login" />
<Input type="email" placeholder="Email" />
<Input type="password" placeholder="Password" />
<Button text="Register" />
</Form>
<p>
<span>Already registered?</span>
<Button className="popup__login" text="Login" onClick={() => changeStage('login')} />
</p>
</>
)
}
{stage === 'login' && (
<Form>
<h2>Login</h2>
<Input type="text" placeholder="Login" />
<Input type="password" placeholder="Password" />
<Button text="Register" />
</Form>
)
}
</CSSTransitionGroup>
</Popup>
Styles
.example-enter {
opacity: 0;
}
.example-enter.example-enter-active {
opacity: 1;
transition: opacity 500ms ease-in-out;
}
.example-leave {
opacity: 1;
}
.example-leave.example-leave-active {
opacity: 0;
transition: opacity 300ms ease-in-out;
}