diff --git a/.github/dependabot.yaml b/.github/dependabot.yml similarity index 100% rename from .github/dependabot.yaml rename to .github/dependabot.yml diff --git a/.github/mergeable.yaml b/.github/mergeable.yml similarity index 100% rename from .github/mergeable.yaml rename to .github/mergeable.yml diff --git a/package-lock.json b/package-lock.json index 3fe1b72..ffb86ba 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { - "name": "nvq-loan-calculator", + "name": "@nvisionative/nvq-loan-calculator", "version": "1.0.0-beta0001", "lockfileVersion": 2, "requires": true, "packages": { "": { - "name": "nvq-loan-calculator", + "name": "@nvisionative/nvq-loan-calculator", "version": "1.0.0-beta0001", "license": "MIT", "devDependencies": { diff --git a/src/components/nvq-loan-calculator/nvq-loan-calculator.tsx b/src/components/nvq-loan-calculator/nvq-loan-calculator.tsx index 39c03dc..e5cf24e 100644 --- a/src/components/nvq-loan-calculator/nvq-loan-calculator.tsx +++ b/src/components/nvq-loan-calculator/nvq-loan-calculator.tsx @@ -71,6 +71,11 @@ export class NvqLoanCalculator { } private getValidatedNumber(target: HTMLInputElement, digits: number, defaultValue: number = 0): number { + if (target.value === '') { + target.dataset.lastValidValue = defaultValue.toString(); + return undefined; + } + if (target.validity.valid) { const value = parseFloat(target.value); const roundedValue = this.roundTo(value, digits); @@ -115,6 +120,10 @@ export class NvqLoanCalculator { } private calculatePayment() { + if (isNaN(this.downPayment)) { + this.downPayment = 0; + } + // Assuming monthly compounding. const monthlyInterestRate = this.interestRate / 100 / 12; if (this.amortizationYears === undefined){ @@ -176,8 +185,7 @@ export class NvqLoanCalculator { min={0} max={this.totalAmount} step={0.01} - required - value={this.downPayment} + value={this.downPayment > 0 ? this.downPayment : ''} onKeyDown={e => this.onlyAllowNumbers(e)} onInput={e => this.downPayment = this.getValidatedNumber(e.target as HTMLInputElement, 2)} onBlur={e => this.displayErrorIfAny(e.target as HTMLInputElement)}