From 75df12f92d2a8a2cdc792a1c9244e911be3843b2 Mon Sep 17 00:00:00 2001 From: Minghua Sun Date: Tue, 1 Sep 2020 19:08:47 -0400 Subject: [PATCH 1/4] Allow value 0 to be returned in onBlur callback (#1161) * allow value 0 to be returned in onBlur callback * add changelog * Update react/src/components/forms/InputCurrency/index.js Co-authored-by: Steven Murray * address comment Co-authored-by: Steven Murray --- changelogs/react-fix-inputCurrency-bug.yml | 5 +++++ react/src/components/forms/InputCurrency/index.js | 12 ++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 changelogs/react-fix-inputCurrency-bug.yml diff --git a/changelogs/react-fix-inputCurrency-bug.yml b/changelogs/react-fix-inputCurrency-bug.yml new file mode 100644 index 0000000000..2847466115 --- /dev/null +++ b/changelogs/react-fix-inputCurrency-bug.yml @@ -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 diff --git a/react/src/components/forms/InputCurrency/index.js b/react/src/components/forms/InputCurrency/index.js index 247b657308..2f17767eeb 100644 --- a/react/src/components/forms/InputCurrency/index.js +++ b/react/src/components/forms/InputCurrency/index.js @@ -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; } From 6e85459c8feed38ab9c326b931940aeaf04cb695 Mon Sep 17 00:00:00 2001 From: Minghua Sun Date: Wed, 2 Sep 2020 14:35:24 -0400 Subject: [PATCH 2/4] allow onBlur callback to fire on input with $ --- react/src/components/forms/InputCurrency/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/react/src/components/forms/InputCurrency/index.js b/react/src/components/forms/InputCurrency/index.js index 2f17767eeb..1c8e0fe63c 100644 --- a/react/src/components/forms/InputCurrency/index.js +++ b/react/src/components/forms/InputCurrency/index.js @@ -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 { From 5e591c7b64759ee11889633559ecb0179634d046 Mon Sep 17 00:00:00 2001 From: Minghua Sun Date: Wed, 2 Sep 2020 14:38:07 -0400 Subject: [PATCH 3/4] add changelog --- changelogs/react-fix-inputCurrency-bug.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/changelogs/react-fix-inputCurrency-bug.yml b/changelogs/react-fix-inputCurrency-bug.yml index 2847466115..65575e1143 100644 --- a/changelogs/react-fix-inputCurrency-bug.yml +++ b/changelogs/react-fix-inputCurrency-bug.yml @@ -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 From a362321e7a75655e67047d2528695f472ee00835 Mon Sep 17 00:00:00 2001 From: Minghua Sun Date: Wed, 2 Sep 2020 15:01:25 -0400 Subject: [PATCH 4/4] Changelog update and remove old changelog files --- CHANGELOG.md | 5 +++++ changelogs/react-fix-inputCurrency-bug.yml | 9 --------- 2 files changed, 5 insertions(+), 9 deletions(-) delete mode 100644 changelogs/react-fix-inputCurrency-bug.yml diff --git a/CHANGELOG.md b/CHANGELOG.md index 67f863515e..0df967e7d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Mayflower Release Notes All notable changes to this project will be documented in this file. +## 9.55.1 (9/2/2020) +### Fixed +- (React) [InputCurrency] Fix onBlur bug to allow value 0 to be returned in onBlur callback. (#1161) +- (React) [InputCurrency] Fix onBlur bug to allow onBlur callback to fire on input with `$`. (#1163) + ## 9.55.0 (8/24/2020) ### Changed - (React) [MainNav] DP-19425: Fix formatting of COVID global nav link on search.mass.gov (#1143) diff --git a/changelogs/react-fix-inputCurrency-bug.yml b/changelogs/react-fix-inputCurrency-bug.yml deleted file mode 100644 index 65575e1143..0000000000 --- a/changelogs/react-fix-inputCurrency-bug.yml +++ /dev/null @@ -1,9 +0,0 @@ -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