Skip to content

Commit

Permalink
[fixed] 'stacked' progress with 'active' and 'striped' children
Browse files Browse the repository at this point in the history
Now it correctly renders 'active' and 'striped' children bars.
  • Loading branch information
AlexKVal committed Jul 11, 2015
1 parent c27e1d4 commit 0683df7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
4 changes: 2 additions & 2 deletions docs/examples/ProgressBarStacked.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const progressInstance = (
<ProgressBar>
<ProgressBar bsStyle='success' now={35} key={1} />
<ProgressBar striped bsStyle='success' now={35} key={1} />
<ProgressBar bsStyle='warning' now={20} key={2} />
<ProgressBar bsStyle='danger' now={10} key={3} />
<ProgressBar active bsStyle='danger' now={10} key={3} />
</ProgressBar>
);

Expand Down
15 changes: 7 additions & 8 deletions src/ProgressBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ const ProgressBar = React.createClass({
return this.renderProgressBar();
}

const classes = {
active: this.props.active,
progress: true,
'progress-striped': this.props.active || this.props.striped
};

let content;

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

return (
<div {...this.props} className={classNames(this.props.className, classes)}>
<div {...this.props} className={classNames(this.props.className, 'progress')}>
{content}
</div>
);
Expand Down Expand Up @@ -94,10 +88,15 @@ const ProgressBar = React.createClass({
);
}

const classes = classNames(this.props.className, this.getBsClassSet(), {
active: this.props.active,
'progress-bar-striped': this.props.active || this.props.striped
});

return (
<div
{...this.props}
className={classNames(this.props.className, this.getBsClassSet())}
className={classes}
role="progressbar"
style={{width: percentage + '%'}}
aria-valuenow={this.props.now}
Expand Down
30 changes: 27 additions & 3 deletions test/ProgressBarSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,18 @@ describe('ProgressBar', function () {
<ProgressBar min={1} max={11} now={6} striped />
);

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

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

assert.ok(React.findDOMNode(instance).className.match(/\bprogress-striped\b/));
assert.ok(React.findDOMNode(instance).className.match(/\bactive\b/));
const barClassName = React.findDOMNode(instance).firstChild.className;

assert.ok(barClassName.match(/\bprogress-bar-striped\b/));
assert.ok(barClassName.match(/\bactive\b/));
});

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

it('Should render active and striped children in stacked bar too', function () {
let instance = ReactTestUtils.renderIntoDocument(
<ProgressBar>
<ProgressBar active key={1} now={50} />
<ProgressBar striped key={2} now={30} />
</ProgressBar>
);
let wrapper = React.findDOMNode(instance);
let bar1 = wrapper.firstChild;
let bar2 = wrapper.lastChild;

assert.ok(wrapper.className.match(/\bprogress\b/));

assert.ok(bar1.className.match(/\bprogress-bar\b/));
assert.ok(bar1.className.match(/\bactive\b/));
assert.ok(bar1.className.match(/\bprogress-bar-striped\b/));

assert.ok(bar2.className.match(/\bprogress-bar\b/));
assert.ok(bar2.className.match(/\bprogress-bar-striped\b/));
assert.notOk(bar2.className.match(/\bactive\b/));
});

it('allows only ProgressBar in children', function () {
ReactTestUtils.renderIntoDocument(
<ProgressBar>
Expand Down

0 comments on commit 0683df7

Please sign in to comment.