Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React CSSTransitionGroup is not working (doesn't add classes)

I am currently working on notification component in React. It is working except the transitions.. Somehow its not even adding class. I looked up some React animation examples and i do some research but i couldnt find anything useful. Especially article for React15. I didnt understand, this should work perfectly but its just showing and hiding text without any transitions.

import React, { Component } from 'react';
import CSSTransitionGroup from 'react-transition-group/CSSTransitionGroup';
import '../stylesheets/notification.less';

export default class Notifications extends Component {
    render() {
        return (
           <CSSTransitionGroup transitionName="notifications" transitionEnterTimeout={300} transitionLeaveTimeout={300}>
                    <div className={this.props.type === 'error' ? 'notification-inner warning' : 'notification-inner success'}>
                      {this.props.type} {this.props.message}
                    </div>
            </CSSTransitionGroup>
        );
    }
}

And CSS File...

.notifications {
    background:#000;
}
.notifications-enter {
    opacity: 0;
    transform:   translate(-250px,0);
    transform: translate3d(-250px,0,0);
}
.notifications-enter.notifications-enter-active {
    opacity: 1;
    transition: opacity 1s ease;
    transform:   translate(0,0);
    transform: translate3d(0,0,0);
    transition-property: transform, opacity;
    transition-duration: 300ms;
    transition-timing-function: cubic-bezier(0.175, 0.665, 0.320, 1), linear;
}
.notifications-leave {
    opacity: 1;
    transform:   translate(0,0,0);
    transform: translate3d(0,0,0);
  transition-property: transform, opacity;
    transition-duration: 300ms;
    transition-timing-function: cubic-bezier(0.175, 0.665, 0.320, 1), linear;
}
.notifications-leave.notifications-leave-active {
    opacity: 0;
    transform:   translate(250px,0);
    transform: translate3d(250px,0,0);
}
like image 586
jrSakizci Avatar asked Apr 19 '17 12:04

jrSakizci


1 Answers

Make sure you have the key attribute set.

From the doc: https://facebook.github.io/react/docs/animation.html

Note: You must provide the key attribute for all children of ReactCSSTransitionGroup, even when only rendering a single item. This is how React will determine which children have entered, left, or stayed.

like image 199
Nozomi Avatar answered Nov 19 '22 21:11

Nozomi