carbon-react 144.2.1 → 144.2.2

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.
@@ -1,5 +1,5 @@
1
1
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
- import React, { useCallback, useEffect, useMemo, useState } from "react";
2
+ import React, { useCallback, useEffect, useMemo, useState, useContext } from "react";
3
3
  import PropTypes from "prop-types";
4
4
  import { formatToISO, formattedValue, parseISODate, checkISOFormatAndLength } from "../date/__internal__/utils";
5
5
  import DateInput from "../date";
@@ -11,6 +11,7 @@ import useLocale from "../../hooks/__internal__/useLocale";
11
11
  import usePrevious from "../../hooks/__internal__/usePrevious";
12
12
  import getFormatData from "../date/__internal__/date-formats";
13
13
  import DateRangeContext from "./__internal__/date-range.context";
14
+ import NewValidationContext from "../carbon-provider/__internal__/new-validation.context";
14
15
  export const DateRange = ({
15
16
  endDateProps = {},
16
17
  id,
@@ -28,6 +29,10 @@ export const DateRange = ({
28
29
  isOptional,
29
30
  ...rest
30
31
  }) => {
32
+ const {
33
+ validationRedesignOptIn
34
+ } = useContext(NewValidationContext);
35
+ const labelsInlineWithNewValidation = validationRedesignOptIn ? false : labelsInline;
31
36
  const l = useLocale();
32
37
  const {
33
38
  dateFnsLocale
@@ -179,7 +184,7 @@ export const DateRange = ({
179
184
  const onChangeCallback = propsKey === "start" ? startDateOnChange : endDateOnChange;
180
185
  return {
181
186
  label: rest[`${propsKey}Label`],
182
- labelInline: labelsInline,
187
+ labelInline: labelsInlineWithNewValidation,
183
188
  value: inputValue,
184
189
  error: rest[`${propsKey}Error`],
185
190
  warning: rest[`${propsKey}Warning`],
@@ -194,7 +199,7 @@ export const DateRange = ({
194
199
  };
195
200
  };
196
201
  return /*#__PURE__*/React.createElement(StyledDateRange, _extends({}, tagComponent("date-range", rest), {
197
- labelsInline: labelsInline
202
+ labelsInline: labelsInlineWithNewValidation
198
203
  }, filterStyledSystemMarginProps(rest)), /*#__PURE__*/React.createElement(DateRangeContext.Provider, {
199
204
  value: {
200
205
  inputRefMap,
@@ -119,6 +119,7 @@ export const NumeralDate = ({
119
119
  const {
120
120
  validationRedesignOptIn
121
121
  } = useContext(NewValidationContext);
122
+ const labelInlineWithNewValidation = validationRedesignOptIn ? false : labelInline;
122
123
  const {
123
124
  current: uniqueId
124
125
  } = useRef(id || guid());
@@ -208,7 +209,7 @@ export const NumeralDate = ({
208
209
  warning: internalWarning,
209
210
  info: info,
210
211
  label: label,
211
- labelInline: labelInline,
212
+ labelInline: labelInlineWithNewValidation,
212
213
  labelWidth: labelWidth,
213
214
  labelAlign: labelAlign,
214
215
  labelHelp: !validationRedesignOptIn && labelHelp,
@@ -41,6 +41,7 @@ export const RadioButtonGroup = props => {
41
41
  const {
42
42
  validationRedesignOptIn
43
43
  } = useContext(NewValidationContext);
44
+ const legendInlineWithNewValidation = validationRedesignOptIn ? false : legendInline;
44
45
  if (!deprecateUncontrolledWarnTriggered && !onChange) {
45
46
  deprecateUncontrolledWarnTriggered = true;
46
47
  Logger.deprecate("Uncontrolled behaviour in `Radio Button` is deprecated and support will soon be removed. Please make sure all your inputs are controlled.");
@@ -48,7 +49,7 @@ export const RadioButtonGroup = props => {
48
49
  const marginProps = filterStyledSystemMarginProps(props);
49
50
  const isAboveLegendBreakpoint = useIsAboveBreakpoint(adaptiveLegendBreakpoint);
50
51
  const isAboveSpacingBreakpoint = useIsAboveBreakpoint(adaptiveSpacingBreakpoint);
51
- let inlineLegend = legendInline;
52
+ let inlineLegend = legendInlineWithNewValidation;
52
53
  if (adaptiveLegendBreakpoint) {
53
54
  inlineLegend = !!isAboveLegendBreakpoint;
54
55
  }
@@ -101,6 +101,7 @@ const FilterableSelect = /*#__PURE__*/React.forwardRef(({
101
101
  return customEvent;
102
102
  }, [name, id]);
103
103
  const triggerChange = useCallback((newValue, selectionConfirmed) => {
104
+ /* istanbul ignore else */
104
105
  if (onChange) {
105
106
  onChange(createCustomEvent(newValue, selectionConfirmed));
106
107
  }
@@ -146,7 +147,11 @@ const FilterableSelect = /*#__PURE__*/React.forwardRef(({
146
147
  const matchingOption = React.Children.toArray(children).find(child => /*#__PURE__*/React.isValidElement(child) && isExpectedOption(child, newValue));
147
148
  if (!matchingOption || matchingOption.props.text === undefined) {
148
149
  setTextValue(filterText || "");
149
- } else if (isClosing || matchingOption.props.text?.toLowerCase().startsWith(filterText?.toLowerCase().trim())) {
150
+ return;
151
+ }
152
+
153
+ /* istanbul ignore else */
154
+ if (isClosing || matchingOption.props.text?.toLowerCase().startsWith(filterText?.toLowerCase().trim())) {
150
155
  setTextValue(matchingOption.props.text);
151
156
  }
152
157
  }, [children, filterText]);
@@ -309,6 +314,13 @@ const FilterableSelect = /*#__PURE__*/React.forwardRef(({
309
314
  return !isAlreadyOpen;
310
315
  });
311
316
  }
317
+ useEffect(() => {
318
+ return () => {
319
+ if (focusTimer.current) {
320
+ clearTimeout(focusTimer.current);
321
+ }
322
+ };
323
+ }, []);
312
324
  function handleTextboxFocus(event) {
313
325
  const triggerFocus = () => onFocus?.(event);
314
326
  if (openOnFocus) {
@@ -66,6 +66,7 @@ const Textarea = /*#__PURE__*/React.forwardRef(({
66
66
  const {
67
67
  validationRedesignOptIn
68
68
  } = useContext(NewValidationContext);
69
+ const labelInlineWithNewValidation = validationRedesignOptIn ? false : labelInline;
69
70
  const [textareaMinHeight, setTextareaMinHeight] = useState(DEFAULT_MIN_HEIGHT);
70
71
  const computeLabelPropValues = prop => validationRedesignOptIn ? undefined : prop;
71
72
  const {
@@ -217,7 +218,7 @@ const Textarea = /*#__PURE__*/React.forwardRef(({
217
218
  tooltipPosition: tooltipPosition,
218
219
  helpAriaLabel: helpAriaLabel
219
220
  }, /*#__PURE__*/React.createElement(InputBehaviour, null, /*#__PURE__*/React.createElement(StyledTextarea, _extends({
220
- labelInline: labelInline,
221
+ labelInline: labelInlineWithNewValidation,
221
222
  "data-component": dataComponent,
222
223
  "data-role": dataRole,
223
224
  "data-element": dataElement,
@@ -233,7 +234,7 @@ const Textarea = /*#__PURE__*/React.forwardRef(({
233
234
  labelId: labelId,
234
235
  disabled: disabled,
235
236
  id: id,
236
- labelInline: computeLabelPropValues(labelInline),
237
+ labelInline: computeLabelPropValues(labelInlineWithNewValidation),
237
238
  labelAlign: computeLabelPropValues(labelAlign),
238
239
  labelWidth: computeLabelPropValues(labelWidth),
239
240
  labelHelp: computeLabelPropValues(labelHelp),
@@ -16,6 +16,7 @@ var _useLocale = _interopRequireDefault(require("../../hooks/__internal__/useLoc
16
16
  var _usePrevious = _interopRequireDefault(require("../../hooks/__internal__/usePrevious"));
17
17
  var _dateFormats = _interopRequireDefault(require("../date/__internal__/date-formats"));
18
18
  var _dateRange2 = _interopRequireDefault(require("./__internal__/date-range.context"));
19
+ var _newValidation = _interopRequireDefault(require("../carbon-provider/__internal__/new-validation.context"));
19
20
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
20
21
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
21
22
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -37,6 +38,10 @@ const DateRange = ({
37
38
  isOptional,
38
39
  ...rest
39
40
  }) => {
41
+ const {
42
+ validationRedesignOptIn
43
+ } = (0, _react.useContext)(_newValidation.default);
44
+ const labelsInlineWithNewValidation = validationRedesignOptIn ? false : labelsInline;
40
45
  const l = (0, _useLocale.default)();
41
46
  const {
42
47
  dateFnsLocale
@@ -188,7 +193,7 @@ const DateRange = ({
188
193
  const onChangeCallback = propsKey === "start" ? startDateOnChange : endDateOnChange;
189
194
  return {
190
195
  label: rest[`${propsKey}Label`],
191
- labelInline: labelsInline,
196
+ labelInline: labelsInlineWithNewValidation,
192
197
  value: inputValue,
193
198
  error: rest[`${propsKey}Error`],
194
199
  warning: rest[`${propsKey}Warning`],
@@ -203,7 +208,7 @@ const DateRange = ({
203
208
  };
204
209
  };
205
210
  return /*#__PURE__*/_react.default.createElement(_dateRange.default, _extends({}, (0, _tags.default)("date-range", rest), {
206
- labelsInline: labelsInline
211
+ labelsInline: labelsInlineWithNewValidation
207
212
  }, (0, _utils2.filterStyledSystemMarginProps)(rest)), /*#__PURE__*/_react.default.createElement(_dateRange2.default.Provider, {
208
213
  value: {
209
214
  inputRefMap,
@@ -128,6 +128,7 @@ const NumeralDate = ({
128
128
  const {
129
129
  validationRedesignOptIn
130
130
  } = (0, _react.useContext)(_newValidation.default);
131
+ const labelInlineWithNewValidation = validationRedesignOptIn ? false : labelInline;
131
132
  const {
132
133
  current: uniqueId
133
134
  } = (0, _react.useRef)(id || (0, _guid.default)());
@@ -217,7 +218,7 @@ const NumeralDate = ({
217
218
  warning: internalWarning,
218
219
  info: info,
219
220
  label: label,
220
- labelInline: labelInline,
221
+ labelInline: labelInlineWithNewValidation,
221
222
  labelWidth: labelWidth,
222
223
  labelAlign: labelAlign,
223
224
  labelHelp: !validationRedesignOptIn && labelHelp,
@@ -50,6 +50,7 @@ const RadioButtonGroup = props => {
50
50
  const {
51
51
  validationRedesignOptIn
52
52
  } = (0, _react.useContext)(_newValidation.default);
53
+ const legendInlineWithNewValidation = validationRedesignOptIn ? false : legendInline;
53
54
  if (!deprecateUncontrolledWarnTriggered && !onChange) {
54
55
  deprecateUncontrolledWarnTriggered = true;
55
56
  _logger.default.deprecate("Uncontrolled behaviour in `Radio Button` is deprecated and support will soon be removed. Please make sure all your inputs are controlled.");
@@ -57,7 +58,7 @@ const RadioButtonGroup = props => {
57
58
  const marginProps = (0, _utils.filterStyledSystemMarginProps)(props);
58
59
  const isAboveLegendBreakpoint = (0, _useIsAboveBreakpoint.default)(adaptiveLegendBreakpoint);
59
60
  const isAboveSpacingBreakpoint = (0, _useIsAboveBreakpoint.default)(adaptiveSpacingBreakpoint);
60
- let inlineLegend = legendInline;
61
+ let inlineLegend = legendInlineWithNewValidation;
61
62
  if (adaptiveLegendBreakpoint) {
62
63
  inlineLegend = !!isAboveLegendBreakpoint;
63
64
  }
@@ -110,6 +110,7 @@ const FilterableSelect = exports.FilterableSelect = /*#__PURE__*/_react.default.
110
110
  return customEvent;
111
111
  }, [name, id]);
112
112
  const triggerChange = (0, _react.useCallback)((newValue, selectionConfirmed) => {
113
+ /* istanbul ignore else */
113
114
  if (onChange) {
114
115
  onChange(createCustomEvent(newValue, selectionConfirmed));
115
116
  }
@@ -155,7 +156,11 @@ const FilterableSelect = exports.FilterableSelect = /*#__PURE__*/_react.default.
155
156
  const matchingOption = _react.default.Children.toArray(children).find(child => /*#__PURE__*/_react.default.isValidElement(child) && (0, _isExpectedOption.default)(child, newValue));
156
157
  if (!matchingOption || matchingOption.props.text === undefined) {
157
158
  setTextValue(filterText || "");
158
- } else if (isClosing || matchingOption.props.text?.toLowerCase().startsWith(filterText?.toLowerCase().trim())) {
159
+ return;
160
+ }
161
+
162
+ /* istanbul ignore else */
163
+ if (isClosing || matchingOption.props.text?.toLowerCase().startsWith(filterText?.toLowerCase().trim())) {
159
164
  setTextValue(matchingOption.props.text);
160
165
  }
161
166
  }, [children, filterText]);
@@ -318,6 +323,13 @@ const FilterableSelect = exports.FilterableSelect = /*#__PURE__*/_react.default.
318
323
  return !isAlreadyOpen;
319
324
  });
320
325
  }
326
+ (0, _react.useEffect)(() => {
327
+ return () => {
328
+ if (focusTimer.current) {
329
+ clearTimeout(focusTimer.current);
330
+ }
331
+ };
332
+ }, []);
321
333
  function handleTextboxFocus(event) {
322
334
  const triggerFocus = () => onFocus?.(event);
323
335
  if (openOnFocus) {
@@ -75,6 +75,7 @@ const Textarea = exports.OriginalTextarea = exports.Textarea = /*#__PURE__*/_rea
75
75
  const {
76
76
  validationRedesignOptIn
77
77
  } = (0, _react.useContext)(_newValidation.default);
78
+ const labelInlineWithNewValidation = validationRedesignOptIn ? false : labelInline;
78
79
  const [textareaMinHeight, setTextareaMinHeight] = (0, _react.useState)(_textarea.DEFAULT_MIN_HEIGHT);
79
80
  const computeLabelPropValues = prop => validationRedesignOptIn ? undefined : prop;
80
81
  const {
@@ -226,7 +227,7 @@ const Textarea = exports.OriginalTextarea = exports.Textarea = /*#__PURE__*/_rea
226
227
  tooltipPosition: tooltipPosition,
227
228
  helpAriaLabel: helpAriaLabel
228
229
  }, /*#__PURE__*/_react.default.createElement(_inputBehaviour.InputBehaviour, null, /*#__PURE__*/_react.default.createElement(_textarea.default, _extends({
229
- labelInline: labelInline,
230
+ labelInline: labelInlineWithNewValidation,
230
231
  "data-component": dataComponent,
231
232
  "data-role": dataRole,
232
233
  "data-element": dataElement,
@@ -242,7 +243,7 @@ const Textarea = exports.OriginalTextarea = exports.Textarea = /*#__PURE__*/_rea
242
243
  labelId: labelId,
243
244
  disabled: disabled,
244
245
  id: id,
245
- labelInline: computeLabelPropValues(labelInline),
246
+ labelInline: computeLabelPropValues(labelInlineWithNewValidation),
246
247
  labelAlign: computeLabelPropValues(labelAlign),
247
248
  labelWidth: computeLabelPropValues(labelWidth),
248
249
  labelHelp: computeLabelPropValues(labelHelp),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-react",
3
- "version": "144.2.1",
3
+ "version": "144.2.2",
4
4
  "description": "A library of reusable React components for easily building user interfaces.",
5
5
  "files": [
6
6
  "lib",