Skip to content

Commit 0793e12

Browse files
Merge pull request react-bootstrap#298 from glenjamin/number-badge
Fix <Badge> rendering when passed a Number
2 parents 19e4825 + 696c522 commit 0793e12

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

src/Badge.jsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@ var Badge = React.createClass({
88
pullRight: React.PropTypes.bool
99
},
1010

11+
hasContent: function () {
12+
return ValidComponentChildren.hasValidComponent(this.props.children) ||
13+
(typeof this.props.children === 'string') ||
14+
(typeof this.props.children === 'number')
15+
},
16+
1117
render: function () {
1218
var classes = {
1319
'pull-right': this.props.pullRight,
14-
'badge': (ValidComponentChildren.hasValidComponent(this.props.children)
15-
|| (typeof this.props.children === 'string'))
20+
'badge': this.hasContent()
1621
};
1722
return (
1823
<span

test/BadgeSpec.jsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ describe('Badge', function () {
2323
assert.ok(instance.getDOMNode().className.match(/\bbadge\b/));
2424
});
2525

26+
it('Should have a badge using a number', function () {
27+
var count = 42;
28+
var instance = ReactTestUtils.renderIntoDocument(
29+
<Badge>
30+
{count}
31+
</Badge>
32+
);
33+
assert.ok(instance.getDOMNode().className.match(/\bbadge\b/));
34+
});
35+
2636
it('Should have a badge class pulled right', function () {
2737
var instance = ReactTestUtils.renderIntoDocument(
2838
<Badge pullRight>

0 commit comments

Comments
 (0)