Skip to content

Commit

Permalink
fix(progressbar): display progressbar correctly if max is zero
Browse files Browse the repository at this point in the history
closes #3386
  • Loading branch information
chrstnbrn committed Oct 4, 2019
1 parent d0654c1 commit 9c88187
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/progressbar/progressbar.spec.ts
Expand Up @@ -58,6 +58,13 @@ describe('ngb-progressbar', () => {
expect(progressCmp.getPercentValue()).toBe(20);
});

it('should calculate the percentage (custom max size of zero)', () => {
progressCmp.max = 0;

progressCmp.value = 25;
expect(progressCmp.getPercentValue()).toBe(100);
});

it('should set the value to 0 for negative numbers', () => {
progressCmp.value = -20;
expect(progressCmp.getValue()).toBe(0);
Expand Down
8 changes: 7 additions & 1 deletion src/progressbar/progressbar.ts
Expand Up @@ -73,5 +73,11 @@ export class NgbProgressbar {

getValue() { return getValueInRange(this.value, this.max); }

getPercentValue() { return 100 * this.getValue() / this.max; }
getPercentValue() {
if (!this.max) {
return 100;
}

return (100 * this.getValue()) / this.max;
}
}

0 comments on commit 9c88187

Please sign in to comment.