Skip to content

Commit

Permalink
[fixed] Don't render Grid or Row with Tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
taion committed Sep 7, 2015
1 parent 360fceb commit 0c27403
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 35 deletions.
37 changes: 20 additions & 17 deletions src/Tabs.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import classNames from 'classnames';
import React, { cloneElement } from 'react';

import Col from './Col';
import Grid from './Grid';
import Nav from './Nav';
import NavItem from './NavItem';
import Row from './Row';
import styleMaps from './styleMaps';

import ValidComponentChildren from './utils/ValidComponentChildren';
Expand Down Expand Up @@ -61,14 +60,19 @@ const Tabs = React.createClass({
paneWidth: React.PropTypes.oneOfType([
React.PropTypes.number,
React.PropTypes.object
])
]),
/**
* Render without clearfix if horizontally positioned
*/
standalone: React.PropTypes.bool
},

getDefaultProps() {
return {
animation: true,
tabWidth: 2,
position: 'top'
position: 'top',
standalone: false
};
},

Expand Down Expand Up @@ -114,6 +118,7 @@ const Tabs = React.createClass({
bsStyle,
tabWidth,
paneWidth,
standalone,
children,
...props
} = this.props;
Expand Down Expand Up @@ -144,6 +149,11 @@ const Tabs = React.createClass({
const childPanes = ValidComponentChildren.map(children, this.renderPane);

if (isHorizontal) {
if (!standalone) {
containerProps.className =
classNames(containerProps.className, 'clearfix');
}

const {tabsColProps, panesColProps} =
this.getColProps({tabWidth, paneWidth});

Expand All @@ -158,28 +168,21 @@ const Tabs = React.createClass({
</Col>
);

let body;
if (position === 'left') {
body = (
<Row {...containerProps}>
return (
<div {...containerProps}>
{tabs}
{panes}
</Row>
</div>
);
} else {
body = (
<Row {...containerProps}>
return (
<div {...containerProps}>
{panes}
{tabs}
</Row>
</div>
);
}

return (
<Grid>
{body}
</Grid>
);
} else {
return (
<div {...containerProps}>
Expand Down
39 changes: 21 additions & 18 deletions test/TabsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import React from 'react';
import ReactTestUtils from 'react/lib/ReactTestUtils';

import Col from '../src/Col';
import Grid from '../src/Grid';
import Nav from '../src/Nav';
import NavItem from '../src/NavItem';
import Row from '../src/Row';
import Tab from '../src/Tab';
import Tabs from '../src/Tabs';

Expand Down Expand Up @@ -263,18 +261,10 @@ describe('Tabs', function () {
});

it('doesn\'t render grid elements', function () {
const grids = ReactTestUtils.scryRenderedComponentsWithType(
instance, Grid
);
const rows = ReactTestUtils.scryRenderedComponentsWithType(
instance, Row
);
const cols = ReactTestUtils.scryRenderedComponentsWithType(
instance, Col
);

expect(grids).to.be.empty;
expect(rows).to.be.empty;
expect(cols).to.be.empty;
});
});
Expand Down Expand Up @@ -308,20 +298,16 @@ describe('Tabs', function () {
});

it('renders grid elements', function () {
const grids = ReactTestUtils.scryRenderedComponentsWithType(
instance, Grid
);
const rows = ReactTestUtils.scryRenderedComponentsWithType(
instance, Row
);
const cols = ReactTestUtils.scryRenderedComponentsWithType(
instance, Col
);

expect(grids).to.have.length(1);
expect(rows).to.have.length(1);
expect(cols).to.have.length(2);
});

it('should render with clearfix', function() {
expect(React.findDOMNode(instance).className).to.match(/\bclearfix\b/);
});
});

describe('when only tabWidth is provided', function() {
Expand Down Expand Up @@ -385,6 +371,23 @@ describe('Tabs', function () {
.to.match(/\bcol-xs-7\b/).and.to.match(/\bcol-md-8\b/);
});
});

describe('when standalone', function() {
let instance;

beforeEach(function () {
instance = ReactTestUtils.renderIntoDocument(
<Tabs defaultActiveKey={1} position="left" standalone>
<Tab title="A Tab" eventKey={1}>Tab content</Tab>
</Tabs>
);
});

it('should not render with clearfix', function() {
expect(React.findDOMNode(instance).className)
.to.not.match(/\bclearfix\b/);
});
});
});

describe('animation', function () {
Expand Down

0 comments on commit 0c27403

Please sign in to comment.