Skip to content

Commit

Permalink
[added] TabbedArea allows disabled tabs
Browse files Browse the repository at this point in the history
Added disabled example to TabbedArea

Added disabled example to TabbedArea

Added disabled example to TabbedArea

Test for TabbedArea passing 'disabled'

Updated test

Add test and fix lint issues
  • Loading branch information
traviscooper committed May 13, 2015
1 parent 659976c commit d3f57c5
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/examples/TabbedAreaControlled.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const ControlledTabArea = React.createClass({
<TabbedArea activeKey={this.state.key} onSelect={this.handleSelect}>
<TabPane eventKey={1} tab='Tab 1'>TabPane 1 content</TabPane>
<TabPane eventKey={2} tab='Tab 2'>TabPane 2 content</TabPane>
<TabPane eventKey={3} tab='Tab 3' disabled={true}>TabPane 3 content</TabPane>
</TabbedArea>
);
}
Expand Down
1 change: 1 addition & 0 deletions docs/examples/TabbedAreaNoAnimation.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const tabbedAreaInstance = (
<TabbedArea defaultActiveKey={1} animation={false}>
<TabPane eventKey={1} tab='Tab 1'>TabPane 1 content</TabPane>
<TabPane eventKey={2} tab='Tab 2'>TabPane 2 content</TabPane>
<TabPane eventKey={3} tab='Tab 3' disabled={true}>TabPane 3 content</TabPane>
</TabbedArea>
);

Expand Down
1 change: 1 addition & 0 deletions docs/examples/TabbedAreaUncontrolled.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const tabbedAreaInstance = (
<TabbedArea defaultActiveKey={2}>
<TabPane eventKey={1} tab='Tab 1'>TabPane 1 content</TabPane>
<TabPane eventKey={2} tab='Tab 2'>TabPane 2 content</TabPane>
<TabPane eventKey={3} tab='Tab 3' disabled={true}>TabPane 3 content</TabPane>
</TabbedArea>
);

Expand Down
3 changes: 2 additions & 1 deletion src/TabPane.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const TabPane = React.createClass({
propTypes: {
active: React.PropTypes.bool,
animation: React.PropTypes.bool,
onAnimateOutEnd: React.PropTypes.func
onAnimateOutEnd: React.PropTypes.func,
disabled: React.PropTypes.bool
},

getDefaultProps() {
Expand Down
5 changes: 3 additions & 2 deletions src/TabbedArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,13 @@ const TabbedArea = React.createClass({
},

renderTab(child) {
let {eventKey, className, tab } = child.props;
let {eventKey, className, tab, disabled } = child.props;
return (
<NavItem
ref={'tab' + eventKey}
eventKey={eventKey}
className={className} >
className={className}
disabled={disabled}>
{tab}
</NavItem>
);
Expand Down
32 changes: 32 additions & 0 deletions test/TabbedAreaSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,5 +197,37 @@ describe('TabbedArea', function () {
assert.equal(tabPane[1].getDOMNode().getAttribute('class').match(/pull-right/)[0], 'pull-right');
});

it('Should pass disabled to NavItem', function () {
let instance = ReactTestUtils.renderIntoDocument(
<TabbedArea activeKey={1}>
<TabPane tab="Tab 1" eventKey={1}>Tab 1 content</TabPane>
<TabPane tab="Tab 2" eventKey={2} disabled={true}>Tab 2 content</TabPane>
</TabbedArea>
);

assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'disabled'));
});

it('Should not show content when clicking disabled tab', function () {
let tab1 = <span className="tab1">Tab 1</span>;
let instance = ReactTestUtils.renderIntoDocument(
<TabbedArea defaultActiveKey={2} animation={false}>
<TabPane tab={tab1} eventKey={1} disabled={true}>Tab 1 content</TabPane>
<TabPane tab="Tab 2" eventKey={2}>Tab 2 content</TabPane>
</TabbedArea>
);

let tabbedArea = ReactTestUtils.findRenderedComponentWithType(instance, TabbedArea);
let panes = ReactTestUtils.scryRenderedComponentsWithType(instance, TabPane);

ReactTestUtils.Simulate.click(
ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'tab1')
);

assert.equal(panes[0].props.active, false);
assert.equal(panes[1].props.active, true);
assert.equal(tabbedArea.refs.tabs.props.activeKey, 2);
});


});

0 comments on commit d3f57c5

Please sign in to comment.