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/react/src/components/forms/InputCurrency/index.js b/react/src/components/forms/InputCurrency/index.js index 247b657308..1c8e0fe63c 100644 --- a/react/src/components/forms/InputCurrency/index.js +++ b/react/src/components/forms/InputCurrency/index.js @@ -140,15 +140,16 @@ 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 = 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 = !stringValue || isNaN(Number(numbro.unformat(stringValue))); + const isNotNumber = isNaN(numberValue); 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; }