Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initialSelectedIndex property to Tabs #389

Merged
merged 4 commits into from
Mar 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/src/app/components/pages/components/tabs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
10 changes: 8 additions & 2 deletions src/js/tabs/tabs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ var InkBar = require('../ink-bar');
var Tabs = React.createClass({

propTypes: {
onActive: React.PropTypes.func
initialSelectedIndex: React.PropTypes.number,
onActive: React.PropTypes.func,
tabWidth: React.PropTypes.number
},

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
};
},

Expand Down