Skip to content

Commit

Permalink
Allow value 0 to be returned in onBlur callback (#1161)
Browse files Browse the repository at this point in the history
* allow value 0 to be returned in onBlur callback

* add changelog

* Update react/src/components/forms/InputCurrency/index.js

Co-authored-by: Steven Murray <[email protected]>

* address comment

Co-authored-by: Steven Murray <[email protected]>
  • Loading branch information
clairesunstudio and smurrayatwork authored Sep 1, 2020
1 parent 13c6207 commit 75df12f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
5 changes: 5 additions & 0 deletions changelogs/react-fix-inputCurrency-bug.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Added:
- project: React
component: InputCurrency
description: Fix onBlur bug to allow value 0 to be returned in onBlur callback. (#1161)
impact: Patch
12 changes: 6 additions & 6 deletions react/src/components/forms/InputCurrency/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,15 @@ const Currency = (props) => {
const handleBlur = (e) => {
const { type } = e;
const inputEl = ref.current;
const stringValue = inputEl.value;
// isNotNumber returns true if stringValue is null, undefined or 'NaN'
const value = inputEl && inputEl.value;
const numberValue = Number(numbro.unformat(value));
// isNotNumber returns true if value is null, undefined or NaN vs Number.isNaN only checks if value is NaN
/* eslint-disable-next-line no-restricted-globals */
const isNotNumber = !stringValue || isNaN(Number(numbro.unformat(stringValue)));
const isNotNumber = isNaN(value);
if (isNotNumber) {
inputEl.setAttribute('placeholder', props.placeholder);
}
let newValue = isNotNumber ? '' : Number(numbro.unformat(stringValue));
if (!is.empty(newValue)) {
} else {
let newValue = numberValue;
if (hasNumberProperty(props, 'max') && newValue > props.max) {
newValue = props.max;
}
Expand Down

0 comments on commit 75df12f

Please sign in to comment.