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 = ( -