From 4aad7475877cd3ec425f8b14b009915fda7e8fe8 Mon Sep 17 00:00:00 2001 From: Jonathan Di Nardo Date: Thu, 26 Mar 2015 16:37:41 -0400 Subject: [PATCH] Added the ability to provide a selected index to tabs as a property. This allows you to change the active tab in a render function. This opens the door to easily changing the active tab programatically, and allows you to initialize tabs to an active tab index other than 0 --- src/js/tabs/tabs.jsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/js/tabs/tabs.jsx b/src/js/tabs/tabs.jsx index 2484d6a1470d35..2f7c1798df38fb 100644 --- a/src/js/tabs/tabs.jsx +++ b/src/js/tabs/tabs.jsx @@ -29,6 +29,12 @@ var Tabs = React.createClass({ ); }, + componentWillReceiveProps: function(newProps) { + this.setState({ + selectedIndex: newProps.selectedIndex + }); + }, + componentDidMount: function(){ if(this.props.tabWidth) { if(!(this.props.children.length * this.props.tabWidth > this.getEvenWidth())){ @@ -40,6 +46,7 @@ var Tabs = React.createClass({ } } this.setState({ + selectedIndex: this.props.selectedIndex, width: this.getEvenWidth(), fixed: true });