Skip to content

Commit d3f57c5

Browse files
committedMay 13, 2015
[added] TabbedArea allows disabled tabs
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
1 parent 659976c commit d3f57c5

File tree

6 files changed

+40
-3
lines changed

6 files changed

+40
-3
lines changed
 

‎docs/examples/TabbedAreaControlled.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const ControlledTabArea = React.createClass({
1515
<TabbedArea activeKey={this.state.key} onSelect={this.handleSelect}>
1616
<TabPane eventKey={1} tab='Tab 1'>TabPane 1 content</TabPane>
1717
<TabPane eventKey={2} tab='Tab 2'>TabPane 2 content</TabPane>
18+
<TabPane eventKey={3} tab='Tab 3' disabled={true}>TabPane 3 content</TabPane>
1819
</TabbedArea>
1920
);
2021
}

‎docs/examples/TabbedAreaNoAnimation.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const tabbedAreaInstance = (
22
<TabbedArea defaultActiveKey={1} animation={false}>
33
<TabPane eventKey={1} tab='Tab 1'>TabPane 1 content</TabPane>
44
<TabPane eventKey={2} tab='Tab 2'>TabPane 2 content</TabPane>
5+
<TabPane eventKey={3} tab='Tab 3' disabled={true}>TabPane 3 content</TabPane>
56
</TabbedArea>
67
);
78

‎docs/examples/TabbedAreaUncontrolled.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const tabbedAreaInstance = (
22
<TabbedArea defaultActiveKey={2}>
33
<TabPane eventKey={1} tab='Tab 1'>TabPane 1 content</TabPane>
44
<TabPane eventKey={2} tab='Tab 2'>TabPane 2 content</TabPane>
5+
<TabPane eventKey={3} tab='Tab 3' disabled={true}>TabPane 3 content</TabPane>
56
</TabbedArea>
67
);
78

‎src/TabPane.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ const TabPane = React.createClass({
66
propTypes: {
77
active: React.PropTypes.bool,
88
animation: React.PropTypes.bool,
9-
onAnimateOutEnd: React.PropTypes.func
9+
onAnimateOutEnd: React.PropTypes.func,
10+
disabled: React.PropTypes.bool
1011
},
1112

1213
getDefaultProps() {

‎src/TabbedArea.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,13 @@ const TabbedArea = React.createClass({
105105
},
106106

107107
renderTab(child) {
108-
let {eventKey, className, tab } = child.props;
108+
let {eventKey, className, tab, disabled } = child.props;
109109
return (
110110
<NavItem
111111
ref={'tab' + eventKey}
112112
eventKey={eventKey}
113-
className={className} >
113+
className={className}
114+
disabled={disabled}>
114115
{tab}
115116
</NavItem>
116117
);

‎test/TabbedAreaSpec.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,5 +197,37 @@ describe('TabbedArea', function () {
197197
assert.equal(tabPane[1].getDOMNode().getAttribute('class').match(/pull-right/)[0], 'pull-right');
198198
});
199199

200+
it('Should pass disabled to NavItem', function () {
201+
let instance = ReactTestUtils.renderIntoDocument(
202+
<TabbedArea activeKey={1}>
203+
<TabPane tab="Tab 1" eventKey={1}>Tab 1 content</TabPane>
204+
<TabPane tab="Tab 2" eventKey={2} disabled={true}>Tab 2 content</TabPane>
205+
</TabbedArea>
206+
);
207+
208+
assert.ok(ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'disabled'));
209+
});
210+
211+
it('Should not show content when clicking disabled tab', function () {
212+
let tab1 = <span className="tab1">Tab 1</span>;
213+
let instance = ReactTestUtils.renderIntoDocument(
214+
<TabbedArea defaultActiveKey={2} animation={false}>
215+
<TabPane tab={tab1} eventKey={1} disabled={true}>Tab 1 content</TabPane>
216+
<TabPane tab="Tab 2" eventKey={2}>Tab 2 content</TabPane>
217+
</TabbedArea>
218+
);
219+
220+
let tabbedArea = ReactTestUtils.findRenderedComponentWithType(instance, TabbedArea);
221+
let panes = ReactTestUtils.scryRenderedComponentsWithType(instance, TabPane);
222+
223+
ReactTestUtils.Simulate.click(
224+
ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'tab1')
225+
);
226+
227+
assert.equal(panes[0].props.active, false);
228+
assert.equal(panes[1].props.active, true);
229+
assert.equal(tabbedArea.refs.tabs.props.activeKey, 2);
230+
});
231+
200232

201233
});

0 commit comments

Comments
 (0)