-
-
- {contents}
-
+
+ {panels}
+
+ );
+ }
+});
+
+var Tabs = React.createClass({
+ getInitialState: function () {
+ return {
+ activeIndex: 0
+ };
+ },
+ componentWillMount: function () {
+ if (this.props.activeTab) {
+ this.setState({ activeIndex: this.props.activeTab });
+ }
+ },
+ updateTabs: function (event) {
+ var tabIndex = parseInt(event.target.getAttribute('data-index'));
+ this.setState({ activeIndex: tabIndex });
+ },
+ render: function () {
+ var tabLinks = _.pluck(_.pluck(this.props.children, 'props'), 'heading');
+
+ return (
+
+
+ {this.props.children}
);
}
@@ -54,11 +75,15 @@ var SimpleAltTabs = React.createClass({
var Tab = React.createClass({
render: function () {
- return "";
+ return (
+
+ {this.props.children}
+
+ );
}
});
module.exports = {
- SimpleAltTabs: SimpleAltTabs,
+ Tabs: Tabs,
Tab: Tab
};
diff --git a/test/spec/javascripts/tabs_spec.js b/test/spec/javascripts/tabs_spec.js
index 80ce2bf07..cf6b94db8 100644
--- a/test/spec/javascripts/tabs_spec.js
+++ b/test/spec/javascripts/tabs_spec.js
@@ -4,10 +4,10 @@ var $ = require('jquery');
var React = require('react/addons');
var TestUtils = React.addons.TestUtils;
-var SimpleAltTabs = require('../../../src/pivotal-ui/javascripts/tabs.jsx').SimpleAltTabs;
+var Tabs = require('../../../src/pivotal-ui/javascripts/tabs.jsx').Tabs;
var Tab = require('../../../src/pivotal-ui/javascripts/tabs.jsx').Tab;
-describe('SimpleAltTabs', function() {
+describe("Tabs", function() {
beforeEach(function() {
this.node = $('
').appendTo('body').get(0);
});
@@ -17,42 +17,65 @@ describe('SimpleAltTabs', function() {
document.body.removeChild(this.node);
});
- describe("when the active flag is not set", function() {
+ describe("when the active tab is not set", function() {
beforeEach(function() {
React.render(
-
+
Content for first tab
Content for second tab
- ,
+ ,
this.node
);
});
- it("renders the correct tabs and content", function() {
- expect($('#container .tab-simple-alt ul.nav.nav-tabs li.active a')).toHaveText("My first tab");
- expect($('#container .tab-simple-alt ul.nav.nav-tabs li:not(.active) a')).toHaveText("My second tab");
+ it("renders the tabs and content with first tab active", function() {
+ expect($('#container .tab-simple ul.nav.nav-tabs li.active a')).toHaveText("My first tab");
+ expect($('#container .tab-simple ul.nav.nav-tabs li:not(.active) a')).toHaveText("My second tab");
- expect($('#container li.active a').attr('href')).toEqual('#' + $('#container .tab-pane.active').attr("id"));
+ expect($('#container .tab-simple .tab-content .tab-pane.in.active')).toHaveText("Content for first tab");
+ expect($('#container .tab-simple .tab-content .tab-pane:not(.in.active)')).toHaveText("Content for second tab");
+ });
+ });
+
+ describe("when the active tab is set", function() {
+ beforeEach(function() {
+ React.render(
+
+ Content for first tab
+ Content for second tab
+ ,
+ this.node
+ );
+ });
+
+ it("renders the tabs and content with specified tab active", function() {
+ expect($('#container .tab-simple ul.nav.nav-tabs li.active a')).toHaveText("My second tab");
+ expect($('#container .tab-simple ul.nav.nav-tabs li:not(.active) a')).toHaveText("My first tab");
- expect($('#container .tab-simple-alt .tab-content .tab-pane.in.active')).toHaveText("Content for first tab");
- expect($('#container .tab-simple-alt .tab-content .tab-pane:not(.in.active)')).toHaveText("Content for second tab");
+ expect($('#container .tab-simple .tab-content .tab-pane.in.active')).toHaveText("Content for second tab");
+ expect($('#container .tab-simple .tab-content .tab-pane:not(.in.active)')).toHaveText("Content for first tab");
});
});
- describe("when the active flag is set on a tab", function() {
+ describe("clicking a non-active tab", function() {
beforeEach(function() {
React.render(
-
+
Content for first tab
- Content for second tab
- ,
+
Content for second tab
+ ,
this.node
);
+
+ TestUtils.Simulate.click($('li:not(.active) a').get(0));
});
- it("sets the specified tab as active", function() {
- expect($('#container .tab-simple-alt ul.nav.nav-tabs li.active a')).toHaveText("My second tab");
- expect($('#container .tab-simple-alt .tab-content .tab-pane.in.active')).toHaveText("Content for second tab");
+ it("updates the active tab and content", function() {
+ expect($('#container .tab-simple ul.nav.nav-tabs li.active a')).toHaveText("My second tab");
+ expect($('#container .tab-simple ul.nav.nav-tabs li:not(.active) a')).toHaveText("My first tab");
+
+ expect($('#container .tab-simple .tab-content .tab-pane.in.active')).toHaveText("Content for second tab");
+ expect($('#container .tab-simple .tab-content .tab-pane:not(.in.active)')).toHaveText("Content for first tab");
});
});
});