From 6bad1e861cb58ea9ed15817962cf0d601cf917e3 Mon Sep 17 00:00:00 2001 From: Jimmy Jia Date: Sun, 18 Oct 2015 13:22:39 -0400 Subject: [PATCH] [fixed] Explicitly disallow justified Navbar Navs Per upstream TWBS docs, they're not supported --- src/Nav.js | 20 ++++++++++++++++---- test/NavSpec.js | 9 +++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/Nav.js b/src/Nav.js index 63f614836b..776883abfc 100644 --- a/src/Nav.js +++ b/src/Nav.js @@ -1,11 +1,13 @@ -import React, { cloneElement } from 'react'; -import BootstrapMixin from './BootstrapMixin'; -import Collapse from './Collapse'; import classNames from 'classnames'; +import React, { cloneElement } from 'react'; +import all from 'react-prop-types/lib/all'; import ValidComponentChildren from './utils/ValidComponentChildren'; import createChainedFunction from './utils/createChainedFunction'; +import BootstrapMixin from './BootstrapMixin'; +import Collapse from './Collapse'; + const Nav = React.createClass({ mixins: [BootstrapMixin], @@ -14,7 +16,17 @@ const Nav = React.createClass({ activeKey: React.PropTypes.any, bsStyle: React.PropTypes.oneOf(['tabs', 'pills']), stacked: React.PropTypes.bool, - justified: React.PropTypes.bool, + /** + * Make `NavItem`s equal widths on small or larger displays and stacked + * otherwise. Not supported for `Nav`s in `Navbar`s. + */ + justified: all( + React.PropTypes.bool, + ({justified, navbar}) => ( + justified && navbar ? + Error('justified navbar `Nav`s are not supported') : null + ) + ), onSelect: React.PropTypes.func, collapsible: React.PropTypes.bool, /** diff --git a/test/NavSpec.js b/test/NavSpec.js index 60ca06d782..0bae89cd48 100644 --- a/test/NavSpec.js +++ b/test/NavSpec.js @@ -5,6 +5,8 @@ import Button from '../src/Button'; import Nav from '../src/Nav'; import NavItem from '../src/NavItem'; +import {shouldWarn} from './helpers'; + describe('Nav', () => { it('Should set the correct item active', () => { let instance = ReactTestUtils.renderIntoDocument( @@ -178,6 +180,13 @@ describe('Nav', () => { assert.equal(navNode.id, 'nav-id'); }); + it('Should warn when attempting to use a justified navbar nav', () => { + ReactTestUtils.renderIntoDocument( +