carbon-react 114.7.1 → 114.8.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/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/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
|
@@ -46,5 +46,5 @@ export interface CheckableInputProps extends CommonCheckableInputProps {
|
|
|
46
46
|
/** When true label is inline */
|
|
47
47
|
labelInline?: boolean;
|
|
48
48
|
}
|
|
49
|
-
declare const CheckableInput:
|
|
49
|
+
declare const CheckableInput: React.ForwardRefExoticComponent<CheckableInputProps & React.RefAttributes<HTMLInputElement>>;
|
|
50
50
|
export default CheckableInput;
|
|
@@ -6,8 +6,7 @@ import FormField from "../form-field";
|
|
|
6
6
|
import HiddenCheckableInput from "./hidden-checkable-input.component";
|
|
7
7
|
import guid from "../utils/helpers/guid";
|
|
8
8
|
import useInputAccessibility from "../../hooks/__internal__/useInputAccessibility";
|
|
9
|
-
|
|
10
|
-
const CheckableInput = ({
|
|
9
|
+
const CheckableInput = /*#__PURE__*/React.forwardRef(({
|
|
11
10
|
ariaLabelledBy: externalAriaLabelledBy,
|
|
12
11
|
autoFocus,
|
|
13
12
|
checked,
|
|
@@ -18,7 +17,6 @@ const CheckableInput = ({
|
|
|
18
17
|
fieldHelpInline,
|
|
19
18
|
info,
|
|
20
19
|
id: inputId,
|
|
21
|
-
inputRef,
|
|
22
20
|
type,
|
|
23
21
|
value,
|
|
24
22
|
inputWidth,
|
|
@@ -37,7 +35,7 @@ const CheckableInput = ({
|
|
|
37
35
|
validationOnLabel,
|
|
38
36
|
warning,
|
|
39
37
|
...props
|
|
40
|
-
}) => {
|
|
38
|
+
}, ref) => {
|
|
41
39
|
const {
|
|
42
40
|
current: id
|
|
43
41
|
} = useRef(inputId || guid());
|
|
@@ -88,7 +86,6 @@ const CheckableInput = ({
|
|
|
88
86
|
checked,
|
|
89
87
|
disabled,
|
|
90
88
|
id,
|
|
91
|
-
inputRef,
|
|
92
89
|
type,
|
|
93
90
|
value,
|
|
94
91
|
name,
|
|
@@ -96,6 +93,7 @@ const CheckableInput = ({
|
|
|
96
93
|
onChange,
|
|
97
94
|
onFocus,
|
|
98
95
|
required,
|
|
96
|
+
ref,
|
|
99
97
|
...props
|
|
100
98
|
};
|
|
101
99
|
return /*#__PURE__*/React.createElement(StyledCheckableInputWrapper, {
|
|
@@ -106,8 +104,7 @@ const CheckableInput = ({
|
|
|
106
104
|
labelInline: labelInline,
|
|
107
105
|
reverse: reverse
|
|
108
106
|
}, /*#__PURE__*/React.createElement(InputBehaviour, null, /*#__PURE__*/React.createElement(FormField, formFieldProps, /*#__PURE__*/React.createElement(StyledCheckableInput, null, /*#__PURE__*/React.createElement(HiddenCheckableInput, inputProps), children))));
|
|
109
|
-
};
|
|
110
|
-
|
|
107
|
+
});
|
|
111
108
|
CheckableInput.propTypes = {
|
|
112
109
|
"about": PropTypes.string,
|
|
113
110
|
"accept": PropTypes.string,
|
|
@@ -203,9 +200,6 @@ CheckableInput.propTypes = {
|
|
|
203
200
|
"info": PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
|
|
204
201
|
"inlist": PropTypes.any,
|
|
205
202
|
"inputMode": PropTypes.oneOf(["decimal", "email", "none", "numeric", "search", "tel", "text", "url"]),
|
|
206
|
-
"inputRef": PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
|
|
207
|
-
"current": PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.object]).isRequired
|
|
208
|
-
})]),
|
|
209
203
|
"inputWidth": PropTypes.number,
|
|
210
204
|
"is": PropTypes.string,
|
|
211
205
|
"itemID": PropTypes.string,
|
|
@@ -469,4 +463,5 @@ CheckableInput.propTypes = {
|
|
|
469
463
|
"warning": PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
|
|
470
464
|
"width": PropTypes.oneOfType([PropTypes.number, PropTypes.string])
|
|
471
465
|
};
|
|
466
|
+
CheckableInput.displayName = "CheckableInput";
|
|
472
467
|
export default CheckableInput;
|
|
@@ -18,8 +18,6 @@ export interface CommonHiddenCheckableInputProps extends Omit<React.InputHTMLAtt
|
|
|
18
18
|
onMouseEnter?: (ev: React.MouseEvent<HTMLInputElement>) => void;
|
|
19
19
|
/** Value of the input */
|
|
20
20
|
value?: string;
|
|
21
|
-
/** A callback to retrieve the input reference */
|
|
22
|
-
inputRef?: React.Ref<HTMLInputElement>;
|
|
23
21
|
}
|
|
24
22
|
export interface HiddenCheckableInputProps extends CommonHiddenCheckableInputProps {
|
|
25
23
|
/** HTML type attribute of the input */
|
|
@@ -27,5 +25,5 @@ export interface HiddenCheckableInputProps extends CommonHiddenCheckableInputPro
|
|
|
27
25
|
/** Role attribute of the input */
|
|
28
26
|
role?: string;
|
|
29
27
|
}
|
|
30
|
-
declare const _default: React.MemoExoticComponent<
|
|
28
|
+
declare const _default: React.MemoExoticComponent<React.ForwardRefExoticComponent<HiddenCheckableInputProps & React.RefAttributes<HTMLInputElement>>>;
|
|
31
29
|
export default _default;
|
|
@@ -4,18 +4,16 @@ import React, { useContext } from "react";
|
|
|
4
4
|
import PropTypes from "prop-types";
|
|
5
5
|
import HiddenCheckableInputStyle from "./hidden-checkable-input.style";
|
|
6
6
|
import { InputContext, InputGroupContext } from "../input-behaviour";
|
|
7
|
-
|
|
8
|
-
const HiddenCheckableInput = ({
|
|
7
|
+
const HiddenCheckableInput = /*#__PURE__*/React.forwardRef(({
|
|
9
8
|
name,
|
|
10
9
|
checked,
|
|
11
10
|
type,
|
|
12
11
|
value,
|
|
13
|
-
inputRef,
|
|
14
12
|
onChange,
|
|
15
13
|
autoFocus,
|
|
16
14
|
role,
|
|
17
15
|
...props
|
|
18
|
-
}) => {
|
|
16
|
+
}, ref) => {
|
|
19
17
|
const {
|
|
20
18
|
onBlur,
|
|
21
19
|
onFocus,
|
|
@@ -70,10 +68,9 @@ const HiddenCheckableInput = ({
|
|
|
70
68
|
onMouseEnter: handleMouseEnter,
|
|
71
69
|
onMouseLeave: handleMouseLeave,
|
|
72
70
|
onChange: onChange,
|
|
73
|
-
ref:
|
|
71
|
+
ref: ref
|
|
74
72
|
}));
|
|
75
|
-
};
|
|
76
|
-
|
|
73
|
+
});
|
|
77
74
|
HiddenCheckableInput.propTypes = {
|
|
78
75
|
"about": PropTypes.string,
|
|
79
76
|
"accept": PropTypes.string,
|
|
@@ -164,9 +161,6 @@ HiddenCheckableInput.propTypes = {
|
|
|
164
161
|
"id": PropTypes.string,
|
|
165
162
|
"inlist": PropTypes.any,
|
|
166
163
|
"inputMode": PropTypes.oneOf(["decimal", "email", "none", "numeric", "search", "tel", "text", "url"]),
|
|
167
|
-
"inputRef": PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
|
|
168
|
-
"current": PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.object]).isRequired
|
|
169
|
-
})]),
|
|
170
164
|
"is": PropTypes.string,
|
|
171
165
|
"itemID": PropTypes.string,
|
|
172
166
|
"itemProp": PropTypes.string,
|
|
@@ -369,4 +363,5 @@ HiddenCheckableInput.propTypes = {
|
|
|
369
363
|
"vocab": PropTypes.string,
|
|
370
364
|
"width": PropTypes.oneOfType([PropTypes.number, PropTypes.string])
|
|
371
365
|
};
|
|
366
|
+
HiddenCheckableInput.displayName = "HiddenCheckableInput";
|
|
372
367
|
export default /*#__PURE__*/React.memo(HiddenCheckableInput);
|
|
@@ -10,7 +10,7 @@ export interface CommonInputProps extends Omit<React.InputHTMLAttributes<HTMLInp
|
|
|
10
10
|
/** HTML id attribute of the input */
|
|
11
11
|
id?: string;
|
|
12
12
|
/** A callback to retrieve the input reference */
|
|
13
|
-
inputRef?: (input: React.RefObject<HTMLInputElement>) => void;
|
|
13
|
+
inputRef?: (input: React.RefObject<HTMLInputElement | HTMLTextAreaElement>) => void;
|
|
14
14
|
/** Name of the input */
|
|
15
15
|
name?: string;
|
|
16
16
|
/** Specify a callback triggered on blur */
|
|
@@ -42,5 +42,5 @@ export interface InputProps extends CommonInputProps {
|
|
|
42
42
|
/** HTML type attribute of the input */
|
|
43
43
|
type?: string;
|
|
44
44
|
}
|
|
45
|
-
declare const Input: React.ForwardRefExoticComponent<InputProps & React.RefAttributes<HTMLInputElement>>;
|
|
45
|
+
declare const Input: React.ForwardRefExoticComponent<InputProps & React.RefAttributes<HTMLInputElement | HTMLTextAreaElement>>;
|
|
46
46
|
export default Input;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
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); }
|
|
2
2
|
|
|
3
|
-
import React, { useEffect, useContext, useRef } from "react";
|
|
3
|
+
import React, { useEffect, useContext, useRef, useCallback } from "react";
|
|
4
4
|
import PropTypes from "prop-types";
|
|
5
5
|
import StyledInput from "./input.style";
|
|
6
6
|
import { InputContext, InputGroupContext } from "../input-behaviour";
|
|
@@ -33,6 +33,7 @@ const Input = /*#__PURE__*/React.forwardRef(({
|
|
|
33
33
|
disabled,
|
|
34
34
|
readOnly,
|
|
35
35
|
autoFocus,
|
|
36
|
+
// TODO: remove inputRef prop from this component (and props interface) when it has been removed from all exposed input components
|
|
36
37
|
inputRef,
|
|
37
38
|
onClick,
|
|
38
39
|
onChangeDeferred,
|
|
@@ -50,15 +51,21 @@ const Input = /*#__PURE__*/React.forwardRef(({
|
|
|
50
51
|
const deferredTimeout = useRef(null);
|
|
51
52
|
let input = useRef(null);
|
|
52
53
|
|
|
53
|
-
if (ref) {
|
|
54
|
+
if (ref && "current" in ref) {
|
|
54
55
|
input = ref;
|
|
55
56
|
}
|
|
56
57
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
const callbackRef = useCallback(element => {
|
|
59
|
+
input.current = element;
|
|
60
|
+
|
|
61
|
+
if (typeof ref === "function") {
|
|
62
|
+
ref(element);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (autoFocus && element) {
|
|
66
|
+
element.focus();
|
|
60
67
|
}
|
|
61
|
-
}, [autoFocus,
|
|
68
|
+
}, [autoFocus, ref]);
|
|
62
69
|
useEffect(() => {
|
|
63
70
|
if (inputRef) {
|
|
64
71
|
inputRef(input);
|
|
@@ -146,7 +153,7 @@ const Input = /*#__PURE__*/React.forwardRef(({
|
|
|
146
153
|
name: name,
|
|
147
154
|
type: type,
|
|
148
155
|
id: id || name,
|
|
149
|
-
ref:
|
|
156
|
+
ref: callbackRef,
|
|
150
157
|
"data-element": "input",
|
|
151
158
|
onFocus: handleFocus,
|
|
152
159
|
onBlur: handleBlur,
|
|
@@ -22,9 +22,8 @@ export interface CheckboxProps extends CommonCheckableInputProps, MarginProps {
|
|
|
22
22
|
tooltipPosition?: "top" | "bottom" | "left" | "right";
|
|
23
23
|
/** The value of the checkbox, passed on form submit */
|
|
24
24
|
value?: string;
|
|
25
|
+
/** A callback to retrieve the input reference (deprecated) */
|
|
26
|
+
inputRef?: React.Ref<HTMLInputElement>;
|
|
25
27
|
}
|
|
26
|
-
export declare const Checkbox:
|
|
27
|
-
({ id, label, onChange, name, onClick, onBlur, onFocus, value, fieldHelp, autoFocus, labelHelp, labelSpacing, labelWidth, adaptiveSpacingBreakpoint, required, error, warning, info, fieldHelpInline, reverse, checked, disabled, inputWidth, size, tooltipPosition, "data-component": dataComponent, "data-element": dataElement, "data-role": dataRole, helpAriaLabel, ...props }: CheckboxProps): JSX.Element;
|
|
28
|
-
displayName: string;
|
|
29
|
-
};
|
|
28
|
+
export declare const Checkbox: React.ForwardRefExoticComponent<CheckboxProps & React.RefAttributes<HTMLInputElement>>;
|
|
30
29
|
export default Checkbox;
|
|
@@ -9,8 +9,9 @@ import useIsAboveBreakpoint from "../../hooks/__internal__/useIsAboveBreakpoint"
|
|
|
9
9
|
import { filterStyledSystemMarginProps } from "../../style/utils";
|
|
10
10
|
import { TooltipProvider } from "../../__internal__/tooltip-provider";
|
|
11
11
|
import { CheckboxGroupContext } from "./checkbox-group.component";
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
import Logger from "../../__internal__/utils/logger";
|
|
13
|
+
let deprecateInputRefWarnTriggered = false;
|
|
14
|
+
const Checkbox = /*#__PURE__*/React.forwardRef(({
|
|
14
15
|
id,
|
|
15
16
|
label,
|
|
16
17
|
onChange,
|
|
@@ -42,8 +43,9 @@ const Checkbox = ({
|
|
|
42
43
|
"data-element": dataElement,
|
|
43
44
|
"data-role": dataRole,
|
|
44
45
|
helpAriaLabel,
|
|
46
|
+
inputRef,
|
|
45
47
|
...props
|
|
46
|
-
}) => {
|
|
48
|
+
}, ref) => {
|
|
47
49
|
const largeScreen = useIsAboveBreakpoint(adaptiveSpacingBreakpoint);
|
|
48
50
|
const adaptiveSpacingSmallScreen = !!(adaptiveSpacingBreakpoint && !largeScreen);
|
|
49
51
|
const {
|
|
@@ -51,6 +53,12 @@ const Checkbox = ({
|
|
|
51
53
|
warning: contextWarning,
|
|
52
54
|
info: contextInfo
|
|
53
55
|
} = useContext(CheckboxGroupContext);
|
|
56
|
+
|
|
57
|
+
if (!deprecateInputRefWarnTriggered && inputRef) {
|
|
58
|
+
deprecateInputRefWarnTriggered = true;
|
|
59
|
+
Logger.deprecate("The `inputRef` prop in `Checkbox` component is deprecated and will soon be removed. Please use `ref` instead.");
|
|
60
|
+
}
|
|
61
|
+
|
|
54
62
|
const inputProps = {
|
|
55
63
|
onClick,
|
|
56
64
|
onChange,
|
|
@@ -77,6 +85,7 @@ const Checkbox = ({
|
|
|
77
85
|
inputWidth,
|
|
78
86
|
labelWidth,
|
|
79
87
|
tooltipPosition,
|
|
88
|
+
ref: ref || inputRef,
|
|
80
89
|
...props
|
|
81
90
|
};
|
|
82
91
|
return /*#__PURE__*/React.createElement(TooltipProvider, {
|
|
@@ -97,8 +106,7 @@ const Checkbox = ({
|
|
|
97
106
|
reverse: reverse,
|
|
98
107
|
size: size
|
|
99
108
|
}, filterStyledSystemMarginProps(props)), /*#__PURE__*/React.createElement(CheckableInput, inputProps, /*#__PURE__*/React.createElement(CheckboxSvg, null))));
|
|
100
|
-
};
|
|
101
|
-
|
|
109
|
+
});
|
|
102
110
|
Checkbox.propTypes = {
|
|
103
111
|
"about": PropTypes.string,
|
|
104
112
|
"accept": PropTypes.string,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
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); }
|
|
2
2
|
|
|
3
|
-
import React, { useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import React, { useContext, useEffect, useMemo, useRef, useState, useCallback } from "react";
|
|
4
4
|
import PropTypes from "prop-types";
|
|
5
5
|
import styledSystemPropTypes from "@styled-system/prop-types";
|
|
6
6
|
import { additionalYears, findMatchedFormatAndValue, formattedValue, formatToISO, isDateValid, parseDate, parseISODate, checkISOFormatAndLength, getSeparator } from "./__internal__/utils";
|
|
@@ -13,9 +13,10 @@ import Textbox from "../textbox";
|
|
|
13
13
|
import DatePicker from "./__internal__/date-picker";
|
|
14
14
|
import DateRangeContext from "../date-range/date-range.context";
|
|
15
15
|
import useClickAwayListener from "../../hooks/__internal__/useClickAwayListener";
|
|
16
|
+
import Logger from "../../__internal__/utils/logger";
|
|
16
17
|
const marginPropTypes = filterStyledSystemMarginProps(styledSystemPropTypes.space);
|
|
17
|
-
|
|
18
|
-
const DateInput = ({
|
|
18
|
+
let deprecateInputRefWarnTriggered = false;
|
|
19
|
+
const DateInput = /*#__PURE__*/React.forwardRef(({
|
|
19
20
|
adaptiveLabelBreakpoint,
|
|
20
21
|
allowEmptyValue,
|
|
21
22
|
autoFocus,
|
|
@@ -38,11 +39,12 @@ const DateInput = ({
|
|
|
38
39
|
size = "medium",
|
|
39
40
|
tooltipPosition,
|
|
40
41
|
value,
|
|
42
|
+
inputRef,
|
|
41
43
|
...rest
|
|
42
|
-
}) => {
|
|
44
|
+
}, ref) => {
|
|
43
45
|
const wrapperRef = useRef();
|
|
44
46
|
const parentRef = useRef();
|
|
45
|
-
const
|
|
47
|
+
const internalInputRef = useRef();
|
|
46
48
|
const alreadyFocused = useRef(false);
|
|
47
49
|
const isBlurBlocked = useRef(false);
|
|
48
50
|
const focusedViaPicker = useRef(false);
|
|
@@ -63,6 +65,11 @@ const DateInput = ({
|
|
|
63
65
|
const [selectedDays, setSelectedDays] = useState(checkISOFormatAndLength(value) ? parseISODate(value) : parseDate(format, value));
|
|
64
66
|
const isInitialValue = useRef(true);
|
|
65
67
|
|
|
68
|
+
if (!deprecateInputRefWarnTriggered && inputRef) {
|
|
69
|
+
deprecateInputRefWarnTriggered = true;
|
|
70
|
+
Logger.deprecate("The `inputRef` prop in `DateInput` component is deprecated and will soon be removed. Please use `ref` instead.");
|
|
71
|
+
}
|
|
72
|
+
|
|
66
73
|
const computeInvalidRawValue = inputValue => allowEmptyValue && !inputValue.length ? inputValue : null;
|
|
67
74
|
|
|
68
75
|
const buildCustomEvent = ev => {
|
|
@@ -90,9 +97,9 @@ const DateInput = ({
|
|
|
90
97
|
const handleClickAway = () => {
|
|
91
98
|
if (open) {
|
|
92
99
|
alreadyFocused.current = true;
|
|
93
|
-
|
|
100
|
+
internalInputRef.current.focus();
|
|
94
101
|
isBlurBlocked.current = false;
|
|
95
|
-
|
|
102
|
+
internalInputRef.current.blur();
|
|
96
103
|
setOpen(false);
|
|
97
104
|
alreadyFocused.current = false;
|
|
98
105
|
}
|
|
@@ -106,10 +113,10 @@ const DateInput = ({
|
|
|
106
113
|
};
|
|
107
114
|
|
|
108
115
|
const focusInput = () => {
|
|
109
|
-
var
|
|
116
|
+
var _internalInputRef$cur;
|
|
110
117
|
|
|
111
118
|
focusedViaPicker.current = true;
|
|
112
|
-
(
|
|
119
|
+
(_internalInputRef$cur = internalInputRef.current) === null || _internalInputRef$cur === void 0 ? void 0 : _internalInputRef$cur.focus();
|
|
113
120
|
};
|
|
114
121
|
|
|
115
122
|
const handleDayClick = (day, ev) => {
|
|
@@ -234,11 +241,19 @@ const DateInput = ({
|
|
|
234
241
|
handleClickInside(ev);
|
|
235
242
|
};
|
|
236
243
|
|
|
237
|
-
const assignInput =
|
|
244
|
+
const assignInput = useCallback(inputElement => {
|
|
238
245
|
var _inputRefMap$inputNam;
|
|
239
246
|
|
|
240
|
-
|
|
241
|
-
parentRef.current =
|
|
247
|
+
internalInputRef.current = inputElement;
|
|
248
|
+
parentRef.current = inputElement === null || inputElement === void 0 ? void 0 : inputElement.parentElement;
|
|
249
|
+
|
|
250
|
+
if (ref) {
|
|
251
|
+
if (typeof ref === "function") {
|
|
252
|
+
ref(inputElement);
|
|
253
|
+
} else {
|
|
254
|
+
ref.current = inputElement;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
242
257
|
|
|
243
258
|
if (inputRefMap && ((_inputRefMap$inputNam = inputRefMap[inputName]) === null || _inputRefMap$inputNam === void 0 ? void 0 : _inputRefMap$inputNam.setOpen) !== setOpen) {
|
|
244
259
|
setInputRefMap({
|
|
@@ -248,8 +263,7 @@ const DateInput = ({
|
|
|
248
263
|
}
|
|
249
264
|
});
|
|
250
265
|
}
|
|
251
|
-
};
|
|
252
|
-
|
|
266
|
+
}, [inputName, inputRefMap, setInputRefMap, ref]);
|
|
253
267
|
useEffect(() => {
|
|
254
268
|
const [matchedFormat, matchedValue] = findMatchedFormatAndValue(value, formats);
|
|
255
269
|
|
|
@@ -292,6 +306,7 @@ const DateInput = ({
|
|
|
292
306
|
}, filterStyledSystemMarginProps(rest), {
|
|
293
307
|
applyDateRangeStyling: !!inputRefMap
|
|
294
308
|
}), /*#__PURE__*/React.createElement(Textbox, _extends({}, filterOutStyledSystemSpacingProps(rest), {
|
|
309
|
+
inputRef: inputRef,
|
|
295
310
|
value: computedValue(),
|
|
296
311
|
onBlur: handleBlur,
|
|
297
312
|
onChange: handleChange,
|
|
@@ -303,7 +318,7 @@ const DateInput = ({
|
|
|
303
318
|
iconOnMouseDown: handleIconMouseDown,
|
|
304
319
|
inputIcon: "calendar",
|
|
305
320
|
labelInline: labelInline,
|
|
306
|
-
|
|
321
|
+
ref: assignInput,
|
|
307
322
|
adaptiveLabelBreakpoint: adaptiveLabelBreakpoint,
|
|
308
323
|
tooltipPosition: tooltipPosition,
|
|
309
324
|
helpAriaLabel: helpAriaLabel,
|
|
@@ -323,8 +338,7 @@ const DateInput = ({
|
|
|
323
338
|
pickerMouseDown: handlePickerMouseDown,
|
|
324
339
|
open: open
|
|
325
340
|
}));
|
|
326
|
-
};
|
|
327
|
-
|
|
341
|
+
});
|
|
328
342
|
DateInput.propTypes = { ...Textbox.propTypes,
|
|
329
343
|
...marginPropTypes,
|
|
330
344
|
|
|
@@ -351,4 +365,5 @@ DateInput.propTypes = { ...Textbox.propTypes,
|
|
|
351
365
|
/** Boolean to allow the input to have an empty value */
|
|
352
366
|
allowEmptyValue: PropTypes.bool
|
|
353
367
|
};
|
|
368
|
+
DateInput.displayName = "DateInput";
|
|
354
369
|
export default DateInput;
|
|
@@ -26,6 +26,8 @@ const DateRange = ({
|
|
|
26
26
|
tooltipPosition,
|
|
27
27
|
validationOnLabel,
|
|
28
28
|
value,
|
|
29
|
+
startRef,
|
|
30
|
+
endRef,
|
|
29
31
|
...rest
|
|
30
32
|
}) => {
|
|
31
33
|
const l = useLocale();
|
|
@@ -220,13 +222,15 @@ const DateRange = ({
|
|
|
220
222
|
"data-element": "start-date",
|
|
221
223
|
labelWidth: inlineLabelWidth // Textbox only applies this when labelsInLine prop is true
|
|
222
224
|
,
|
|
223
|
-
tooltipPosition: tooltipPosition
|
|
225
|
+
tooltipPosition: tooltipPosition,
|
|
226
|
+
ref: startRef
|
|
224
227
|
})), /*#__PURE__*/React.createElement(DateInput, _extends({}, dateProps("end"), {
|
|
225
228
|
onFocus: () => handleFocus("start"),
|
|
226
229
|
"data-element": "end-date",
|
|
227
230
|
labelWidth: inlineLabelWidth // Textbox only applies this when labelsInLine prop is true
|
|
228
231
|
,
|
|
229
|
-
tooltipPosition: tooltipPosition
|
|
232
|
+
tooltipPosition: tooltipPosition,
|
|
233
|
+
ref: endRef
|
|
230
234
|
}))));
|
|
231
235
|
};
|
|
232
236
|
|
|
@@ -268,6 +272,13 @@ DateRange.propTypes = {
|
|
|
268
272
|
Pass true boolean to only display blue border */
|
|
269
273
|
startInfo: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
|
|
270
274
|
|
|
275
|
+
/**
|
|
276
|
+
* A React ref to pass to the first of the two Date Input fields
|
|
277
|
+
*/
|
|
278
|
+
startRef: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
|
|
279
|
+
current: PropTypes.instanceOf(HTMLInputElement)
|
|
280
|
+
})]),
|
|
281
|
+
|
|
271
282
|
/** Indicate that error has occurred on end date
|
|
272
283
|
Pass string to display icon, tooltip and red border
|
|
273
284
|
Pass true boolean to only display red border */
|
|
@@ -283,6 +294,13 @@ DateRange.propTypes = {
|
|
|
283
294
|
Pass true boolean to only display blue border */
|
|
284
295
|
endInfo: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
|
|
285
296
|
|
|
297
|
+
/**
|
|
298
|
+
* A React ref to pass to the second of the two Date Input fields
|
|
299
|
+
*/
|
|
300
|
+
endRef: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
|
|
301
|
+
current: PropTypes.instanceOf(HTMLInputElement)
|
|
302
|
+
})]),
|
|
303
|
+
|
|
286
304
|
/** When true, validation icons will be placed on labels instead of being placed on the inputs */
|
|
287
305
|
validationOnLabel: PropTypes.bool,
|
|
288
306
|
|
|
@@ -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;
|
|
@@ -6,8 +6,9 @@ import invariant from "invariant";
|
|
|
6
6
|
import Textbox from "../textbox";
|
|
7
7
|
import LocaleContext from "../../__internal__/i18n-context";
|
|
8
8
|
import usePrevious from "../../hooks/__internal__/usePrevious";
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
import Logger from "../../__internal__/utils/logger";
|
|
10
|
+
let deprecateInputRefWarnTriggered = false;
|
|
11
|
+
const Decimal = /*#__PURE__*/React.forwardRef(({
|
|
11
12
|
align = "right",
|
|
12
13
|
defaultValue,
|
|
13
14
|
precision = 2,
|
|
@@ -22,9 +23,16 @@ const Decimal = ({
|
|
|
22
23
|
required,
|
|
23
24
|
locale,
|
|
24
25
|
value,
|
|
26
|
+
inputRef,
|
|
25
27
|
...rest
|
|
26
|
-
}) => {
|
|
28
|
+
}, ref) => {
|
|
27
29
|
const l = useContext(LocaleContext);
|
|
30
|
+
|
|
31
|
+
if (!deprecateInputRefWarnTriggered && inputRef) {
|
|
32
|
+
deprecateInputRefWarnTriggered = true;
|
|
33
|
+
Logger.deprecate("The `inputRef` prop in `Decimal` component is deprecated and will soon be removed. Please use `ref` instead.");
|
|
34
|
+
}
|
|
35
|
+
|
|
28
36
|
const emptyValue = allowEmptyValue ? "" : "0.00";
|
|
29
37
|
const getSafeValueProp = useCallback(initialValue => {
|
|
30
38
|
// We're intentionally preventing the use of number values to help prevent any unintentional rounding issues
|
|
@@ -54,7 +62,7 @@ const Decimal = ({
|
|
|
54
62
|
return valueToFormat;
|
|
55
63
|
}
|
|
56
64
|
/* Guards against any white-space only strings like " " being
|
|
57
|
-
|
|
65
|
+
mishandled and returned as `NaN` for the value displayed in the textbox */
|
|
58
66
|
|
|
59
67
|
|
|
60
68
|
if (valueToFormat === "" || valueToFormat.match(/\s+/g)) {
|
|
@@ -194,15 +202,16 @@ const Decimal = ({
|
|
|
194
202
|
onBlur: handleOnBlur,
|
|
195
203
|
value: stateValue,
|
|
196
204
|
"data-component": "decimal",
|
|
197
|
-
id: id
|
|
205
|
+
id: id,
|
|
206
|
+
ref: ref,
|
|
207
|
+
inputRef: inputRef
|
|
198
208
|
}, rest)), /*#__PURE__*/React.createElement("input", {
|
|
199
209
|
name: name,
|
|
200
210
|
value: toStandardDecimal(stateValue),
|
|
201
211
|
type: "hidden",
|
|
202
212
|
"data-component": "hidden-input"
|
|
203
213
|
}));
|
|
204
|
-
};
|
|
205
|
-
|
|
214
|
+
});
|
|
206
215
|
Decimal.propTypes = {
|
|
207
216
|
"about": PropTypes.string,
|
|
208
217
|
"accept": PropTypes.string,
|
|
@@ -734,4 +743,5 @@ Decimal.propTypes = {
|
|
|
734
743
|
"width": PropTypes.oneOfType([PropTypes.number, PropTypes.string])
|
|
735
744
|
};
|
|
736
745
|
export { Decimal };
|
|
746
|
+
Decimal.displayName = "Decimal";
|
|
737
747
|
export default Decimal;
|
|
@@ -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;
|
|
@@ -4,6 +4,7 @@ import React, { useState } from "react";
|
|
|
4
4
|
import PropTypes from "prop-types";
|
|
5
5
|
import Textbox from "../textbox";
|
|
6
6
|
import { generateGroups, toSum } from "./grouped-character.utils";
|
|
7
|
+
import Logger from "../../__internal__/utils/logger";
|
|
7
8
|
|
|
8
9
|
const buildCustomTarget = ({
|
|
9
10
|
target
|
|
@@ -22,21 +23,28 @@ const buildCustomTarget = ({
|
|
|
22
23
|
};
|
|
23
24
|
};
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
let deprecateInputRefWarnTriggered = false;
|
|
27
|
+
const GroupedCharacter = /*#__PURE__*/React.forwardRef(({
|
|
26
28
|
defaultValue,
|
|
27
29
|
groups,
|
|
28
30
|
onBlur,
|
|
29
31
|
onChange,
|
|
30
32
|
separator: rawSeparator,
|
|
31
33
|
value: externalValue,
|
|
34
|
+
inputRef,
|
|
32
35
|
...rest
|
|
33
|
-
}) => {
|
|
36
|
+
}, ref) => {
|
|
34
37
|
const [internalValue, setInternalValue] = useState(defaultValue || "");
|
|
35
38
|
const isControlled = externalValue !== undefined;
|
|
36
39
|
const separator = rawSeparator.substring(0, 1); // Ensure max length is 1
|
|
37
40
|
|
|
38
41
|
const maxRawLength = groups.reduce(toSum);
|
|
39
42
|
|
|
43
|
+
if (!deprecateInputRefWarnTriggered && inputRef) {
|
|
44
|
+
deprecateInputRefWarnTriggered = true;
|
|
45
|
+
Logger.deprecate("The `inputRef` prop in `GroupedCharacter` component is deprecated and will soon be removed. Please use `ref` instead.");
|
|
46
|
+
}
|
|
47
|
+
|
|
40
48
|
const formatValue = val => generateGroups(groups, val).join(separator);
|
|
41
49
|
|
|
42
50
|
const sanitizeValue = val => val.split(separator).join("").substring(0, maxRawLength);
|
|
@@ -115,10 +123,11 @@ const GroupedCharacter = ({
|
|
|
115
123
|
formattedValue: formatValue(value),
|
|
116
124
|
onChange: handleChange,
|
|
117
125
|
onBlur: handleBlur,
|
|
118
|
-
onKeyPress: handleKeyPress
|
|
126
|
+
onKeyPress: handleKeyPress,
|
|
127
|
+
inputRef: inputRef,
|
|
128
|
+
ref: ref
|
|
119
129
|
}));
|
|
120
|
-
};
|
|
121
|
-
|
|
130
|
+
});
|
|
122
131
|
GroupedCharacter.propTypes = {
|
|
123
132
|
"about": PropTypes.string,
|
|
124
133
|
"accept": PropTypes.string,
|
|
@@ -655,4 +664,5 @@ GroupedCharacter.propTypes = {
|
|
|
655
664
|
"width": PropTypes.oneOfType([PropTypes.number, PropTypes.string])
|
|
656
665
|
};
|
|
657
666
|
export { GroupedCharacter };
|
|
667
|
+
GroupedCharacter.displayName = "GroupedCharacter";
|
|
658
668
|
export default GroupedCharacter;
|
|
@@ -103,7 +103,7 @@ const MenuItem = ({
|
|
|
103
103
|
ref
|
|
104
104
|
};
|
|
105
105
|
const clonedChildren = isChildSearch.current ? childrenItems.map(child => /*#__PURE__*/React.cloneElement(child, {
|
|
106
|
-
|
|
106
|
+
ref: childRef
|
|
107
107
|
})) : children;
|
|
108
108
|
|
|
109
109
|
const getTitle = title => maxWidth && typeof title === "string" ? title : "";
|