Skip to content

Commit bd15b4a

Browse files
charleshansenelenasharma
authored andcommitted
feat(Tabs): Tabs accept actions prop
- Improves consistency with css Tabs component [#106770388] Signed-off-by: Elena Sharma <esharma@pivotal.io>
1 parent 500c321 commit bd15b4a

File tree

3 files changed

+42
-19
lines changed

3 files changed

+42
-19
lines changed

library/spec/pivotal-ui-react/tabs/tabs_spec.js

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('Tabs', function() {
1414

1515
const triggerResize = function() {
1616
const evt = document.createEvent('HTMLEvents');
17-
evt.initEvent('resize', true, true );
17+
evt.initEvent('resize', true, true);
1818
window.dispatchEvent(evt);
1919
};
2020

@@ -111,36 +111,46 @@ describe('Tabs', function() {
111111
});
112112
});
113113

114-
xdescribe('actions', () => {
114+
describe('actions', () => {
115115
beforeEach(() => {
116+
const actions = (
117+
<div>
118+
<button>=)</button>
119+
<button>=|</button>
120+
<button>=(</button>
121+
</div>
122+
);
116123
ReactDOM.render(
117-
<Tabs>
118-
tabType={tabType}
119-
actions={
120-
<div>
121-
<button>=)</button>
122-
<button>=|</button>
123-
<button>=(</button>
124-
</div>}
124+
<Tabs tabType={tabType} actions={actions}>
125+
<Tab eventKey={1} title="Tab1">Content1</Tab>
126+
<Tab eventKey={2} title="Tab2">Content2</Tab>
125127
</Tabs>,
126128
root
127129
);
128130
});
129131

130-
it('renders the actions', () => {
131-
expect($('.nav-tabs .actions')).toContain('=)');
132-
expect($('.nav-tabs .actions')).toContain('=|');
133-
expect($('.nav-tabs .actions')).toContain('=(');
132+
it('renders the actions for large screens', () => {
133+
expect('.tab-simple .tabs-action').toContainText('=)');
134+
expect('.tab-simple .tabs-action').toContainText('=|');
135+
expect('.tab-simple .tabs-action').toContainText('=(');
136+
});
137+
138+
it('renders the actions for small screens', () => {
139+
MediaSize.matches.and.returnValue(false);
140+
triggerResize();
141+
expect('.tab-simple-small-screen .tabs-action').toContainText('=)');
142+
expect('.tab-simple-small-screen .tabs-action').toContainText('=|');
143+
expect('.tab-simple-small-screen .tabs-action').toContainText('=(');
134144
});
135145
});
136146

137147
describe('passthroughs', function() {
138148
beforeEach(function() {
139149
ReactDOM.render(
140150
<Tabs defaultActiveKey={2}
141-
tabType={tabType}
142-
className="test-class"
143-
style={{opacity: 0.5}}/>,
151+
tabType={tabType}
152+
className="test-class"
153+
style={{opacity: 0.5}}/>,
144154
root
145155
);
146156

library/src/pivotal-ui-react/tabs/tabs.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class SmallTab extends React.Component {
4141

4242
class SmallTabs extends React.Component {
4343
static propTypes = {
44+
actions: types.node,
4445
activeKey: types.number,
4546
id: types.string,
4647
handleClick: types.func,
@@ -53,6 +54,7 @@ class SmallTabs extends React.Component {
5354

5455
render() {
5556
const {
57+
actions,
5658
activeKey,
5759
children,
5860
className,
@@ -82,8 +84,13 @@ class SmallTabs extends React.Component {
8284
return <SmallTab {...myProps}>{isActive && children}</SmallTab>;
8385
});
8486

87+
const actionsNode = actions ? <div className="tabs-action">{actions}</div> : null;
88+
8589
return (
86-
<div className={smallScreenClasses}>{childrenAsPanels}</div>
90+
<div className={smallScreenClasses}>
91+
{actionsNode}
92+
{childrenAsPanels}
93+
</div>
8794
);
8895
}
8996
}
@@ -104,6 +111,7 @@ class Tabs extends mixin(React.Component).with(Animation) {
104111
}
105112

106113
static propTypes = {
114+
actions: types.node,
107115
activeKey: types.number,
108116
defaultActiveKey: types.any,
109117
id: types.string,
@@ -166,6 +174,7 @@ class Tabs extends mixin(React.Component).with(Animation) {
166174

167175
render() {
168176
const {
177+
actions,
169178
children,
170179
className,
171180
defaultActiveKey,
@@ -226,8 +235,11 @@ class Tabs extends mixin(React.Component).with(Animation) {
226235
);
227236
});
228237

238+
const actionsNode = actions ? <div className="tabs-action">{actions}</div> : null;
239+
229240
return (
230241
<div className={classnames(largeScreenClasses, {'tab-left clearfix': isLeft})} {...props}>
242+
{actionsNode}
231243
<ul role='tablist'
232244
className={classnames('nav', {'nav-tabs': !isLeft}, {[leftTabClasses]: isLeft})}>
233245
{listChildren}

styleguide/docs/react/tabs.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Property | Required? | Type | Description
3535
`largeScreenClassName` | no | css class | Will be applied to large screen tabs only
3636
`onSelect` | no | function | Will override default behavior when clicking on a tab. If you want to retain the default behavior as well as add new functionality, change default active key in the function you provide
3737
`tabType` | no | one of: `"simple"`, `"simple-alt"` | Change the styling of your tabs, mostly whether the selected tab is transparent
38+
`actions` | no | node | an element or text that will display in the upper right
3839
3940
*/
4041

@@ -46,7 +47,7 @@ parent: tabs_react
4647
---
4748
4849
```react_example
49-
<Tabs defaultActiveKey={1}>
50+
<Tabs defaultActiveKey={1} actions={<a>Action!</a>}>
5051
<Tab eventKey={1} title="Tab 1">Wow!</Tab>
5152
<Tab eventKey={2} title="Tab 2">
5253
<h2>Neat!</h2>

0 commit comments

Comments
 (0)