carbon-react 106.6.7 → 106.6.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -29,8 +29,7 @@ const Decimal = ({
29
29
  }) => {
30
30
  const l = useContext(LocaleContext);
31
31
  const emptyValue = allowEmptyValue ? "" : "0.00";
32
-
33
- const getSafeValueProp = initialValue => {
32
+ const getSafeValueProp = useCallback(initialValue => {
34
33
  // We're intentionally preventing the use of number values to help prevent any unintentional rounding issues
35
34
  invariant(typeof initialValue === "string", "Decimal `value` prop must be a string");
36
35
 
@@ -39,8 +38,7 @@ const Decimal = ({
39
38
  }
40
39
 
41
40
  return initialValue;
42
- };
43
-
41
+ }, [allowEmptyValue]);
44
42
  const getSeparator = useCallback(separatorType => {
45
43
  const numberWithGroupAndDecimalSeparator = 10000.1;
46
44
  return Intl.NumberFormat(locale || l.locale()).formatToParts(numberWithGroupAndDecimalSeparator).find(part => part.type === separatorType).value;
@@ -169,18 +167,22 @@ const Decimal = ({
169
167
  invariant(prevControlledRef.current !== isControlled, message);
170
168
  prevControlledRef.current = isControlled;
171
169
  }, [isControlled]);
170
+ const prevValue = usePrevious(value);
172
171
  useEffect(() => {
173
- const unformattedValue = toStandardDecimal(stateValue);
172
+ const standardDecimalValue = toStandardDecimal(stateValue);
174
173
 
175
174
  if (isControlled) {
176
175
  const valueProp = getSafeValueProp(value);
177
176
 
178
- if (unformattedValue !== valueProp) {
179
- setStateValue(formatValue(value));
177
+ if (standardDecimalValue !== valueProp) {
178
+ if (valueProp === "" && prevValue === "") {
179
+ setStateValue(formatValue(emptyValue));
180
+ } else {
181
+ setStateValue(formatValue(valueProp));
182
+ }
180
183
  }
181
- } // eslint-disable-next-line react-hooks/exhaustive-deps
182
-
183
- }, [value]);
184
+ }
185
+ }, [emptyValue, formatValue, getSafeValueProp, isControlled, prevValue, stateValue, toStandardDecimal, value]);
184
186
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Textbox, _extends({
185
187
  onKeyPress: onKeyPress,
186
188
  align: align,
@@ -50,8 +50,7 @@ const Decimal = ({
50
50
  }) => {
51
51
  const l = (0, _react.useContext)(_i18nContext.default);
52
52
  const emptyValue = allowEmptyValue ? "" : "0.00";
53
-
54
- const getSafeValueProp = initialValue => {
53
+ const getSafeValueProp = (0, _react.useCallback)(initialValue => {
55
54
  // We're intentionally preventing the use of number values to help prevent any unintentional rounding issues
56
55
  (0, _invariant.default)(typeof initialValue === "string", "Decimal `value` prop must be a string");
57
56
 
@@ -60,8 +59,7 @@ const Decimal = ({
60
59
  }
61
60
 
62
61
  return initialValue;
63
- };
64
-
62
+ }, [allowEmptyValue]);
65
63
  const getSeparator = (0, _react.useCallback)(separatorType => {
66
64
  const numberWithGroupAndDecimalSeparator = 10000.1;
67
65
  return Intl.NumberFormat(locale || l.locale()).formatToParts(numberWithGroupAndDecimalSeparator).find(part => part.type === separatorType).value;
@@ -190,18 +188,22 @@ const Decimal = ({
190
188
  (0, _invariant.default)(prevControlledRef.current !== isControlled, message);
191
189
  prevControlledRef.current = isControlled;
192
190
  }, [isControlled]);
191
+ const prevValue = (0, _usePrevious.default)(value);
193
192
  (0, _react.useEffect)(() => {
194
- const unformattedValue = toStandardDecimal(stateValue);
193
+ const standardDecimalValue = toStandardDecimal(stateValue);
195
194
 
196
195
  if (isControlled) {
197
196
  const valueProp = getSafeValueProp(value);
198
197
 
199
- if (unformattedValue !== valueProp) {
200
- setStateValue(formatValue(value));
198
+ if (standardDecimalValue !== valueProp) {
199
+ if (valueProp === "" && prevValue === "") {
200
+ setStateValue(formatValue(emptyValue));
201
+ } else {
202
+ setStateValue(formatValue(valueProp));
203
+ }
201
204
  }
202
- } // eslint-disable-next-line react-hooks/exhaustive-deps
203
-
204
- }, [value]);
205
+ }
206
+ }, [emptyValue, formatValue, getSafeValueProp, isControlled, prevValue, stateValue, toStandardDecimal, value]);
205
207
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_textbox.default, _extends({
206
208
  onKeyPress: onKeyPress,
207
209
  align: align,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-react",
3
- "version": "106.6.7",
3
+ "version": "106.6.8",
4
4
  "description": "A library of reusable React components for easily building user interfaces.",
5
5
  "engineStrict": true,
6
6
  "engines": {