Skip to content

Commit 2d13f89

Browse files
committed
Just ignore href on active BreadcrumbItem
Makes it easier to use with react-router-bootstrap
1 parent fd8fc48 commit 2d13f89

3 files changed

Lines changed: 13 additions & 21 deletions

File tree

src/Breadcrumb.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const Breadcrumb = React.createClass({
3232
},
3333

3434
renderBreadcrumbItem(child, index) {
35-
return cloneElement( child, { key: child.key ? child.key : index } );
35+
return cloneElement(child, { key: child.key || index });
3636
}
3737
});
3838

src/BreadcrumbItem.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import classNames from 'classnames';
22
import React from 'react';
3-
import warning from 'warning';
43

54
import SafeAnchor from './SafeAnchor';
65

@@ -56,8 +55,6 @@ const BreadcrumbItem = React.createClass({
5655
target,
5756
...props } = this.props;
5857

59-
warning(!(href && active), '[react-bootstrap] `href` and `active` properties cannot be set at the same time');
60-
6158
const linkProps = {
6259
href,
6360
title,

test/BreadcrumbItemSpec.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,7 @@ import ReactDOM from 'react-dom';
44

55
import BreadcrumbItem from '../src/BreadcrumbItem';
66

7-
import { shouldWarn } from './helpers';
8-
97
describe('BreadcrumbItem', () => {
10-
it('Should warn if `active` and `href` attributes set', () => {
11-
ReactTestUtils.renderIntoDocument(
12-
<BreadcrumbItem href='#' active>
13-
Crumb
14-
</BreadcrumbItem>
15-
);
16-
17-
shouldWarn('[react-bootstrap] `href` and `active` properties cannot be set at the same time');
18-
});
19-
208
it('Should render `a` as inner element when is not active', () => {
219
const instance = ReactTestUtils.renderIntoDocument(
2210
<BreadcrumbItem href='#'>
@@ -28,24 +16,31 @@ describe('BreadcrumbItem', () => {
2816
assert.notInclude(ReactDOM.findDOMNode(instance).className, 'active');
2917
});
3018

31-
it('Should add `active` class with `active` attribute set.', () => {
19+
it('Should render `span.active` with `active` attribute set.', () => {
3220
const instance = ReactTestUtils.renderIntoDocument(
3321
<BreadcrumbItem active>
3422
Active Crumb
3523
</BreadcrumbItem>
3624
);
3725

3826
assert.include(ReactDOM.findDOMNode(instance).className, 'active');
27+
assert.ok(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'span'));
3928
});
4029

41-
it('Should render `span` as inner element when is active', () => {
30+
it('Should render `span.active` when active and has href', () => {
4231
const instance = ReactTestUtils.renderIntoDocument(
43-
<BreadcrumbItem active>
44-
Crumb
32+
<BreadcrumbItem href="#" active>
33+
Active Crumb
4534
</BreadcrumbItem>
4635
);
4736

48-
assert.ok(ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'span'));
37+
assert.include(ReactDOM.findDOMNode(instance).className, 'active');
38+
39+
const spanNode = ReactTestUtils.findRenderedDOMComponentWithTag(instance, 'span');
40+
assert.ok(spanNode);
41+
assert.notOk(spanNode.hasAttribute('href'));
42+
43+
assert.lengthOf(ReactTestUtils.scryRenderedDOMComponentsWithTag(instance, 'a'), 0);
4944
});
5045

5146
it('Should add custom classes onto `li` wrapper element', () => {

0 commit comments

Comments
 (0)