Skip to content

Commit

Permalink
(react)[InputCurrency]allow onBlur callback to fire on input with $ (#…
Browse files Browse the repository at this point in the history
…1163)

* allow onBlur callback to fire on input with $

* add changelog
  • Loading branch information
clairesunstudio authored Sep 2, 2020
1 parent 75df12f commit 228a1ae
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 5 additions & 1 deletion changelogs/react-fix-inputCurrency-bug.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Added:
Fixed:
- project: React
component: InputCurrency
description: Fix onBlur bug to allow value 0 to be returned in onBlur callback. (#1161)
impact: Patch
- project: React
component: InputCurrency
description: Fix onBlur bug to allow onBlur callback to fire on input with `$`. (#1163)
impact: Patch
5 changes: 3 additions & 2 deletions react/src/components/forms/InputCurrency/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,11 @@ const Currency = (props) => {
const { type } = e;
const inputEl = ref.current;
const value = inputEl && inputEl.value;
const numberValue = Number(numbro.unformat(value));
const numberValue = value && Number(numbro.unformat(value.replace('$', '')));

// 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 = isNaN(value);
const isNotNumber = isNaN(numberValue);
if (isNotNumber) {
inputEl.setAttribute('placeholder', props.placeholder);
} else {
Expand Down

0 comments on commit 228a1ae

Please sign in to comment.