Skip to content

Commit 0683df7

Browse files
committed
[fixed] 'stacked' progress with 'active' and 'striped' children
Now it correctly renders 'active' and 'striped' children bars.
1 parent c27e1d4 commit 0683df7

File tree

3 files changed

+36
-13
lines changed

3 files changed

+36
-13
lines changed

docs/examples/ProgressBarStacked.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const progressInstance = (
22
<ProgressBar>
3-
<ProgressBar bsStyle='success' now={35} key={1} />
3+
<ProgressBar striped bsStyle='success' now={35} key={1} />
44
<ProgressBar bsStyle='warning' now={20} key={2} />
5-
<ProgressBar bsStyle='danger' now={10} key={3} />
5+
<ProgressBar active bsStyle='danger' now={10} key={3} />
66
</ProgressBar>
77
);
88

src/ProgressBar.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,6 @@ const ProgressBar = React.createClass({
4343
return this.renderProgressBar();
4444
}
4545

46-
const classes = {
47-
active: this.props.active,
48-
progress: true,
49-
'progress-striped': this.props.active || this.props.striped
50-
};
51-
5246
let content;
5347

5448
if (this.props.children) {
@@ -58,7 +52,7 @@ const ProgressBar = React.createClass({
5852
}
5953

6054
return (
61-
<div {...this.props} className={classNames(this.props.className, classes)}>
55+
<div {...this.props} className={classNames(this.props.className, 'progress')}>
6256
{content}
6357
</div>
6458
);
@@ -94,10 +88,15 @@ const ProgressBar = React.createClass({
9488
);
9589
}
9690

91+
const classes = classNames(this.props.className, this.getBsClassSet(), {
92+
active: this.props.active,
93+
'progress-bar-striped': this.props.active || this.props.striped
94+
});
95+
9796
return (
9897
<div
9998
{...this.props}
100-
className={classNames(this.props.className, this.getBsClassSet())}
99+
className={classes}
101100
role="progressbar"
102101
style={{width: percentage + '%'}}
103102
aria-valuenow={this.props.now}

test/ProgressBarSpec.js

+27-3
Original file line numberDiff line numberDiff line change
@@ -152,16 +152,18 @@ describe('ProgressBar', function () {
152152
<ProgressBar min={1} max={11} now={6} striped />
153153
);
154154

155-
assert.ok(React.findDOMNode(instance).className.match(/\bprogress-striped\b/));
155+
assert.ok(React.findDOMNode(instance).firstChild.className.match(/\bprogress-bar-striped\b/));
156156
});
157157

158158
it('Should show animated striped bar', function () {
159159
let instance = ReactTestUtils.renderIntoDocument(
160160
<ProgressBar min={1} max={11} now={6} active />
161161
);
162162

163-
assert.ok(React.findDOMNode(instance).className.match(/\bprogress-striped\b/));
164-
assert.ok(React.findDOMNode(instance).className.match(/\bactive\b/));
163+
const barClassName = React.findDOMNode(instance).firstChild.className;
164+
165+
assert.ok(barClassName.match(/\bprogress-bar-striped\b/));
166+
assert.ok(barClassName.match(/\bactive\b/));
165167
});
166168

167169
it('Should show stacked bars', function () {
@@ -182,6 +184,28 @@ describe('ProgressBar', function () {
182184
assert.equal(bar2.style.width, '30%');
183185
});
184186

187+
it('Should render active and striped children in stacked bar too', function () {
188+
let instance = ReactTestUtils.renderIntoDocument(
189+
<ProgressBar>
190+
<ProgressBar active key={1} now={50} />
191+
<ProgressBar striped key={2} now={30} />
192+
</ProgressBar>
193+
);
194+
let wrapper = React.findDOMNode(instance);
195+
let bar1 = wrapper.firstChild;
196+
let bar2 = wrapper.lastChild;
197+
198+
assert.ok(wrapper.className.match(/\bprogress\b/));
199+
200+
assert.ok(bar1.className.match(/\bprogress-bar\b/));
201+
assert.ok(bar1.className.match(/\bactive\b/));
202+
assert.ok(bar1.className.match(/\bprogress-bar-striped\b/));
203+
204+
assert.ok(bar2.className.match(/\bprogress-bar\b/));
205+
assert.ok(bar2.className.match(/\bprogress-bar-striped\b/));
206+
assert.notOk(bar2.className.match(/\bactive\b/));
207+
});
208+
185209
it('allows only ProgressBar in children', function () {
186210
ReactTestUtils.renderIntoDocument(
187211
<ProgressBar>

0 commit comments

Comments
 (0)