From c3c5296ca65574ca933a4a8f3a2304d70d6ecb82 Mon Sep 17 00:00:00 2001 From: Wilbert van de Ridder Date: Thu, 5 Mar 2015 09:54:00 +0100 Subject: [PATCH 1/4] Add initialSelectedIndex property to Tabs Fixes https://github.com/callemall/material-ui/issues/375. Also checks whether the index is not out of bounds w.r.t. the amount of tab children. --- src/js/tabs/tabs.jsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/js/tabs/tabs.jsx b/src/js/tabs/tabs.jsx index 92417549dd4bcc..b5448d26554b3a 100644 --- a/src/js/tabs/tabs.jsx +++ b/src/js/tabs/tabs.jsx @@ -10,8 +10,12 @@ var Tabs = React.createClass({ }, getInitialState: function(){ + var selectedIndex = 0; + if (this.props.initialSelectedIndex && this.props.initialSelectedIndex < this.props.children.length) { + selectedIndex = this.props.initialSelectedIndex; + } return { - selectedIndex: 0 + selectedIndex: selectedIndex }; }, From f45084b6e2cc62e9496cc02e2b5408e0c6fbba8f Mon Sep 17 00:00:00 2001 From: Wilbert van de Ridder Date: Wed, 11 Mar 2015 18:02:41 +0100 Subject: [PATCH 2/4] Update tabs.jsx --- src/js/tabs/tabs.jsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/js/tabs/tabs.jsx b/src/js/tabs/tabs.jsx index b5448d26554b3a..0bcc196ac2a51d 100644 --- a/src/js/tabs/tabs.jsx +++ b/src/js/tabs/tabs.jsx @@ -6,7 +6,8 @@ var InkBar = require('../ink-bar'); var Tabs = React.createClass({ propTypes: { - onActive: React.PropTypes.func + onActive: React.PropTypes.func, + initialSelectedIndex: React.PropTypes.number }, getInitialState: function(){ From f8d190bf769f444e03040bfd0a822cd022f74337 Mon Sep 17 00:00:00 2001 From: Wilbert van de Ridder Date: Wed, 11 Mar 2015 18:05:47 +0100 Subject: [PATCH 3/4] Update tabs.jsx --- src/js/tabs/tabs.jsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/js/tabs/tabs.jsx b/src/js/tabs/tabs.jsx index 0bcc196ac2a51d..2484d6a1470d35 100644 --- a/src/js/tabs/tabs.jsx +++ b/src/js/tabs/tabs.jsx @@ -6,8 +6,9 @@ var InkBar = require('../ink-bar'); var Tabs = React.createClass({ propTypes: { + initialSelectedIndex: React.PropTypes.number, onActive: React.PropTypes.func, - initialSelectedIndex: React.PropTypes.number + tabWidth: React.PropTypes.number }, getInitialState: function(){ From cd98b70bef075bf0d3e23ba5de3bddc647fdcf99 Mon Sep 17 00:00:00 2001 From: Wilbert van de Ridder Date: Wed, 11 Mar 2015 18:11:19 +0100 Subject: [PATCH 4/4] Update tabs.jsx --- docs/src/app/components/pages/components/tabs.jsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/src/app/components/pages/components/tabs.jsx b/docs/src/app/components/pages/components/tabs.jsx index 882cf795b4ecc8..3eff6e4cefabc3 100644 --- a/docs/src/app/components/pages/components/tabs.jsx +++ b/docs/src/app/components/pages/components/tabs.jsx @@ -57,6 +57,12 @@ var TabsPage = React.createClass({ { name: 'Tabs Props', infoArray: [ + { + name: 'initialSelectedIndex', + type: 'number', + header: 'optional', + desc: 'Specify initial visible tab index. Initial selected index is set by default to 0. If initialSelectedIndex is set but larger than the total amount of specified tabs, initialSelectedIndex will revert back to default' + }, { name: 'tabWidth', type: 'number',