From 82c4488890e4e6a167aeece47c9800fa493ed359 Mon Sep 17 00:00:00 2001 From: AlexKVal Date: Sat, 18 Jul 2015 19:02:28 +0300 Subject: [PATCH 1/2] Add tests checking correct active state handling after removing tab pane --- test/TabbedAreaSpec.js | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/test/TabbedAreaSpec.js b/test/TabbedAreaSpec.js index 5d8cf7c065..876b09dcb8 100644 --- a/test/TabbedAreaSpec.js +++ b/test/TabbedAreaSpec.js @@ -4,6 +4,7 @@ import TabbedArea from '../src/TabbedArea'; import NavItem from '../src/NavItem'; import TabPane from '../src/TabPane'; import ValidComponentChildren from '../src/utils/ValidComponentChildren'; +import { render } from './helpers'; describe('TabbedArea', function () { it('Should show the correct tab', function () { @@ -230,6 +231,48 @@ describe('TabbedArea', function () { assert.equal(tabbedArea.refs.tabs.props.activeKey, 2); }); + describe('animation', function () { + let mountPoint; + + beforeEach(()=>{ + mountPoint = document.createElement('div'); + document.body.appendChild(mountPoint); + }); + + afterEach(function () { + React.unmountComponentAtNode(mountPoint); + document.body.removeChild(mountPoint); + }); + + function checkTabRemovingWithAnimation(animation) { + it(`should correctly set "active" after tabPane is removed with "animation=${animation}"`, function() { + let instance = render( + + Tab 1 content + Tab 2 content + + , mountPoint); + + let panes = ReactTestUtils.scryRenderedComponentsWithType(instance, TabPane); + + assert.equal(panes[0].props.active, false); + assert.equal(panes[1].props.active, true); + + // second tab has been removed + render( + + Tab 1 content + + , mountPoint); + + assert.equal(panes[0].props.active, true); + }); + } + + checkTabRemovingWithAnimation(true); + checkTabRemovingWithAnimation(false); + }); + describe('Web Accessibility', function(){ it('Should generate ids from parent id', function () { From 2558f32b92166c6b0dddda38c4d344fcf4356e74 Mon Sep 17 00:00:00 2001 From: AlexKVal Date: Fri, 24 Jul 2015 23:08:16 +0300 Subject: [PATCH 2/2] [fixed] TabbedArea panes rendering with animation --- src/TabbedArea.js | 49 +++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/src/TabbedArea.js b/src/TabbedArea.js index 9a1c1ae3b9..89021be333 100644 --- a/src/TabbedArea.js +++ b/src/TabbedArea.js @@ -51,8 +51,22 @@ const TabbedArea = React.createClass({ componentWillReceiveProps(nextProps) { if (nextProps.activeKey != null && nextProps.activeKey !== this.props.activeKey) { + // check if the 'previousActiveKey' child still exists + let previousActiveKey = this.props.activeKey; + React.Children.forEach(nextProps.children, (child) => { + if (React.isValidElement(child)) { + if (child.props.eventKey === previousActiveKey) { + this.setState({ + previousActiveKey + }); + return; + } + } + }); + + // if the 'previousActiveKey' child does not exist anymore this.setState({ - previousActiveKey: this.props.activeKey + previousActiveKey: null }); } }, @@ -66,15 +80,12 @@ const TabbedArea = React.createClass({ render() { let { id, ...props } = this.props; - let activeKey = - this.props.activeKey != null ? this.props.activeKey : this.state.activeKey; - function renderTabIfSet(child) { return child.props.tab != null ? this.renderTab(child) : null; } let nav = ( -