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
|
@@ -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;
|
|
@@ -3,6 +3,8 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
|
|
|
3
3
|
import React, { useRef } from "react";
|
|
4
4
|
import PropTypes from "prop-types";
|
|
5
5
|
import Textbox from "../textbox";
|
|
6
|
+
import Logger from "../../__internal__/utils/logger";
|
|
7
|
+
let deprecateInputRefWarnTriggered = false;
|
|
6
8
|
|
|
7
9
|
function isValidNumber(value) {
|
|
8
10
|
const regex = new RegExp("^[-]?[0-9]*$");
|
|
@@ -10,15 +12,21 @@ function isValidNumber(value) {
|
|
|
10
12
|
return result;
|
|
11
13
|
}
|
|
12
14
|
|
|
13
|
-
const Number = ({
|
|
15
|
+
const Number = /*#__PURE__*/React.forwardRef(({
|
|
14
16
|
onChange,
|
|
15
17
|
onKeyDown,
|
|
16
18
|
value,
|
|
19
|
+
inputRef,
|
|
17
20
|
...rest
|
|
18
|
-
}) => {
|
|
21
|
+
}, ref) => {
|
|
19
22
|
const selectionStart = useRef(null);
|
|
20
23
|
const selectionEnd = useRef(null);
|
|
21
24
|
|
|
25
|
+
if (!deprecateInputRefWarnTriggered && inputRef) {
|
|
26
|
+
deprecateInputRefWarnTriggered = true;
|
|
27
|
+
Logger.deprecate("The `inputRef` prop in `Number` component is deprecated and will soon be removed. Please use `ref` instead.");
|
|
28
|
+
}
|
|
29
|
+
|
|
22
30
|
const handleOnChange = event => {
|
|
23
31
|
if (isValidNumber(event.target.value) && onChange) {
|
|
24
32
|
onChange(event);
|
|
@@ -40,10 +48,11 @@ const Number = ({
|
|
|
40
48
|
return /*#__PURE__*/React.createElement(Textbox, _extends({}, rest, {
|
|
41
49
|
value: value,
|
|
42
50
|
onChange: handleOnChange,
|
|
43
|
-
onKeyDown: handleKeyDown
|
|
51
|
+
onKeyDown: handleKeyDown,
|
|
52
|
+
ref: ref,
|
|
53
|
+
inputRef: inputRef
|
|
44
54
|
}));
|
|
45
|
-
};
|
|
46
|
-
|
|
55
|
+
});
|
|
47
56
|
Number.propTypes = {
|
|
48
57
|
"about": PropTypes.string,
|
|
49
58
|
"accept": PropTypes.string,
|
|
@@ -578,4 +587,5 @@ Number.propTypes = {
|
|
|
578
587
|
"width": PropTypes.oneOfType([PropTypes.number, PropTypes.string])
|
|
579
588
|
};
|
|
580
589
|
export { Number };
|
|
590
|
+
Number.displayName = "Number";
|
|
581
591
|
export default Number;
|
|
@@ -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;
|
|
@@ -62,6 +62,9 @@ const NumeralDate = ({
|
|
|
62
62
|
enableInternalWarning,
|
|
63
63
|
tooltipPosition,
|
|
64
64
|
helpAriaLabel,
|
|
65
|
+
dayRef,
|
|
66
|
+
monthRef,
|
|
67
|
+
yearRef,
|
|
65
68
|
...rest
|
|
66
69
|
}) => {
|
|
67
70
|
const l = useLocale();
|
|
@@ -73,7 +76,7 @@ const NumeralDate = ({
|
|
|
73
76
|
} = useRef(id || guid());
|
|
74
77
|
const isControlled = useRef(value !== undefined);
|
|
75
78
|
const initialValue = isControlled.current ? value : defaultValue;
|
|
76
|
-
const refs = useRef(dateFormat.map(() =>
|
|
79
|
+
const refs = useRef(dateFormat.map(() => null));
|
|
77
80
|
const [internalMessages, setInternalMessages] = useState({ ...Object.fromEntries(dateFormat.map(datePart => [datePart, ""]))
|
|
78
81
|
});
|
|
79
82
|
const hasCorrectDateFormat = useMemo(() => {
|
|
@@ -140,7 +143,7 @@ const NumeralDate = ({
|
|
|
140
143
|
}
|
|
141
144
|
|
|
142
145
|
setTimeout(() => {
|
|
143
|
-
const hasBlurred = !refs.current.find(ref => ref
|
|
146
|
+
const hasBlurred = !refs.current.find(ref => ref === document.activeElement);
|
|
144
147
|
/* istanbul ignore else */
|
|
145
148
|
|
|
146
149
|
if (onBlur && hasBlurred) {
|
|
@@ -187,6 +190,27 @@ const NumeralDate = ({
|
|
|
187
190
|
const validation = error || warning || info;
|
|
188
191
|
const isStringValidation = typeof validation === "string";
|
|
189
192
|
const hasValidationIcon = isStringValidation && !!validation.length;
|
|
193
|
+
let inputRef;
|
|
194
|
+
|
|
195
|
+
switch (datePart.slice(0, 2)) {
|
|
196
|
+
case "dd":
|
|
197
|
+
inputRef = dayRef;
|
|
198
|
+
break;
|
|
199
|
+
|
|
200
|
+
case "mm":
|
|
201
|
+
inputRef = monthRef;
|
|
202
|
+
break;
|
|
203
|
+
|
|
204
|
+
case "yy":
|
|
205
|
+
inputRef = yearRef;
|
|
206
|
+
break;
|
|
207
|
+
|
|
208
|
+
/* istanbul ignore next */
|
|
209
|
+
|
|
210
|
+
default:
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
|
|
190
214
|
return /*#__PURE__*/React.createElement(NumeralDateContext.Provider, {
|
|
191
215
|
value: {
|
|
192
216
|
disableErrorBorder: index !== 0
|
|
@@ -206,8 +230,18 @@ const NumeralDate = ({
|
|
|
206
230
|
placeholder: datePart,
|
|
207
231
|
value: dateValue[datePart],
|
|
208
232
|
onChange: e => handleChange(e, datePart),
|
|
209
|
-
|
|
210
|
-
refs.current[index] =
|
|
233
|
+
ref: element => {
|
|
234
|
+
refs.current[index] = element;
|
|
235
|
+
|
|
236
|
+
if (!inputRef) {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (typeof inputRef === "function") {
|
|
241
|
+
inputRef(element);
|
|
242
|
+
} else {
|
|
243
|
+
inputRef.current = element;
|
|
244
|
+
}
|
|
211
245
|
},
|
|
212
246
|
onBlur: () => handleBlur(datePart),
|
|
213
247
|
error: !!internalError,
|
|
@@ -260,6 +294,9 @@ NumeralDate.propTypes = {
|
|
|
260
294
|
"toString": PropTypes.func.isRequired,
|
|
261
295
|
"values": PropTypes.func.isRequired
|
|
262
296
|
}),
|
|
297
|
+
"dayRef": PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
|
|
298
|
+
"current": PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.object]).isRequired
|
|
299
|
+
})]),
|
|
263
300
|
"defaultValue": PropTypes.shape({
|
|
264
301
|
"dd": PropTypes.string.isRequired,
|
|
265
302
|
"mm": PropTypes.string.isRequired
|
|
@@ -388,6 +425,9 @@ NumeralDate.propTypes = {
|
|
|
388
425
|
"toString": PropTypes.func.isRequired,
|
|
389
426
|
"valueOf": PropTypes.func.isRequired
|
|
390
427
|
}), PropTypes.string]),
|
|
428
|
+
"monthRef": PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
|
|
429
|
+
"current": PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.object]).isRequired
|
|
430
|
+
})]),
|
|
391
431
|
"mr": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.number, PropTypes.shape({
|
|
392
432
|
"__@toStringTag": PropTypes.string.isRequired,
|
|
393
433
|
"description": PropTypes.string,
|
|
@@ -444,7 +484,10 @@ NumeralDate.propTypes = {
|
|
|
444
484
|
"dd": PropTypes.string.isRequired,
|
|
445
485
|
"mm": PropTypes.string.isRequired
|
|
446
486
|
}),
|
|
447
|
-
"warning": PropTypes.oneOfType([PropTypes.string, PropTypes.bool])
|
|
487
|
+
"warning": PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
|
|
488
|
+
"yearRef": PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
|
|
489
|
+
"current": PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.object]).isRequired
|
|
490
|
+
})])
|
|
448
491
|
};
|
|
449
492
|
export { NumeralDate };
|
|
450
493
|
export default NumeralDate;
|
|
@@ -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>>>;
|
|
@@ -8,6 +8,8 @@ import CheckableInput from "../../__internal__/checkable-input/checkable-input.c
|
|
|
8
8
|
import RadioButtonSvg from "./radio-button-svg.component";
|
|
9
9
|
import { filterStyledSystemMarginProps } from "../../style/utils";
|
|
10
10
|
import { TooltipProvider } from "../../__internal__/tooltip-provider";
|
|
11
|
+
import Logger from "../../__internal__/utils/logger";
|
|
12
|
+
let deprecateInputRefWarnTriggered = false;
|
|
11
13
|
const RadioButton = /*#__PURE__*/React.forwardRef(({
|
|
12
14
|
autoFocus,
|
|
13
15
|
checked,
|
|
@@ -38,6 +40,7 @@ const RadioButton = /*#__PURE__*/React.forwardRef(({
|
|
|
38
40
|
"data-element": dataElement,
|
|
39
41
|
"data-role": dataRole,
|
|
40
42
|
helpAriaLabel,
|
|
43
|
+
inputRef,
|
|
41
44
|
...props
|
|
42
45
|
}, ref) => {
|
|
43
46
|
const marginProps = filterStyledSystemMarginProps(props);
|
|
@@ -50,6 +53,12 @@ const RadioButton = /*#__PURE__*/React.forwardRef(({
|
|
|
50
53
|
|
|
51
54
|
event.target.focus();
|
|
52
55
|
}, [onChange]);
|
|
56
|
+
|
|
57
|
+
if (!deprecateInputRefWarnTriggered && inputRef) {
|
|
58
|
+
deprecateInputRefWarnTriggered = true;
|
|
59
|
+
Logger.deprecate("The `inputRef` prop in `RadioButton` component is deprecated and will soon be removed. Please use `ref` instead.");
|
|
60
|
+
}
|
|
61
|
+
|
|
53
62
|
const commonProps = {
|
|
54
63
|
disabled,
|
|
55
64
|
fieldHelpInline,
|
|
@@ -83,7 +92,7 @@ const RadioButton = /*#__PURE__*/React.forwardRef(({
|
|
|
83
92
|
*/
|
|
84
93
|
reverse: !reverse,
|
|
85
94
|
required,
|
|
86
|
-
|
|
95
|
+
ref: ref || inputRef,
|
|
87
96
|
...props
|
|
88
97
|
};
|
|
89
98
|
!!props.children ? process.env.NODE_ENV !== "production" ? invariant(false, "This component is meant to be used as a self-closing tag. " + "You should probably use the label prop instead.") : invariant(false) : void 0;
|
|
@@ -56,5 +56,5 @@ export interface SearchProps extends ValidationProps, MarginProps {
|
|
|
56
56
|
/** Overrides the default tooltip position */
|
|
57
57
|
tooltipPosition?: "top" | "bottom" | "left" | "right";
|
|
58
58
|
}
|
|
59
|
-
export declare const Search:
|
|
59
|
+
export declare const Search: React.ForwardRefExoticComponent<SearchProps & React.RefAttributes<HTMLInputElement>>;
|
|
60
60
|
export default Search;
|
|
@@ -10,8 +10,9 @@ import StyledSearchButton, { StyledButtonIcon } from "./search-button.style";
|
|
|
10
10
|
import Icon from "../icon";
|
|
11
11
|
import Textbox from "../textbox";
|
|
12
12
|
import Button from "../button";
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
import Logger from "../../__internal__/utils/logger";
|
|
14
|
+
let deprecateInputRefWarnTriggered = false;
|
|
15
|
+
const Search = /*#__PURE__*/React.forwardRef(({
|
|
15
16
|
defaultValue,
|
|
16
17
|
onChange,
|
|
17
18
|
onClick,
|
|
@@ -35,9 +36,15 @@ const Search = ({
|
|
|
35
36
|
info,
|
|
36
37
|
tooltipPosition,
|
|
37
38
|
...rest
|
|
38
|
-
}) => {
|
|
39
|
+
}, ref) => {
|
|
39
40
|
const isControlled = value !== undefined;
|
|
40
41
|
const initialValue = isControlled ? value : defaultValue;
|
|
42
|
+
|
|
43
|
+
if (!deprecateInputRefWarnTriggered && inputRef) {
|
|
44
|
+
deprecateInputRefWarnTriggered = true;
|
|
45
|
+
Logger.deprecate("The `inputRef` prop in `Search` component is deprecated and will soon be removed. Please use `ref` instead.");
|
|
46
|
+
}
|
|
47
|
+
|
|
41
48
|
!(typeof initialValue === "string") ? process.env.NODE_ENV !== "production" ? invariant(false, "This component has no initial value") : invariant(false) : void 0;
|
|
42
49
|
!(threshold === undefined || typeof threshold === "number" && threshold > 0) ? process.env.NODE_ENV !== "production" ? invariant(false, "Threshold must be a positive number") : invariant(false) : void 0;
|
|
43
50
|
const [searchValue, setSearchValue] = useState(initialValue);
|
|
@@ -133,12 +140,6 @@ const Search = ({
|
|
|
133
140
|
}
|
|
134
141
|
};
|
|
135
142
|
|
|
136
|
-
const assignInput = input => {
|
|
137
|
-
if (inputRef) {
|
|
138
|
-
inputRef.current = input === null || input === void 0 ? void 0 : input.current;
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
|
|
142
143
|
const isSearchTyped = isFocused || (!isControlled ? !!searchValue.length : !!value.length);
|
|
143
144
|
return /*#__PURE__*/React.createElement(StyledSearch, _extends({
|
|
144
145
|
isFocused: isFocused,
|
|
@@ -164,7 +165,7 @@ const Search = ({
|
|
|
164
165
|
onBlur: handleBlur,
|
|
165
166
|
onChange: handleChange,
|
|
166
167
|
onKeyDown: handleKeyDown,
|
|
167
|
-
|
|
168
|
+
ref: ref || inputRef,
|
|
168
169
|
tabIndex: tabIndex,
|
|
169
170
|
error: error,
|
|
170
171
|
warning: warning,
|
|
@@ -176,8 +177,7 @@ const Search = ({
|
|
|
176
177
|
}, buttonProps), /*#__PURE__*/React.createElement(StyledButtonIcon, null, /*#__PURE__*/React.createElement(Icon, {
|
|
177
178
|
type: "search"
|
|
178
179
|
})))));
|
|
179
|
-
};
|
|
180
|
-
|
|
180
|
+
});
|
|
181
181
|
Search.propTypes = {
|
|
182
182
|
"aria-label": PropTypes.string,
|
|
183
183
|
"defaultValue": PropTypes.string,
|
|
@@ -359,4 +359,5 @@ Search.propTypes = {
|
|
|
359
359
|
"warning": PropTypes.oneOfType([PropTypes.string, PropTypes.bool])
|
|
360
360
|
};
|
|
361
361
|
export { Search };
|
|
362
|
+
Search.displayName = "Search";
|
|
362
363
|
export default Search;
|
|
@@ -11,6 +11,8 @@ import StyledSelect from "../select.style";
|
|
|
11
11
|
import SelectList from "../select-list/select-list.component";
|
|
12
12
|
import isExpectedOption from "../utils/is-expected-option";
|
|
13
13
|
import isNavigationKey from "../utils/is-navigation-key";
|
|
14
|
+
import Logger from "../../../__internal__/utils/logger";
|
|
15
|
+
let deprecateInputRefWarnTriggered = false;
|
|
14
16
|
const FilterableSelectList = withFilter(SelectList);
|
|
15
17
|
const FilterableSelect = /*#__PURE__*/React.forwardRef(({
|
|
16
18
|
value,
|
|
@@ -44,8 +46,9 @@ const FilterableSelect = /*#__PURE__*/React.forwardRef(({
|
|
|
44
46
|
tooltipPosition,
|
|
45
47
|
listPlacement = "bottom",
|
|
46
48
|
flipEnabled = true,
|
|
49
|
+
inputRef,
|
|
47
50
|
...textboxProps
|
|
48
|
-
},
|
|
51
|
+
}, ref) => {
|
|
49
52
|
const [activeDescendantId, setActiveDescendantId] = useState();
|
|
50
53
|
const selectListId = useRef(guid());
|
|
51
54
|
const labelId = useRef(label ? guid() : undefined);
|
|
@@ -61,6 +64,12 @@ const FilterableSelect = /*#__PURE__*/React.forwardRef(({
|
|
|
61
64
|
const [selectedValue, setSelectedValue] = useState(value || defaultValue || "");
|
|
62
65
|
const [highlightedValue, setHighlightedValue] = useState("");
|
|
63
66
|
const [filterText, setFilterText] = useState("");
|
|
67
|
+
|
|
68
|
+
if (!deprecateInputRefWarnTriggered && inputRef) {
|
|
69
|
+
deprecateInputRefWarnTriggered = true;
|
|
70
|
+
Logger.deprecate("The `inputRef` prop in `FilterableSelect` component is deprecated and will soon be removed. Please use `ref` instead.");
|
|
71
|
+
}
|
|
72
|
+
|
|
64
73
|
const createCustomEvent = useCallback(newValue => {
|
|
65
74
|
const customEvent = {
|
|
66
75
|
target: { ...(name && {
|
|
@@ -358,13 +367,19 @@ const FilterableSelect = /*#__PURE__*/React.forwardRef(({
|
|
|
358
367
|
onListAction();
|
|
359
368
|
}
|
|
360
369
|
|
|
361
|
-
|
|
362
|
-
setTextboxRef(
|
|
370
|
+
const assignInput = useCallback(element => {
|
|
371
|
+
setTextboxRef(element);
|
|
372
|
+
|
|
373
|
+
if (inputRef || !ref) {
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
363
376
|
|
|
364
|
-
if (
|
|
365
|
-
|
|
377
|
+
if (typeof ref === "function") {
|
|
378
|
+
ref(element);
|
|
379
|
+
} else {
|
|
380
|
+
ref.current = element;
|
|
366
381
|
}
|
|
367
|
-
}
|
|
382
|
+
}, [ref, inputRef]);
|
|
368
383
|
|
|
369
384
|
function getTextboxProps() {
|
|
370
385
|
return {
|
|
@@ -373,7 +388,7 @@ const FilterableSelect = /*#__PURE__*/React.forwardRef(({
|
|
|
373
388
|
label,
|
|
374
389
|
disabled,
|
|
375
390
|
readOnly,
|
|
376
|
-
|
|
391
|
+
ref: assignInput,
|
|
377
392
|
selectedValue,
|
|
378
393
|
formattedValue: textValue,
|
|
379
394
|
onClick: handleTextboxClick,
|
|
@@ -385,6 +400,7 @@ const FilterableSelect = /*#__PURE__*/React.forwardRef(({
|
|
|
385
400
|
onChange: handleTextboxChange,
|
|
386
401
|
onMouseDown: handleTextboxMouseDown,
|
|
387
402
|
tooltipPosition,
|
|
403
|
+
inputRef,
|
|
388
404
|
...filterOutStyledSystemSpacingProps(textboxProps)
|
|
389
405
|
};
|
|
390
406
|
}
|
|
@@ -13,6 +13,8 @@ import Pill from "../../pill";
|
|
|
13
13
|
import isExpectedOption from "../utils/is-expected-option";
|
|
14
14
|
import isExpectedValue from "../utils/is-expected-value";
|
|
15
15
|
import isNavigationKey from "../utils/is-navigation-key";
|
|
16
|
+
import Logger from "../../../__internal__/utils/logger";
|
|
17
|
+
let deprecateInputRefWarnTriggered = false;
|
|
16
18
|
const FilterableSelectList = withFilter(SelectList);
|
|
17
19
|
const MultiSelect = /*#__PURE__*/React.forwardRef(({
|
|
18
20
|
value,
|
|
@@ -45,8 +47,9 @@ const MultiSelect = /*#__PURE__*/React.forwardRef(({
|
|
|
45
47
|
listMaxHeight,
|
|
46
48
|
flipEnabled = true,
|
|
47
49
|
wrapPillText = true,
|
|
50
|
+
inputRef,
|
|
48
51
|
...textboxProps
|
|
49
|
-
},
|
|
52
|
+
}, ref) => {
|
|
50
53
|
const [activeDescendantId, setActiveDescendantId] = useState();
|
|
51
54
|
const selectListId = useRef(guid());
|
|
52
55
|
const accessibilityLabelId = useRef(guid());
|
|
@@ -66,6 +69,12 @@ const MultiSelect = /*#__PURE__*/React.forwardRef(({
|
|
|
66
69
|
const [filterText, setFilterText] = useState("");
|
|
67
70
|
const [placeholderOverride, setPlaceholderOverride] = useState();
|
|
68
71
|
const actualValue = isControlled.current ? value : selectedValue;
|
|
72
|
+
|
|
73
|
+
if (!deprecateInputRefWarnTriggered && inputRef) {
|
|
74
|
+
deprecateInputRefWarnTriggered = true;
|
|
75
|
+
Logger.deprecate("The `inputRef` prop in `MultiSelect` component is deprecated and will soon be removed. Please use `ref` instead.");
|
|
76
|
+
}
|
|
77
|
+
|
|
69
78
|
const setOpen = useCallback(() => {
|
|
70
79
|
setOpenState(isAlreadyOpen => {
|
|
71
80
|
if (!isAlreadyOpen && onOpen) {
|
|
@@ -374,13 +383,19 @@ const MultiSelect = /*#__PURE__*/React.forwardRef(({
|
|
|
374
383
|
});
|
|
375
384
|
}
|
|
376
385
|
|
|
377
|
-
|
|
378
|
-
setTextboxRef(
|
|
386
|
+
const assignInput = useCallback(element => {
|
|
387
|
+
setTextboxRef(element);
|
|
388
|
+
|
|
389
|
+
if (inputRef || !ref) {
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
379
392
|
|
|
380
|
-
if (
|
|
381
|
-
|
|
393
|
+
if (typeof ref === "function") {
|
|
394
|
+
ref(element);
|
|
395
|
+
} else {
|
|
396
|
+
ref.current = element;
|
|
382
397
|
}
|
|
383
|
-
}
|
|
398
|
+
}, [ref, inputRef]);
|
|
384
399
|
|
|
385
400
|
function getTextboxProps() {
|
|
386
401
|
return {
|
|
@@ -390,7 +405,7 @@ const MultiSelect = /*#__PURE__*/React.forwardRef(({
|
|
|
390
405
|
readOnly,
|
|
391
406
|
placeholder: placeholderOverride,
|
|
392
407
|
leftChildren: mapValuesToPills,
|
|
393
|
-
|
|
408
|
+
ref: assignInput,
|
|
394
409
|
formattedValue: textValue,
|
|
395
410
|
selectedValue: actualValue,
|
|
396
411
|
onClick: handleTextboxClick,
|
|
@@ -403,6 +418,7 @@ const MultiSelect = /*#__PURE__*/React.forwardRef(({
|
|
|
403
418
|
onChange: handleTextboxChange,
|
|
404
419
|
tooltipPosition,
|
|
405
420
|
size,
|
|
421
|
+
inputRef,
|
|
406
422
|
...filterOutStyledSystemSpacingProps(textboxProps)
|
|
407
423
|
};
|
|
408
424
|
}
|
|
@@ -22,8 +22,7 @@ const floatingMiddleware = [offset(({
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
})];
|
|
25
|
-
|
|
26
|
-
const SelectTextbox = ({
|
|
25
|
+
const SelectTextbox = /*#__PURE__*/React.forwardRef(({
|
|
27
26
|
accessibilityLabelId,
|
|
28
27
|
labelId,
|
|
29
28
|
"aria-controls": ariaControls,
|
|
@@ -44,7 +43,7 @@ const SelectTextbox = ({
|
|
|
44
43
|
transparent,
|
|
45
44
|
activeDescendantId,
|
|
46
45
|
...restProps
|
|
47
|
-
}) => {
|
|
46
|
+
}, ref) => {
|
|
48
47
|
const reference = useMemo(() => ({
|
|
49
48
|
current: textboxRef === null || textboxRef === void 0 ? void 0 : textboxRef.parentElement.parentElement
|
|
50
49
|
}), [textboxRef]);
|
|
@@ -96,6 +95,7 @@ const SelectTextbox = ({
|
|
|
96
95
|
onBlur: handleTextboxBlur,
|
|
97
96
|
labelId,
|
|
98
97
|
type: "text",
|
|
98
|
+
ref,
|
|
99
99
|
...restProps
|
|
100
100
|
};
|
|
101
101
|
}
|
|
@@ -146,8 +146,7 @@ const SelectTextbox = ({
|
|
|
146
146
|
value: selectedValue,
|
|
147
147
|
placeholder: hasTextCursor ? placeholder || l.select.placeholder() : undefined
|
|
148
148
|
}, getInputAriaAttributes(), getTextboxProps()), !hasTextCursor && renderSelectText());
|
|
149
|
-
};
|
|
150
|
-
|
|
149
|
+
});
|
|
151
150
|
const formInputPropTypes = {
|
|
152
151
|
/**
|
|
153
152
|
* Id of the element containing the currently displayed value
|
|
@@ -262,5 +261,6 @@ SelectTextbox.propTypes = { ...formInputPropTypes,
|
|
|
262
261
|
* Value of the Select Input */
|
|
263
262
|
selectedValue: PropTypes.oneOfType([PropTypes.string, PropTypes.object, PropTypes.arrayOf(PropTypes.string), PropTypes.arrayOf(PropTypes.object)])
|
|
264
263
|
};
|
|
264
|
+
SelectTextbox.displayName = "SelectTextbox";
|
|
265
265
|
export default SelectTextbox;
|
|
266
266
|
export { formInputPropTypes };
|
|
@@ -12,6 +12,8 @@ import guid from "../../../__internal__/utils/helpers/guid";
|
|
|
12
12
|
import getNextChildByText from "../utils/get-next-child-by-text";
|
|
13
13
|
import isExpectedOption from "../utils/is-expected-option";
|
|
14
14
|
import isNavigationKey from "../utils/is-navigation-key";
|
|
15
|
+
import Logger from "../../../__internal__/utils/logger";
|
|
16
|
+
let deprecateInputRefWarnTriggered = false;
|
|
15
17
|
const SimpleSelect = /*#__PURE__*/React.forwardRef(({
|
|
16
18
|
value,
|
|
17
19
|
defaultValue,
|
|
@@ -40,8 +42,9 @@ const SimpleSelect = /*#__PURE__*/React.forwardRef(({
|
|
|
40
42
|
"data-role": dataRole,
|
|
41
43
|
listPlacement = "bottom",
|
|
42
44
|
flipEnabled = true,
|
|
45
|
+
inputRef,
|
|
43
46
|
...props
|
|
44
|
-
},
|
|
47
|
+
}, ref) => {
|
|
45
48
|
const selectListId = useRef(guid());
|
|
46
49
|
const labelId = useRef(guid());
|
|
47
50
|
const containerRef = useRef();
|
|
@@ -57,6 +60,12 @@ const SimpleSelect = /*#__PURE__*/React.forwardRef(({
|
|
|
57
60
|
const [activeDescendantId, setActiveDescendantId] = useState();
|
|
58
61
|
const [textValue, setTextValue] = useState("");
|
|
59
62
|
const [selectedValue, setSelectedValue] = useState(value || defaultValue || "");
|
|
63
|
+
|
|
64
|
+
if (!deprecateInputRefWarnTriggered && inputRef) {
|
|
65
|
+
deprecateInputRefWarnTriggered = true;
|
|
66
|
+
Logger.deprecate("The `inputRef` prop in `Select` component is deprecated and will soon be removed. Please use `ref` instead.");
|
|
67
|
+
}
|
|
68
|
+
|
|
60
69
|
const childOptions = useMemo(() => React.Children.toArray(children), [children]);
|
|
61
70
|
const createCustomEvent = useCallback(newValue => {
|
|
62
71
|
const customEvent = {
|
|
@@ -287,13 +296,19 @@ const SimpleSelect = /*#__PURE__*/React.forwardRef(({
|
|
|
287
296
|
setOpenState(false);
|
|
288
297
|
}
|
|
289
298
|
|
|
290
|
-
|
|
291
|
-
setTextboxRef(
|
|
299
|
+
const assignInput = useCallback(element => {
|
|
300
|
+
setTextboxRef(element);
|
|
301
|
+
|
|
302
|
+
if (inputRef || !ref) {
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
292
305
|
|
|
293
|
-
if (
|
|
294
|
-
|
|
306
|
+
if (typeof ref === "function") {
|
|
307
|
+
ref(element);
|
|
308
|
+
} else {
|
|
309
|
+
ref.current = element;
|
|
295
310
|
}
|
|
296
|
-
}
|
|
311
|
+
}, [ref, inputRef]);
|
|
297
312
|
|
|
298
313
|
function getTextboxProps() {
|
|
299
314
|
return {
|
|
@@ -301,7 +316,7 @@ const SimpleSelect = /*#__PURE__*/React.forwardRef(({
|
|
|
301
316
|
name,
|
|
302
317
|
disabled,
|
|
303
318
|
readOnly,
|
|
304
|
-
|
|
319
|
+
ref: assignInput,
|
|
305
320
|
selectedValue,
|
|
306
321
|
formattedValue: textValue,
|
|
307
322
|
onClick: handleTextboxClick,
|
|
@@ -312,6 +327,7 @@ const SimpleSelect = /*#__PURE__*/React.forwardRef(({
|
|
|
312
327
|
onBlur: handleTextboxBlur,
|
|
313
328
|
tooltipPosition,
|
|
314
329
|
transparent,
|
|
330
|
+
inputRef,
|
|
315
331
|
...filterOutStyledSystemSpacingProps(props)
|
|
316
332
|
};
|
|
317
333
|
}
|
|
@@ -3,7 +3,7 @@ export declare const StyledSimpleColor: import("styled-components").StyledCompon
|
|
|
3
3
|
export declare const StyledColorSampleBox: import("styled-components").StyledComponent<"div", any, {
|
|
4
4
|
color: string;
|
|
5
5
|
}, never>;
|
|
6
|
-
export declare const StyledSimpleColorInput: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<import("../../../__internal__/input").InputProps & import("react").RefAttributes<HTMLInputElement>>, any, {}, never>;
|
|
6
|
+
export declare const StyledSimpleColorInput: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<import("../../../__internal__/input").InputProps & import("react").RefAttributes<HTMLInputElement | HTMLTextAreaElement>>, any, {}, never>;
|
|
7
7
|
export declare const StyledTickIcon: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<import("../../icon").IconProps & import("react").RefAttributes<HTMLSpanElement>>, any, {
|
|
8
8
|
color: string;
|
|
9
9
|
}, never>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import React from "react";
|
|
2
2
|
import { MarginProps } from "styled-system";
|
|
3
3
|
import { CommonCheckableInputProps } from "../../__internal__/checkable-input";
|
|
4
4
|
export interface SwitchProps extends CommonCheckableInputProps, MarginProps {
|
|
@@ -26,6 +26,8 @@ export interface SwitchProps extends CommonCheckableInputProps, MarginProps {
|
|
|
26
26
|
tooltipPosition?: "top" | "bottom" | "left" | "right";
|
|
27
27
|
/** Aria label for rendered help component */
|
|
28
28
|
helpAriaLabel?: string;
|
|
29
|
+
/** A callback to retrieve the input reference (deprecated) */
|
|
30
|
+
inputRef?: React.Ref<HTMLInputElement>;
|
|
29
31
|
}
|
|
30
|
-
export declare const Switch:
|
|
32
|
+
export declare const Switch: React.ForwardRefExoticComponent<SwitchProps & React.RefAttributes<HTMLInputElement>>;
|
|
31
33
|
export default Switch;
|
|
@@ -6,8 +6,9 @@ import SwitchSlider from "./__internal__/switch-slider.component";
|
|
|
6
6
|
import useIsAboveBreakpoint from "../../hooks/__internal__/useIsAboveBreakpoint";
|
|
7
7
|
import { TooltipProvider } from "../../__internal__/tooltip-provider";
|
|
8
8
|
import { filterStyledSystemMarginProps } from "../../style/utils";
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
import Logger from "../../__internal__/utils/logger";
|
|
10
|
+
let deprecateInputRefWarnTriggered = false;
|
|
11
|
+
const Switch = /*#__PURE__*/React.forwardRef(({
|
|
11
12
|
autoFocus,
|
|
12
13
|
id,
|
|
13
14
|
label,
|
|
@@ -36,10 +37,17 @@ const Switch = ({
|
|
|
36
37
|
"data-element": dataElement,
|
|
37
38
|
"data-role": dataRole,
|
|
38
39
|
helpAriaLabel,
|
|
40
|
+
inputRef,
|
|
39
41
|
...rest
|
|
40
|
-
}) => {
|
|
42
|
+
}, ref) => {
|
|
41
43
|
const isControlled = checked !== undefined;
|
|
42
44
|
const [checkedInternal, setCheckedInternal] = useState(defaultChecked || false);
|
|
45
|
+
|
|
46
|
+
if (!deprecateInputRefWarnTriggered && inputRef) {
|
|
47
|
+
deprecateInputRefWarnTriggered = true;
|
|
48
|
+
Logger.deprecate("The `inputRef` prop in `Switch` component is deprecated and will soon be removed. Please use `ref` instead.");
|
|
49
|
+
}
|
|
50
|
+
|
|
43
51
|
const onChangeInternal = useCallback(e => {
|
|
44
52
|
setCheckedInternal(e.target.checked);
|
|
45
53
|
onChange === null || onChange === void 0 ? void 0 : onChange(e);
|
|
@@ -98,14 +106,14 @@ const Switch = ({
|
|
|
98
106
|
reverse: !reverse,
|
|
99
107
|
// switched to preserve backward compatibility
|
|
100
108
|
validationOnLabel: shouldValidationBeOnLabel && !disabled,
|
|
109
|
+
ref: ref || inputRef,
|
|
101
110
|
...rest
|
|
102
111
|
};
|
|
103
112
|
return /*#__PURE__*/React.createElement(TooltipProvider, {
|
|
104
113
|
helpAriaLabel: helpAriaLabel,
|
|
105
114
|
tooltipPosition: tooltipPosition
|
|
106
115
|
}, /*#__PURE__*/React.createElement(StyledSwitch, switchStyleProps, /*#__PURE__*/React.createElement(CheckableInput, inputProps, /*#__PURE__*/React.createElement(SwitchSlider, switchSliderProps))));
|
|
107
|
-
};
|
|
108
|
-
|
|
116
|
+
});
|
|
109
117
|
Switch.propTypes = {
|
|
110
118
|
"about": PropTypes.string,
|
|
111
119
|
"accept": PropTypes.string,
|
|
@@ -628,4 +636,5 @@ Switch.propTypes = {
|
|
|
628
636
|
"width": PropTypes.oneOfType([PropTypes.number, PropTypes.string])
|
|
629
637
|
};
|
|
630
638
|
export { Switch };
|
|
639
|
+
Switch.displayName = "Switch";
|
|
631
640
|
export default Switch;
|