From 9c0ce15fe67a58bb00f1ac80b9ed41857df03c19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=B0=E6=96=87?= Date: Mon, 13 Jul 2015 23:01:43 +0800 Subject: [PATCH 1/2] feat: fix bug when componentDidMount context fix height --- assets/index.less | 9 ++++---- examples/simple.js | 9 ++++++++ package.json | 2 +- src/Panel.jsx | 52 ++++++++++++++++++++-------------------------- 4 files changed, 37 insertions(+), 35 deletions(-) diff --git a/assets/index.less b/assets/index.less index 73bfed8..7946275 100644 --- a/assets/index.less +++ b/assets/index.less @@ -7,11 +7,10 @@ transition-duration: .3s; transition-timing-function: ease-in; overflow: hidden; - } - - &-content-active { - opacity: 1; - height: auto; + > p, > div { + margin-top: 16px; + margin-bottom: 16px; + } } } diff --git a/examples/simple.js b/examples/simple.js index 6fdb6cf..a54c03f 100644 --- a/examples/simple.js +++ b/examples/simple.js @@ -34,6 +34,15 @@ var Test = React.createClass({ ); } + items.push( + + + +

{text}

+
+
+
+ ); return items; }, diff --git a/package.json b/package.json index 57c04da..7d36d7c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rc-collapse", - "version": "1.2.0", + "version": "1.2.1", "description": "rc-collapse ui component for react", "keywords": [ "react", diff --git a/src/Panel.jsx b/src/Panel.jsx index 9a2a869..8a438ed 100644 --- a/src/Panel.jsx +++ b/src/Panel.jsx @@ -58,7 +58,8 @@ module.exports = createClass({ componentDidMount() { if (this.props.isActive) { var el = findDOMNode(this.refs.content); - el.style.height = el.scrollHeight + 'px'; + el.style.height = 'auto'; + el.style.opacity = 1; } }, @@ -71,33 +72,26 @@ module.exports = createClass({ return; } - // current isActive - if (!isActive) { - var preNode = findDOMNode(this.refs.content); - preNode.style.height = preNode.scrollHeight + 'px'; - preNode.style.opacity = 1; - cssAnimation.setTransition(preNode, 'Property', 'height ,opacity'); - cssAnimation.style(preNode, { - height: 0, - opacity: 0 - }, function() { - preNode.style.height = ''; - preNode.style.opacity = ''; - cssAnimation.setTransition(preNode, 'Property', ''); - }); - } else { - // from isActive to hide - var currentNode = findDOMNode(this.refs.content); - currentNode.style.height = 0; - cssAnimation.setTransition(currentNode, 'Property', 'height ,opacity'); - cssAnimation.style(currentNode, { - height: currentNode.scrollHeight + 'px', - opacity: 1 - }, function() { - currentNode.style.height = 'auto'; - currentNode.style.opacity = 1; - cssAnimation.setTransition(currentNode, 'Property', ''); - }); - } + this._anim(isActive ? 0 : 1); + }, + + _anim(opacity) { + var el = findDOMNode(this.refs.content); + var scrollHeight = el.scrollHeight + 'px'; + + // start state + el.style.height = opacity ? scrollHeight : 0; + el.style.opacity = opacity; + + cssAnimation.setTransition(el, 'Property', 'height ,opacity'); + cssAnimation.style(el, { + height: opacity ? 0 : scrollHeight, + opacity: opacity ? 0 : 1 + }, function() { + el.style.height = opacity ? 0 : 'auto'; + el.style.opacity = opacity ? 0 : 1; + cssAnimation.setTransition(el, 'Property', ''); + }); } + }); From 2961b582b53190b60b2c636d1c9e4f8e50e68251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=B0=E6=96=87?= Date: Mon, 13 Jul 2015 23:03:59 +0800 Subject: [PATCH 2/2] chore: change demo --- examples/simple.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/simple.js b/examples/simple.js index a54c03f..f650db1 100644 --- a/examples/simple.js +++ b/examples/simple.js @@ -67,7 +67,7 @@ var Test = React.createClass({



- {this.getItems()} + {this.getItems()} ; } });