Skip to content

Commit

Permalink
fix(progressbar): fix stacked progress bars breaking width
Browse files Browse the repository at this point in the history
  • Loading branch information
SteffanLong committed Jul 28, 2015
1 parent a028d2a commit f86a06a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/progressbar/progressbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ angular.module('ui.bootstrap.progressbar', [])

bar.recalculatePercentage = function() {
bar.percent = +(100 * bar.value / bar.max).toFixed(2);

var totalPercentage = 0;
self.bars.forEach(function (bar) {
totalPercentage += bar.percent;
});

if (totalPercentage > 100) {
bar.percent -= totalPercentage - 100;
}
};

bar.$on('$destroy', function() {
Expand Down
15 changes: 15 additions & 0 deletions src/progressbar/test/progressbar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,21 @@ describe('progressbar directive', function () {
$rootScope.$digest();
expect(getBar(0).attr('aria-valuemax')).toBe('300');
});

it('should not have a total width over 100%', function() {
$rootScope.objects = [
{ value: 60, type: 'warning' },
{ value: 103 },
{ value: 270, type: 'info' }
];
$rootScope.max = 433;
$rootScope.$digest();
var totalWidth = 0;
for (var i = 0; i < 3; i++) {
totalWidth += parseFloat(getBar(i).css('width'));
}
expect(totalWidth.toFixed(2)).toBe('100.00');
});
});
});
});

0 comments on commit f86a06a

Please sign in to comment.