Skip to content

Commit

Permalink
Merge pull request #384 from johnhaley81/pass-selected-tab-onchange
Browse files Browse the repository at this point in the history
Pass selected tab to `onChange` event
  • Loading branch information
Hai Nguyen committed Mar 3, 2015
2 parents ffb4baf + b1204cf commit f1a55c1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 3 additions & 3 deletions docs/src/app/components/pages/components/tabs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var Tabs = mui.Tabs;
var Tab= mui.Tab;

var TabsPage = React.createClass({

mixins: [Router.Navigation, Router.State],

render: function(){
Expand Down Expand Up @@ -51,7 +51,7 @@ var TabsPage = React.createClass({
'If you need to access a tab directly - you can do so with the first argument of onActive or ' +
'by accessing the props.children array by passing refs to the Tabs container.';



var componentInfo = [
{
Expand All @@ -70,7 +70,7 @@ var TabsPage = React.createClass({
infoArray: [
{
name: 'onChange',
type: 'function',
type: 'function(tabIndex, tab)',
header: 'optional',
desc: 'Fired on touch or tap of a tab.'
}
Expand Down
9 changes: 6 additions & 3 deletions src/js/tabs/tabs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,17 @@ var Tabs = React.createClass({
},

handleTouchTap: function(tabIndex, tab){
if (this.props.onChange && this.state.selectedIndex !== tabIndex) this.props.onChange();
if (this.props.onChange && this.state.selectedIndex !== tabIndex) {
this.props.onChange(tabIndex, tab);
}

this.setState({selectedIndex: tabIndex});
//default CB is _onActive. Can be updated in tab.jsx
if(tab.props.onActive) tab.props.onActive(tab);
},

render: function(){
var _this = this;
var _this = this;
var width = this.state.fixed ?
this.state.width/this.props.children.length :
this.props.tabWidth;
Expand Down Expand Up @@ -84,4 +87,4 @@ var Tabs = React.createClass({

});

module.exports = Tabs;
module.exports = Tabs;

0 comments on commit f1a55c1

Please sign in to comment.