CSSTransition 持续时间不起作用

CSSTransition duration doesn't work

我正在尝试使用 CSSTransition 实现向下滑动动画,但似乎 transitionduration 不起作用。

codepen

component.jsx

let { CSSTransition, TransitionGroup } = ReactTransitionGroup

class Example extends React.Component {

    state = {
    show: false,
  };

    render() {
        return (
          <div>
            <button onClick={() => this.setState({
          show: true })}>Show</button>
          {this.state.show && (
            <CSSTransition in={this.state.show} timeout={2000} classNames="birthday-input" appear>
              <div className="form-group birthday-input">
                <h1>HEADER</h1>
              </div>
            </CSSTransition> 
          )}
            </div>
        );
    }
}

ReactDOM.render(
  <Example />,
  document.getElementById('root')
);

component.scss

.birthday-input-enter {
  max-height: 0;
}
.birthday-input-enter-active {
  -webkit-transition: max-height 1s ease;
  max-height: 1000px;
}
.birthday-input-exit {
  max-height: 1000px;
}
.birthday-input-exit-active {
  max-height: 0;
  -webkit-transition: max-height 1s ease;
}

来自库文档: 当 in 属性切换为 true 时,组件将添加 example-enter CSS class 和 example-enter-active CSS class在下一个滴答声中。这是基于 classNames prop.

的约定

首先,在您的情况下,in 永远不会计算为真,因为 showBirthInputundefined

其次,它必须对 JS 评估做一些事情,因为如果我取出 JS 评估,而不是让 CSSTransitionshow 上渲染,它会完美地工作。

这是基于您的代码的工作示例: https://stackblitz.com/edit/react-pshw1h?file=index.js