carbon-react 114.7.1 → 114.9.0
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.
- package/esm/__internal__/checkable-input/checkable-input.component.d.ts +1 -1
- package/esm/__internal__/checkable-input/checkable-input.component.js +5 -10
- package/esm/__internal__/checkable-input/hidden-checkable-input.component.d.ts +1 -3
- package/esm/__internal__/checkable-input/hidden-checkable-input.component.js +5 -10
- package/esm/__internal__/input/input.component.d.ts +2 -2
- package/esm/__internal__/input/input.component.js +14 -7
- package/esm/__internal__/input-behaviour/useInputBehaviour.d.ts +1 -1
- package/esm/components/advanced-color-picker/advanced-color-picker.component.js +1 -3
- package/esm/components/checkbox/checkbox.component.d.ts +3 -4
- package/esm/components/checkbox/checkbox.component.js +13 -5
- package/esm/components/date/date.component.js +32 -17
- package/esm/components/date-range/date-range.component.js +20 -2
- package/esm/components/date-range/date-range.d.ts +8 -0
- package/esm/components/decimal/decimal.component.d.ts +1 -1
- package/esm/components/decimal/decimal.component.js +17 -7
- package/esm/components/grouped-character/grouped-character.component.d.ts +1 -1
- package/esm/components/grouped-character/grouped-character.component.js +15 -5
- package/esm/components/menu/menu-item/menu-item.component.js +1 -1
- package/esm/components/number/number.component.d.ts +2 -2
- package/esm/components/number/number.component.js +15 -5
- package/esm/components/numeral-date/numeral-date.component.d.ts +13 -1
- package/esm/components/numeral-date/numeral-date.component.js +48 -5
- package/esm/components/radio-button/radio-button.component.d.ts +2 -0
- package/esm/components/radio-button/radio-button.component.js +10 -1
- package/esm/components/search/search.component.d.ts +1 -1
- package/esm/components/search/search.component.js +13 -12
- package/esm/components/select/filterable-select/filterable-select.component.js +23 -7
- package/esm/components/select/multi-select/multi-select.component.js +23 -7
- package/esm/components/select/select-textbox/select-textbox.component.js +5 -5
- package/esm/components/select/simple-select/simple-select.component.js +23 -7
- package/esm/components/simple-color-picker/simple-color/simple-color.style.d.ts +1 -1
- package/esm/components/switch/switch.component.d.ts +4 -2
- package/esm/components/switch/switch.component.js +14 -5
- package/esm/components/tabs/__internal__/tab-title/tab-title.component.js +5 -0
- package/esm/components/tabs/__internal__/tab-title/tab-title.d.ts +2 -0
- package/esm/components/tabs/tab/tab.component.js +8 -1
- package/esm/components/tabs/tab/tab.d.ts +5 -0
- package/esm/components/tabs/tabs.component.js +16 -23
- package/esm/components/textarea/textarea.component.d.ts +1 -1
- package/esm/components/textarea/textarea.component.js +37 -14
- package/esm/components/textbox/textbox.component.d.ts +1 -1
- package/esm/components/textbox/textbox.component.js +13 -5
- package/esm/components/tile-select/tile-select.component.js +14 -5
- package/lib/__internal__/checkable-input/checkable-input.component.d.ts +1 -1
- package/lib/__internal__/checkable-input/checkable-input.component.js +5 -8
- package/lib/__internal__/checkable-input/hidden-checkable-input.component.d.ts +1 -3
- package/lib/__internal__/checkable-input/hidden-checkable-input.component.js +5 -8
- package/lib/__internal__/input/input.component.d.ts +2 -2
- package/lib/__internal__/input/input.component.js +13 -6
- package/lib/__internal__/input-behaviour/useInputBehaviour.d.ts +1 -1
- package/lib/components/advanced-color-picker/advanced-color-picker.component.js +1 -3
- package/lib/components/checkbox/checkbox.component.d.ts +3 -4
- package/lib/components/checkbox/checkbox.component.js +16 -3
- package/lib/components/date/date.component.js +33 -14
- package/lib/components/date-range/date-range.component.js +20 -2
- package/lib/components/date-range/date-range.d.ts +8 -0
- package/lib/components/decimal/decimal.component.d.ts +1 -1
- package/lib/components/decimal/decimal.component.js +20 -5
- package/lib/components/grouped-character/grouped-character.component.d.ts +1 -1
- package/lib/components/grouped-character/grouped-character.component.js +18 -4
- package/lib/components/menu/menu-item/menu-item.component.js +1 -1
- package/lib/components/number/number.component.d.ts +2 -2
- package/lib/components/number/number.component.js +18 -4
- package/lib/components/numeral-date/numeral-date.component.d.ts +13 -1
- package/lib/components/numeral-date/numeral-date.component.js +48 -5
- package/lib/components/radio-button/radio-button.component.d.ts +2 -0
- package/lib/components/radio-button/radio-button.component.js +13 -1
- package/lib/components/search/search.component.d.ts +1 -1
- package/lib/components/search/search.component.js +16 -10
- package/lib/components/select/filterable-select/filterable-select.component.js +25 -7
- package/lib/components/select/multi-select/multi-select.component.js +25 -7
- package/lib/components/select/select-textbox/select-textbox.component.js +5 -3
- package/lib/components/select/simple-select/simple-select.component.js +26 -7
- package/lib/components/simple-color-picker/simple-color/simple-color.style.d.ts +1 -1
- package/lib/components/switch/switch.component.d.ts +4 -2
- package/lib/components/switch/switch.component.js +17 -3
- package/lib/components/tabs/__internal__/tab-title/tab-title.component.js +5 -0
- package/lib/components/tabs/__internal__/tab-title/tab-title.d.ts +2 -0
- package/lib/components/tabs/tab/tab.component.js +8 -1
- package/lib/components/tabs/tab/tab.d.ts +5 -0
- package/lib/components/tabs/tabs.component.js +16 -24
- package/lib/components/textarea/textarea.component.d.ts +1 -1
- package/lib/components/textarea/textarea.component.js +38 -11
- package/lib/components/textbox/textbox.component.d.ts +1 -1
- package/lib/components/textbox/textbox.component.js +16 -3
- package/lib/components/tile-select/tile-select.component.js +17 -4
- package/package.json +1 -1
|
@@ -23,6 +23,8 @@ var _tooltipProvider = require("../../__internal__/tooltip-provider");
|
|
|
23
23
|
|
|
24
24
|
var _checkboxGroup = require("./checkbox-group.component");
|
|
25
25
|
|
|
26
|
+
var _logger = _interopRequireDefault(require("../../__internal__/utils/logger"));
|
|
27
|
+
|
|
26
28
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
29
|
|
|
28
30
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
@@ -31,7 +33,9 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
|
|
|
31
33
|
|
|
32
34
|
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
33
35
|
|
|
34
|
-
|
|
36
|
+
let deprecateInputRefWarnTriggered = false;
|
|
37
|
+
|
|
38
|
+
const Checkbox = /*#__PURE__*/_react.default.forwardRef(({
|
|
35
39
|
id,
|
|
36
40
|
label,
|
|
37
41
|
onChange,
|
|
@@ -63,8 +67,9 @@ const Checkbox = ({
|
|
|
63
67
|
"data-element": dataElement,
|
|
64
68
|
"data-role": dataRole,
|
|
65
69
|
helpAriaLabel,
|
|
70
|
+
inputRef,
|
|
66
71
|
...props
|
|
67
|
-
}) => {
|
|
72
|
+
}, ref) => {
|
|
68
73
|
const largeScreen = (0, _useIsAboveBreakpoint.default)(adaptiveSpacingBreakpoint);
|
|
69
74
|
const adaptiveSpacingSmallScreen = !!(adaptiveSpacingBreakpoint && !largeScreen);
|
|
70
75
|
const {
|
|
@@ -72,6 +77,13 @@ const Checkbox = ({
|
|
|
72
77
|
warning: contextWarning,
|
|
73
78
|
info: contextInfo
|
|
74
79
|
} = (0, _react.useContext)(_checkboxGroup.CheckboxGroupContext);
|
|
80
|
+
|
|
81
|
+
if (!deprecateInputRefWarnTriggered && inputRef) {
|
|
82
|
+
deprecateInputRefWarnTriggered = true;
|
|
83
|
+
|
|
84
|
+
_logger.default.deprecate("The `inputRef` prop in `Checkbox` component is deprecated and will soon be removed. Please use `ref` instead.");
|
|
85
|
+
}
|
|
86
|
+
|
|
75
87
|
const inputProps = {
|
|
76
88
|
onClick,
|
|
77
89
|
onChange,
|
|
@@ -98,6 +110,7 @@ const Checkbox = ({
|
|
|
98
110
|
inputWidth,
|
|
99
111
|
labelWidth,
|
|
100
112
|
tooltipPosition,
|
|
113
|
+
ref: ref || inputRef,
|
|
101
114
|
...props
|
|
102
115
|
};
|
|
103
116
|
return /*#__PURE__*/_react.default.createElement(_tooltipProvider.TooltipProvider, {
|
|
@@ -118,7 +131,7 @@ const Checkbox = ({
|
|
|
118
131
|
reverse: reverse,
|
|
119
132
|
size: size
|
|
120
133
|
}, (0, _utils.filterStyledSystemMarginProps)(props)), /*#__PURE__*/_react.default.createElement(_checkableInput.default, inputProps, /*#__PURE__*/_react.default.createElement(_checkboxSvg.default, null))));
|
|
121
|
-
};
|
|
134
|
+
});
|
|
122
135
|
|
|
123
136
|
exports.Checkbox = Checkbox;
|
|
124
137
|
Checkbox.propTypes = {
|
|
@@ -31,6 +31,8 @@ var _dateRange = _interopRequireDefault(require("../date-range/date-range.contex
|
|
|
31
31
|
|
|
32
32
|
var _useClickAwayListener = _interopRequireDefault(require("../../hooks/__internal__/useClickAwayListener"));
|
|
33
33
|
|
|
34
|
+
var _logger = _interopRequireDefault(require("../../__internal__/utils/logger"));
|
|
35
|
+
|
|
34
36
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
35
37
|
|
|
36
38
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
@@ -40,8 +42,9 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
|
|
|
40
42
|
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
41
43
|
|
|
42
44
|
const marginPropTypes = (0, _utils2.filterStyledSystemMarginProps)(_propTypes2.default.space);
|
|
45
|
+
let deprecateInputRefWarnTriggered = false;
|
|
43
46
|
|
|
44
|
-
const DateInput = ({
|
|
47
|
+
const DateInput = /*#__PURE__*/_react.default.forwardRef(({
|
|
45
48
|
adaptiveLabelBreakpoint,
|
|
46
49
|
allowEmptyValue,
|
|
47
50
|
autoFocus,
|
|
@@ -64,11 +67,12 @@ const DateInput = ({
|
|
|
64
67
|
size = "medium",
|
|
65
68
|
tooltipPosition,
|
|
66
69
|
value,
|
|
70
|
+
inputRef,
|
|
67
71
|
...rest
|
|
68
|
-
}) => {
|
|
72
|
+
}, ref) => {
|
|
69
73
|
const wrapperRef = (0, _react.useRef)();
|
|
70
74
|
const parentRef = (0, _react.useRef)();
|
|
71
|
-
const
|
|
75
|
+
const internalInputRef = (0, _react.useRef)();
|
|
72
76
|
const alreadyFocused = (0, _react.useRef)(false);
|
|
73
77
|
const isBlurBlocked = (0, _react.useRef)(false);
|
|
74
78
|
const focusedViaPicker = (0, _react.useRef)(false);
|
|
@@ -89,6 +93,12 @@ const DateInput = ({
|
|
|
89
93
|
const [selectedDays, setSelectedDays] = (0, _react.useState)((0, _utils.checkISOFormatAndLength)(value) ? (0, _utils.parseISODate)(value) : (0, _utils.parseDate)(format, value));
|
|
90
94
|
const isInitialValue = (0, _react.useRef)(true);
|
|
91
95
|
|
|
96
|
+
if (!deprecateInputRefWarnTriggered && inputRef) {
|
|
97
|
+
deprecateInputRefWarnTriggered = true;
|
|
98
|
+
|
|
99
|
+
_logger.default.deprecate("The `inputRef` prop in `DateInput` component is deprecated and will soon be removed. Please use `ref` instead.");
|
|
100
|
+
}
|
|
101
|
+
|
|
92
102
|
const computeInvalidRawValue = inputValue => allowEmptyValue && !inputValue.length ? inputValue : null;
|
|
93
103
|
|
|
94
104
|
const buildCustomEvent = ev => {
|
|
@@ -116,9 +126,9 @@ const DateInput = ({
|
|
|
116
126
|
const handleClickAway = () => {
|
|
117
127
|
if (open) {
|
|
118
128
|
alreadyFocused.current = true;
|
|
119
|
-
|
|
129
|
+
internalInputRef.current.focus();
|
|
120
130
|
isBlurBlocked.current = false;
|
|
121
|
-
|
|
131
|
+
internalInputRef.current.blur();
|
|
122
132
|
setOpen(false);
|
|
123
133
|
alreadyFocused.current = false;
|
|
124
134
|
}
|
|
@@ -132,10 +142,10 @@ const DateInput = ({
|
|
|
132
142
|
};
|
|
133
143
|
|
|
134
144
|
const focusInput = () => {
|
|
135
|
-
var
|
|
145
|
+
var _internalInputRef$cur;
|
|
136
146
|
|
|
137
147
|
focusedViaPicker.current = true;
|
|
138
|
-
(
|
|
148
|
+
(_internalInputRef$cur = internalInputRef.current) === null || _internalInputRef$cur === void 0 ? void 0 : _internalInputRef$cur.focus();
|
|
139
149
|
};
|
|
140
150
|
|
|
141
151
|
const handleDayClick = (day, ev) => {
|
|
@@ -260,11 +270,19 @@ const DateInput = ({
|
|
|
260
270
|
handleClickInside(ev);
|
|
261
271
|
};
|
|
262
272
|
|
|
263
|
-
const assignInput =
|
|
273
|
+
const assignInput = (0, _react.useCallback)(inputElement => {
|
|
264
274
|
var _inputRefMap$inputNam;
|
|
265
275
|
|
|
266
|
-
|
|
267
|
-
parentRef.current =
|
|
276
|
+
internalInputRef.current = inputElement;
|
|
277
|
+
parentRef.current = inputElement === null || inputElement === void 0 ? void 0 : inputElement.parentElement;
|
|
278
|
+
|
|
279
|
+
if (ref) {
|
|
280
|
+
if (typeof ref === "function") {
|
|
281
|
+
ref(inputElement);
|
|
282
|
+
} else {
|
|
283
|
+
ref.current = inputElement;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
268
286
|
|
|
269
287
|
if (inputRefMap && ((_inputRefMap$inputNam = inputRefMap[inputName]) === null || _inputRefMap$inputNam === void 0 ? void 0 : _inputRefMap$inputNam.setOpen) !== setOpen) {
|
|
270
288
|
setInputRefMap({
|
|
@@ -274,8 +292,7 @@ const DateInput = ({
|
|
|
274
292
|
}
|
|
275
293
|
});
|
|
276
294
|
}
|
|
277
|
-
};
|
|
278
|
-
|
|
295
|
+
}, [inputName, inputRefMap, setInputRefMap, ref]);
|
|
279
296
|
(0, _react.useEffect)(() => {
|
|
280
297
|
const [matchedFormat, matchedValue] = (0, _utils.findMatchedFormatAndValue)(value, formats);
|
|
281
298
|
|
|
@@ -318,6 +335,7 @@ const DateInput = ({
|
|
|
318
335
|
}, (0, _utils2.filterStyledSystemMarginProps)(rest), {
|
|
319
336
|
applyDateRangeStyling: !!inputRefMap
|
|
320
337
|
}), /*#__PURE__*/_react.default.createElement(_textbox.default, _extends({}, (0, _utils2.filterOutStyledSystemSpacingProps)(rest), {
|
|
338
|
+
inputRef: inputRef,
|
|
321
339
|
value: computedValue(),
|
|
322
340
|
onBlur: handleBlur,
|
|
323
341
|
onChange: handleChange,
|
|
@@ -329,7 +347,7 @@ const DateInput = ({
|
|
|
329
347
|
iconOnMouseDown: handleIconMouseDown,
|
|
330
348
|
inputIcon: "calendar",
|
|
331
349
|
labelInline: labelInline,
|
|
332
|
-
|
|
350
|
+
ref: assignInput,
|
|
333
351
|
adaptiveLabelBreakpoint: adaptiveLabelBreakpoint,
|
|
334
352
|
tooltipPosition: tooltipPosition,
|
|
335
353
|
helpAriaLabel: helpAriaLabel,
|
|
@@ -349,7 +367,7 @@ const DateInput = ({
|
|
|
349
367
|
pickerMouseDown: handlePickerMouseDown,
|
|
350
368
|
open: open
|
|
351
369
|
}));
|
|
352
|
-
};
|
|
370
|
+
});
|
|
353
371
|
|
|
354
372
|
DateInput.propTypes = { ..._textbox.default.propTypes,
|
|
355
373
|
...marginPropTypes,
|
|
@@ -377,5 +395,6 @@ DateInput.propTypes = { ..._textbox.default.propTypes,
|
|
|
377
395
|
/** Boolean to allow the input to have an empty value */
|
|
378
396
|
allowEmptyValue: _propTypes.default.bool
|
|
379
397
|
};
|
|
398
|
+
DateInput.displayName = "DateInput";
|
|
380
399
|
var _default = DateInput;
|
|
381
400
|
exports.default = _default;
|
|
@@ -52,6 +52,8 @@ const DateRange = ({
|
|
|
52
52
|
tooltipPosition,
|
|
53
53
|
validationOnLabel,
|
|
54
54
|
value,
|
|
55
|
+
startRef,
|
|
56
|
+
endRef,
|
|
55
57
|
...rest
|
|
56
58
|
}) => {
|
|
57
59
|
const l = (0, _useLocale.default)();
|
|
@@ -246,13 +248,15 @@ const DateRange = ({
|
|
|
246
248
|
"data-element": "start-date",
|
|
247
249
|
labelWidth: inlineLabelWidth // Textbox only applies this when labelsInLine prop is true
|
|
248
250
|
,
|
|
249
|
-
tooltipPosition: tooltipPosition
|
|
251
|
+
tooltipPosition: tooltipPosition,
|
|
252
|
+
ref: startRef
|
|
250
253
|
})), /*#__PURE__*/_react.default.createElement(_date.default, _extends({}, dateProps("end"), {
|
|
251
254
|
onFocus: () => handleFocus("start"),
|
|
252
255
|
"data-element": "end-date",
|
|
253
256
|
labelWidth: inlineLabelWidth // Textbox only applies this when labelsInLine prop is true
|
|
254
257
|
,
|
|
255
|
-
tooltipPosition: tooltipPosition
|
|
258
|
+
tooltipPosition: tooltipPosition,
|
|
259
|
+
ref: endRef
|
|
256
260
|
}))));
|
|
257
261
|
};
|
|
258
262
|
|
|
@@ -294,6 +298,13 @@ DateRange.propTypes = {
|
|
|
294
298
|
Pass true boolean to only display blue border */
|
|
295
299
|
startInfo: _propTypes.default.oneOfType([_propTypes.default.bool, _propTypes.default.string]),
|
|
296
300
|
|
|
301
|
+
/**
|
|
302
|
+
* A React ref to pass to the first of the two Date Input fields
|
|
303
|
+
*/
|
|
304
|
+
startRef: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.shape({
|
|
305
|
+
current: _propTypes.default.instanceOf(HTMLInputElement)
|
|
306
|
+
})]),
|
|
307
|
+
|
|
297
308
|
/** Indicate that error has occurred on end date
|
|
298
309
|
Pass string to display icon, tooltip and red border
|
|
299
310
|
Pass true boolean to only display red border */
|
|
@@ -309,6 +320,13 @@ DateRange.propTypes = {
|
|
|
309
320
|
Pass true boolean to only display blue border */
|
|
310
321
|
endInfo: _propTypes.default.oneOfType([_propTypes.default.bool, _propTypes.default.string]),
|
|
311
322
|
|
|
323
|
+
/**
|
|
324
|
+
* A React ref to pass to the second of the two Date Input fields
|
|
325
|
+
*/
|
|
326
|
+
endRef: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.shape({
|
|
327
|
+
current: _propTypes.default.instanceOf(HTMLInputElement)
|
|
328
|
+
})]),
|
|
329
|
+
|
|
312
330
|
/** When true, validation icons will be placed on labels instead of being placed on the inputs */
|
|
313
331
|
validationOnLabel: _propTypes.default.bool,
|
|
314
332
|
|
|
@@ -40,6 +40,10 @@ export interface DateRangeProps extends MarginProps {
|
|
|
40
40
|
* Pass true boolean to only display orange border
|
|
41
41
|
*/
|
|
42
42
|
endWarning?: boolean | string;
|
|
43
|
+
/**
|
|
44
|
+
* A React ref to pass to the second of the two Date Input fields
|
|
45
|
+
*/
|
|
46
|
+
endRef?: React.ForwardedRef<HTMLInputElement>;
|
|
43
47
|
/** An optional string prop to provide an id to the component */
|
|
44
48
|
id?: string;
|
|
45
49
|
/** Display labels inline */
|
|
@@ -71,6 +75,10 @@ export interface DateRangeProps extends MarginProps {
|
|
|
71
75
|
* Pass true boolean to only display blue border
|
|
72
76
|
*/
|
|
73
77
|
startInfo?: boolean | string;
|
|
78
|
+
/**
|
|
79
|
+
* A React ref to pass to the first of the two Date Input fields
|
|
80
|
+
*/
|
|
81
|
+
startRef?: React.ForwardedRef<HTMLInputElement>;
|
|
74
82
|
/** An array containing the value of startDate and endDate */
|
|
75
83
|
value: string[];
|
|
76
84
|
/** When true, validation icons will be placed on labels instead of being placed on the inputs */
|
|
@@ -40,5 +40,5 @@ export interface DecimalProps extends Omit<CommonTextboxProps, "onChange" | "onB
|
|
|
40
40
|
/** The locale string - default en */
|
|
41
41
|
locale?: string;
|
|
42
42
|
}
|
|
43
|
-
export declare const Decimal:
|
|
43
|
+
export declare const Decimal: React.ForwardRefExoticComponent<DecimalProps & React.RefAttributes<HTMLInputElement>>;
|
|
44
44
|
export default Decimal;
|
|
@@ -17,6 +17,8 @@ var _i18nContext = _interopRequireDefault(require("../../__internal__/i18n-conte
|
|
|
17
17
|
|
|
18
18
|
var _usePrevious = _interopRequireDefault(require("../../hooks/__internal__/usePrevious"));
|
|
19
19
|
|
|
20
|
+
var _logger = _interopRequireDefault(require("../../__internal__/utils/logger"));
|
|
21
|
+
|
|
20
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
23
|
|
|
22
24
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
@@ -25,7 +27,9 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
|
|
|
25
27
|
|
|
26
28
|
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
27
29
|
|
|
28
|
-
|
|
30
|
+
let deprecateInputRefWarnTriggered = false;
|
|
31
|
+
|
|
32
|
+
const Decimal = /*#__PURE__*/_react.default.forwardRef(({
|
|
29
33
|
align = "right",
|
|
30
34
|
defaultValue,
|
|
31
35
|
precision = 2,
|
|
@@ -40,9 +44,17 @@ const Decimal = ({
|
|
|
40
44
|
required,
|
|
41
45
|
locale,
|
|
42
46
|
value,
|
|
47
|
+
inputRef,
|
|
43
48
|
...rest
|
|
44
|
-
}) => {
|
|
49
|
+
}, ref) => {
|
|
45
50
|
const l = (0, _react.useContext)(_i18nContext.default);
|
|
51
|
+
|
|
52
|
+
if (!deprecateInputRefWarnTriggered && inputRef) {
|
|
53
|
+
deprecateInputRefWarnTriggered = true;
|
|
54
|
+
|
|
55
|
+
_logger.default.deprecate("The `inputRef` prop in `Decimal` component is deprecated and will soon be removed. Please use `ref` instead.");
|
|
56
|
+
}
|
|
57
|
+
|
|
46
58
|
const emptyValue = allowEmptyValue ? "" : "0.00";
|
|
47
59
|
const getSafeValueProp = (0, _react.useCallback)(initialValue => {
|
|
48
60
|
// We're intentionally preventing the use of number values to help prevent any unintentional rounding issues
|
|
@@ -72,7 +84,7 @@ const Decimal = ({
|
|
|
72
84
|
return valueToFormat;
|
|
73
85
|
}
|
|
74
86
|
/* Guards against any white-space only strings like " " being
|
|
75
|
-
|
|
87
|
+
mishandled and returned as `NaN` for the value displayed in the textbox */
|
|
76
88
|
|
|
77
89
|
|
|
78
90
|
if (valueToFormat === "" || valueToFormat.match(/\s+/g)) {
|
|
@@ -212,14 +224,16 @@ const Decimal = ({
|
|
|
212
224
|
onBlur: handleOnBlur,
|
|
213
225
|
value: stateValue,
|
|
214
226
|
"data-component": "decimal",
|
|
215
|
-
id: id
|
|
227
|
+
id: id,
|
|
228
|
+
ref: ref,
|
|
229
|
+
inputRef: inputRef
|
|
216
230
|
}, rest)), /*#__PURE__*/_react.default.createElement("input", {
|
|
217
231
|
name: name,
|
|
218
232
|
value: toStandardDecimal(stateValue),
|
|
219
233
|
type: "hidden",
|
|
220
234
|
"data-component": "hidden-input"
|
|
221
235
|
}));
|
|
222
|
-
};
|
|
236
|
+
});
|
|
223
237
|
|
|
224
238
|
exports.Decimal = Decimal;
|
|
225
239
|
Decimal.propTypes = {
|
|
@@ -752,5 +766,6 @@ Decimal.propTypes = {
|
|
|
752
766
|
"warning": _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.bool]),
|
|
753
767
|
"width": _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string])
|
|
754
768
|
};
|
|
769
|
+
Decimal.displayName = "Decimal";
|
|
755
770
|
var _default = Decimal;
|
|
756
771
|
exports.default = _default;
|
|
@@ -26,5 +26,5 @@ export interface GroupedCharacterProps extends Omit<TextboxProps, "onChange" | "
|
|
|
26
26
|
/** Input value if component is meant to be used as a controlled component */
|
|
27
27
|
value?: string;
|
|
28
28
|
}
|
|
29
|
-
export declare const GroupedCharacter:
|
|
29
|
+
export declare const GroupedCharacter: React.ForwardRefExoticComponent<GroupedCharacterProps & React.RefAttributes<HTMLInputElement>>;
|
|
30
30
|
export default GroupedCharacter;
|
|
@@ -13,6 +13,8 @@ var _textbox = _interopRequireDefault(require("../textbox"));
|
|
|
13
13
|
|
|
14
14
|
var _groupedCharacter = require("./grouped-character.utils");
|
|
15
15
|
|
|
16
|
+
var _logger = _interopRequireDefault(require("../../__internal__/utils/logger"));
|
|
17
|
+
|
|
16
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
19
|
|
|
18
20
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
@@ -38,21 +40,30 @@ const buildCustomTarget = ({
|
|
|
38
40
|
};
|
|
39
41
|
};
|
|
40
42
|
|
|
41
|
-
|
|
43
|
+
let deprecateInputRefWarnTriggered = false;
|
|
44
|
+
|
|
45
|
+
const GroupedCharacter = /*#__PURE__*/_react.default.forwardRef(({
|
|
42
46
|
defaultValue,
|
|
43
47
|
groups,
|
|
44
48
|
onBlur,
|
|
45
49
|
onChange,
|
|
46
50
|
separator: rawSeparator,
|
|
47
51
|
value: externalValue,
|
|
52
|
+
inputRef,
|
|
48
53
|
...rest
|
|
49
|
-
}) => {
|
|
54
|
+
}, ref) => {
|
|
50
55
|
const [internalValue, setInternalValue] = (0, _react.useState)(defaultValue || "");
|
|
51
56
|
const isControlled = externalValue !== undefined;
|
|
52
57
|
const separator = rawSeparator.substring(0, 1); // Ensure max length is 1
|
|
53
58
|
|
|
54
59
|
const maxRawLength = groups.reduce(_groupedCharacter.toSum);
|
|
55
60
|
|
|
61
|
+
if (!deprecateInputRefWarnTriggered && inputRef) {
|
|
62
|
+
deprecateInputRefWarnTriggered = true;
|
|
63
|
+
|
|
64
|
+
_logger.default.deprecate("The `inputRef` prop in `GroupedCharacter` component is deprecated and will soon be removed. Please use `ref` instead.");
|
|
65
|
+
}
|
|
66
|
+
|
|
56
67
|
const formatValue = val => (0, _groupedCharacter.generateGroups)(groups, val).join(separator);
|
|
57
68
|
|
|
58
69
|
const sanitizeValue = val => val.split(separator).join("").substring(0, maxRawLength);
|
|
@@ -131,9 +142,11 @@ const GroupedCharacter = ({
|
|
|
131
142
|
formattedValue: formatValue(value),
|
|
132
143
|
onChange: handleChange,
|
|
133
144
|
onBlur: handleBlur,
|
|
134
|
-
onKeyPress: handleKeyPress
|
|
145
|
+
onKeyPress: handleKeyPress,
|
|
146
|
+
inputRef: inputRef,
|
|
147
|
+
ref: ref
|
|
135
148
|
}));
|
|
136
|
-
};
|
|
149
|
+
});
|
|
137
150
|
|
|
138
151
|
exports.GroupedCharacter = GroupedCharacter;
|
|
139
152
|
GroupedCharacter.propTypes = {
|
|
@@ -671,5 +684,6 @@ GroupedCharacter.propTypes = {
|
|
|
671
684
|
"warnOverLimit": _propTypes.default.bool,
|
|
672
685
|
"width": _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string])
|
|
673
686
|
};
|
|
687
|
+
GroupedCharacter.displayName = "GroupedCharacter";
|
|
674
688
|
var _default = GroupedCharacter;
|
|
675
689
|
exports.default = _default;
|
|
@@ -129,7 +129,7 @@ const MenuItem = ({
|
|
|
129
129
|
ref
|
|
130
130
|
};
|
|
131
131
|
const clonedChildren = isChildSearch.current ? childrenItems.map(child => /*#__PURE__*/_react.default.cloneElement(child, {
|
|
132
|
-
|
|
132
|
+
ref: childRef
|
|
133
133
|
})) : children;
|
|
134
134
|
|
|
135
135
|
const getTitle = title => maxWidth && typeof title === "string" ? title : "";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import React from "react";
|
|
2
2
|
import { TextboxProps } from "../textbox";
|
|
3
3
|
export interface NumberProps extends Omit<TextboxProps, "value"> {
|
|
4
4
|
/** Value passed to the input */
|
|
5
5
|
value?: string;
|
|
6
6
|
}
|
|
7
|
-
export declare const Number:
|
|
7
|
+
export declare const Number: React.ForwardRefExoticComponent<NumberProps & React.RefAttributes<HTMLInputElement>>;
|
|
8
8
|
export default Number;
|
|
@@ -11,6 +11,8 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
11
11
|
|
|
12
12
|
var _textbox = _interopRequireDefault(require("../textbox"));
|
|
13
13
|
|
|
14
|
+
var _logger = _interopRequireDefault(require("../../__internal__/utils/logger"));
|
|
15
|
+
|
|
14
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
17
|
|
|
16
18
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
@@ -19,21 +21,30 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
|
|
|
19
21
|
|
|
20
22
|
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
21
23
|
|
|
24
|
+
let deprecateInputRefWarnTriggered = false;
|
|
25
|
+
|
|
22
26
|
function isValidNumber(value) {
|
|
23
27
|
const regex = new RegExp("^[-]?[0-9]*$");
|
|
24
28
|
const result = regex.test(value);
|
|
25
29
|
return result;
|
|
26
30
|
}
|
|
27
31
|
|
|
28
|
-
const Number = ({
|
|
32
|
+
const Number = /*#__PURE__*/_react.default.forwardRef(({
|
|
29
33
|
onChange,
|
|
30
34
|
onKeyDown,
|
|
31
35
|
value,
|
|
36
|
+
inputRef,
|
|
32
37
|
...rest
|
|
33
|
-
}) => {
|
|
38
|
+
}, ref) => {
|
|
34
39
|
const selectionStart = (0, _react.useRef)(null);
|
|
35
40
|
const selectionEnd = (0, _react.useRef)(null);
|
|
36
41
|
|
|
42
|
+
if (!deprecateInputRefWarnTriggered && inputRef) {
|
|
43
|
+
deprecateInputRefWarnTriggered = true;
|
|
44
|
+
|
|
45
|
+
_logger.default.deprecate("The `inputRef` prop in `Number` component is deprecated and will soon be removed. Please use `ref` instead.");
|
|
46
|
+
}
|
|
47
|
+
|
|
37
48
|
const handleOnChange = event => {
|
|
38
49
|
if (isValidNumber(event.target.value) && onChange) {
|
|
39
50
|
onChange(event);
|
|
@@ -55,9 +66,11 @@ const Number = ({
|
|
|
55
66
|
return /*#__PURE__*/_react.default.createElement(_textbox.default, _extends({}, rest, {
|
|
56
67
|
value: value,
|
|
57
68
|
onChange: handleOnChange,
|
|
58
|
-
onKeyDown: handleKeyDown
|
|
69
|
+
onKeyDown: handleKeyDown,
|
|
70
|
+
ref: ref,
|
|
71
|
+
inputRef: inputRef
|
|
59
72
|
}));
|
|
60
|
-
};
|
|
73
|
+
});
|
|
61
74
|
|
|
62
75
|
exports.Number = Number;
|
|
63
76
|
Number.propTypes = {
|
|
@@ -593,5 +606,6 @@ Number.propTypes = {
|
|
|
593
606
|
"warnOverLimit": _propTypes.default.bool,
|
|
594
607
|
"width": _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string])
|
|
595
608
|
};
|
|
609
|
+
Number.displayName = "Number";
|
|
596
610
|
var _default = Number;
|
|
597
611
|
exports.default = _default;
|
|
@@ -75,7 +75,19 @@ export interface NumeralDateProps<DateType extends NumeralDateObject = FullDate>
|
|
|
75
75
|
tooltipPosition?: "top" | "bottom" | "left" | "right";
|
|
76
76
|
/** Aria label for rendered help component */
|
|
77
77
|
helpAriaLabel?: string;
|
|
78
|
+
/**
|
|
79
|
+
* A React ref to pass to the input corresponding to the day
|
|
80
|
+
*/
|
|
81
|
+
dayRef?: React.ForwardedRef<HTMLInputElement>;
|
|
82
|
+
/**
|
|
83
|
+
* A React ref to pass to the input corresponding to the month
|
|
84
|
+
*/
|
|
85
|
+
monthRef?: React.ForwardedRef<HTMLInputElement>;
|
|
86
|
+
/**
|
|
87
|
+
* A React ref to pass to the input corresponding to the year
|
|
88
|
+
*/
|
|
89
|
+
yearRef?: React.ForwardedRef<HTMLInputElement>;
|
|
78
90
|
}
|
|
79
91
|
export declare type ValidDateFormat = typeof ALLOWED_DATE_FORMATS[number];
|
|
80
|
-
export declare const NumeralDate: <DateType extends NumeralDateObject = FullDate>({ dateFormat, defaultValue, disabled, error, warning, "data-component": dataComponent, "data-element": dataElement, "data-role": dataRole, info, id, name, onBlur, onChange, value, validationOnLabel, label, labelInline, labelWidth, labelAlign, labelHelp, labelSpacing, fieldHelp, adaptiveLabelBreakpoint, required, readOnly, size, enableInternalError, enableInternalWarning, tooltipPosition, helpAriaLabel, ...rest }: NumeralDateProps<DateType>) => JSX.Element;
|
|
92
|
+
export declare const NumeralDate: <DateType extends NumeralDateObject = FullDate>({ dateFormat, defaultValue, disabled, error, warning, "data-component": dataComponent, "data-element": dataElement, "data-role": dataRole, info, id, name, onBlur, onChange, value, validationOnLabel, label, labelInline, labelWidth, labelAlign, labelHelp, labelSpacing, fieldHelp, adaptiveLabelBreakpoint, required, readOnly, size, enableInternalError, enableInternalWarning, tooltipPosition, helpAriaLabel, dayRef, monthRef, yearRef, ...rest }: NumeralDateProps<DateType>) => JSX.Element;
|
|
81
93
|
export default NumeralDate;
|
|
@@ -92,6 +92,9 @@ const NumeralDate = ({
|
|
|
92
92
|
enableInternalWarning,
|
|
93
93
|
tooltipPosition,
|
|
94
94
|
helpAriaLabel,
|
|
95
|
+
dayRef,
|
|
96
|
+
monthRef,
|
|
97
|
+
yearRef,
|
|
95
98
|
...rest
|
|
96
99
|
}) => {
|
|
97
100
|
const l = (0, _useLocale.default)();
|
|
@@ -103,7 +106,7 @@ const NumeralDate = ({
|
|
|
103
106
|
} = (0, _react.useRef)(id || (0, _guid.default)());
|
|
104
107
|
const isControlled = (0, _react.useRef)(value !== undefined);
|
|
105
108
|
const initialValue = isControlled.current ? value : defaultValue;
|
|
106
|
-
const refs = (0, _react.useRef)(dateFormat.map(() =>
|
|
109
|
+
const refs = (0, _react.useRef)(dateFormat.map(() => null));
|
|
107
110
|
const [internalMessages, setInternalMessages] = (0, _react.useState)({ ...Object.fromEntries(dateFormat.map(datePart => [datePart, ""]))
|
|
108
111
|
});
|
|
109
112
|
const hasCorrectDateFormat = (0, _react.useMemo)(() => {
|
|
@@ -170,7 +173,7 @@ const NumeralDate = ({
|
|
|
170
173
|
}
|
|
171
174
|
|
|
172
175
|
setTimeout(() => {
|
|
173
|
-
const hasBlurred = !refs.current.find(ref => ref
|
|
176
|
+
const hasBlurred = !refs.current.find(ref => ref === document.activeElement);
|
|
174
177
|
/* istanbul ignore else */
|
|
175
178
|
|
|
176
179
|
if (onBlur && hasBlurred) {
|
|
@@ -217,6 +220,27 @@ const NumeralDate = ({
|
|
|
217
220
|
const validation = error || warning || info;
|
|
218
221
|
const isStringValidation = typeof validation === "string";
|
|
219
222
|
const hasValidationIcon = isStringValidation && !!validation.length;
|
|
223
|
+
let inputRef;
|
|
224
|
+
|
|
225
|
+
switch (datePart.slice(0, 2)) {
|
|
226
|
+
case "dd":
|
|
227
|
+
inputRef = dayRef;
|
|
228
|
+
break;
|
|
229
|
+
|
|
230
|
+
case "mm":
|
|
231
|
+
inputRef = monthRef;
|
|
232
|
+
break;
|
|
233
|
+
|
|
234
|
+
case "yy":
|
|
235
|
+
inputRef = yearRef;
|
|
236
|
+
break;
|
|
237
|
+
|
|
238
|
+
/* istanbul ignore next */
|
|
239
|
+
|
|
240
|
+
default:
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
|
|
220
244
|
return /*#__PURE__*/_react.default.createElement(_numeralDateContext.default.Provider, {
|
|
221
245
|
value: {
|
|
222
246
|
disableErrorBorder: index !== 0
|
|
@@ -236,8 +260,18 @@ const NumeralDate = ({
|
|
|
236
260
|
placeholder: datePart,
|
|
237
261
|
value: dateValue[datePart],
|
|
238
262
|
onChange: e => handleChange(e, datePart),
|
|
239
|
-
|
|
240
|
-
refs.current[index] =
|
|
263
|
+
ref: element => {
|
|
264
|
+
refs.current[index] = element;
|
|
265
|
+
|
|
266
|
+
if (!inputRef) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (typeof inputRef === "function") {
|
|
271
|
+
inputRef(element);
|
|
272
|
+
} else {
|
|
273
|
+
inputRef.current = element;
|
|
274
|
+
}
|
|
241
275
|
},
|
|
242
276
|
onBlur: () => handleBlur(datePart),
|
|
243
277
|
error: !!internalError,
|
|
@@ -291,6 +325,9 @@ NumeralDate.propTypes = {
|
|
|
291
325
|
"toString": _propTypes.default.func.isRequired,
|
|
292
326
|
"values": _propTypes.default.func.isRequired
|
|
293
327
|
}),
|
|
328
|
+
"dayRef": _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.shape({
|
|
329
|
+
"current": _propTypes.default.oneOfType([_propTypes.default.oneOf([null]), _propTypes.default.object]).isRequired
|
|
330
|
+
})]),
|
|
294
331
|
"defaultValue": _propTypes.default.shape({
|
|
295
332
|
"dd": _propTypes.default.string.isRequired,
|
|
296
333
|
"mm": _propTypes.default.string.isRequired
|
|
@@ -419,6 +456,9 @@ NumeralDate.propTypes = {
|
|
|
419
456
|
"toString": _propTypes.default.func.isRequired,
|
|
420
457
|
"valueOf": _propTypes.default.func.isRequired
|
|
421
458
|
}), _propTypes.default.string]),
|
|
459
|
+
"monthRef": _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.shape({
|
|
460
|
+
"current": _propTypes.default.oneOfType([_propTypes.default.oneOf([null]), _propTypes.default.object]).isRequired
|
|
461
|
+
})]),
|
|
422
462
|
"mr": _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.oneOf([null]), _propTypes.default.number, _propTypes.default.shape({
|
|
423
463
|
"__@toStringTag": _propTypes.default.string.isRequired,
|
|
424
464
|
"description": _propTypes.default.string,
|
|
@@ -475,7 +515,10 @@ NumeralDate.propTypes = {
|
|
|
475
515
|
"dd": _propTypes.default.string.isRequired,
|
|
476
516
|
"mm": _propTypes.default.string.isRequired
|
|
477
517
|
}),
|
|
478
|
-
"warning": _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.bool])
|
|
518
|
+
"warning": _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.bool]),
|
|
519
|
+
"yearRef": _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.shape({
|
|
520
|
+
"current": _propTypes.default.oneOfType([_propTypes.default.oneOf([null]), _propTypes.default.object]).isRequired
|
|
521
|
+
})])
|
|
479
522
|
};
|
|
480
523
|
var _default = NumeralDate;
|
|
481
524
|
exports.default = _default;
|
|
@@ -22,6 +22,8 @@ export interface RadioButtonProps extends CommonCheckableInputProps, MarginProps
|
|
|
22
22
|
tooltipPosition?: "top" | "bottom" | "left" | "right";
|
|
23
23
|
/** Aria label for rendered help component */
|
|
24
24
|
helpAriaLabel?: string;
|
|
25
|
+
/** A callback to retrieve the input reference (deprecated) */
|
|
26
|
+
inputRef?: React.Ref<HTMLInputElement>;
|
|
25
27
|
}
|
|
26
28
|
export declare const RadioButton: React.ForwardRefExoticComponent<RadioButtonProps & InternalRadioButtonProps & React.RefAttributes<HTMLInputElement>>;
|
|
27
29
|
declare const _default: React.MemoExoticComponent<React.ForwardRefExoticComponent<RadioButtonProps & InternalRadioButtonProps & React.RefAttributes<HTMLInputElement>>>;
|