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.
Files changed (87) hide show
  1. package/esm/__internal__/checkable-input/checkable-input.component.d.ts +1 -1
  2. package/esm/__internal__/checkable-input/checkable-input.component.js +5 -10
  3. package/esm/__internal__/checkable-input/hidden-checkable-input.component.d.ts +1 -3
  4. package/esm/__internal__/checkable-input/hidden-checkable-input.component.js +5 -10
  5. package/esm/__internal__/input/input.component.d.ts +2 -2
  6. package/esm/__internal__/input/input.component.js +14 -7
  7. package/esm/__internal__/input-behaviour/useInputBehaviour.d.ts +1 -1
  8. package/esm/components/advanced-color-picker/advanced-color-picker.component.js +1 -3
  9. package/esm/components/checkbox/checkbox.component.d.ts +3 -4
  10. package/esm/components/checkbox/checkbox.component.js +13 -5
  11. package/esm/components/date/date.component.js +32 -17
  12. package/esm/components/date-range/date-range.component.js +20 -2
  13. package/esm/components/date-range/date-range.d.ts +8 -0
  14. package/esm/components/decimal/decimal.component.d.ts +1 -1
  15. package/esm/components/decimal/decimal.component.js +17 -7
  16. package/esm/components/grouped-character/grouped-character.component.d.ts +1 -1
  17. package/esm/components/grouped-character/grouped-character.component.js +15 -5
  18. package/esm/components/menu/menu-item/menu-item.component.js +1 -1
  19. package/esm/components/number/number.component.d.ts +2 -2
  20. package/esm/components/number/number.component.js +15 -5
  21. package/esm/components/numeral-date/numeral-date.component.d.ts +13 -1
  22. package/esm/components/numeral-date/numeral-date.component.js +48 -5
  23. package/esm/components/radio-button/radio-button.component.d.ts +2 -0
  24. package/esm/components/radio-button/radio-button.component.js +10 -1
  25. package/esm/components/search/search.component.d.ts +1 -1
  26. package/esm/components/search/search.component.js +13 -12
  27. package/esm/components/select/filterable-select/filterable-select.component.js +23 -7
  28. package/esm/components/select/multi-select/multi-select.component.js +23 -7
  29. package/esm/components/select/select-textbox/select-textbox.component.js +5 -5
  30. package/esm/components/select/simple-select/simple-select.component.js +23 -7
  31. package/esm/components/simple-color-picker/simple-color/simple-color.style.d.ts +1 -1
  32. package/esm/components/switch/switch.component.d.ts +4 -2
  33. package/esm/components/switch/switch.component.js +14 -5
  34. package/esm/components/tabs/__internal__/tab-title/tab-title.component.js +5 -0
  35. package/esm/components/tabs/__internal__/tab-title/tab-title.d.ts +2 -0
  36. package/esm/components/tabs/tab/tab.component.js +8 -1
  37. package/esm/components/tabs/tab/tab.d.ts +5 -0
  38. package/esm/components/tabs/tabs.component.js +16 -23
  39. package/esm/components/textarea/textarea.component.d.ts +1 -1
  40. package/esm/components/textarea/textarea.component.js +37 -14
  41. package/esm/components/textbox/textbox.component.d.ts +1 -1
  42. package/esm/components/textbox/textbox.component.js +13 -5
  43. package/esm/components/tile-select/tile-select.component.js +14 -5
  44. package/lib/__internal__/checkable-input/checkable-input.component.d.ts +1 -1
  45. package/lib/__internal__/checkable-input/checkable-input.component.js +5 -8
  46. package/lib/__internal__/checkable-input/hidden-checkable-input.component.d.ts +1 -3
  47. package/lib/__internal__/checkable-input/hidden-checkable-input.component.js +5 -8
  48. package/lib/__internal__/input/input.component.d.ts +2 -2
  49. package/lib/__internal__/input/input.component.js +13 -6
  50. package/lib/__internal__/input-behaviour/useInputBehaviour.d.ts +1 -1
  51. package/lib/components/advanced-color-picker/advanced-color-picker.component.js +1 -3
  52. package/lib/components/checkbox/checkbox.component.d.ts +3 -4
  53. package/lib/components/checkbox/checkbox.component.js +16 -3
  54. package/lib/components/date/date.component.js +33 -14
  55. package/lib/components/date-range/date-range.component.js +20 -2
  56. package/lib/components/date-range/date-range.d.ts +8 -0
  57. package/lib/components/decimal/decimal.component.d.ts +1 -1
  58. package/lib/components/decimal/decimal.component.js +20 -5
  59. package/lib/components/grouped-character/grouped-character.component.d.ts +1 -1
  60. package/lib/components/grouped-character/grouped-character.component.js +18 -4
  61. package/lib/components/menu/menu-item/menu-item.component.js +1 -1
  62. package/lib/components/number/number.component.d.ts +2 -2
  63. package/lib/components/number/number.component.js +18 -4
  64. package/lib/components/numeral-date/numeral-date.component.d.ts +13 -1
  65. package/lib/components/numeral-date/numeral-date.component.js +48 -5
  66. package/lib/components/radio-button/radio-button.component.d.ts +2 -0
  67. package/lib/components/radio-button/radio-button.component.js +13 -1
  68. package/lib/components/search/search.component.d.ts +1 -1
  69. package/lib/components/search/search.component.js +16 -10
  70. package/lib/components/select/filterable-select/filterable-select.component.js +25 -7
  71. package/lib/components/select/multi-select/multi-select.component.js +25 -7
  72. package/lib/components/select/select-textbox/select-textbox.component.js +5 -3
  73. package/lib/components/select/simple-select/simple-select.component.js +26 -7
  74. package/lib/components/simple-color-picker/simple-color/simple-color.style.d.ts +1 -1
  75. package/lib/components/switch/switch.component.d.ts +4 -2
  76. package/lib/components/switch/switch.component.js +17 -3
  77. package/lib/components/tabs/__internal__/tab-title/tab-title.component.js +5 -0
  78. package/lib/components/tabs/__internal__/tab-title/tab-title.d.ts +2 -0
  79. package/lib/components/tabs/tab/tab.component.js +8 -1
  80. package/lib/components/tabs/tab/tab.d.ts +5 -0
  81. package/lib/components/tabs/tabs.component.js +16 -24
  82. package/lib/components/textarea/textarea.component.d.ts +1 -1
  83. package/lib/components/textarea/textarea.component.js +38 -11
  84. package/lib/components/textbox/textbox.component.d.ts +1 -1
  85. package/lib/components/textbox/textbox.component.js +16 -3
  86. package/lib/components/tile-select/tile-select.component.js +17 -4
  87. package/package.json +1 -1
@@ -13,6 +13,7 @@ export const TabTitleContext = /*#__PURE__*/React.createContext({});
13
13
  const TabTitle = /*#__PURE__*/React.forwardRef(({
14
14
  isTabSelected,
15
15
  dataTabId,
16
+ "data-role": dataRole,
16
17
  title,
17
18
  position = "top",
18
19
  error,
@@ -127,6 +128,7 @@ const TabTitle = /*#__PURE__*/React.forwardRef(({
127
128
  "aria-selected": isTabSelected,
128
129
  "data-element": "select-tab",
129
130
  "data-tabid": dataTabId,
131
+ "data-role": dataRole,
130
132
  role: "tab",
131
133
  position: position,
132
134
  isTabSelected: isTabSelected,
@@ -201,6 +203,9 @@ TabTitle.propTypes = {
201
203
  isTabSelected: PropTypes.bool,
202
204
  position: PropTypes.oneOf(["top", "left"]),
203
205
  className: PropTypes.string,
206
+
207
+ /** Identifier used for testing purposes */
208
+ "data-role": PropTypes.string,
204
209
  dataTabId: PropTypes.string,
205
210
  id: PropTypes.string,
206
211
  onClick: PropTypes.func,
@@ -5,6 +5,8 @@ export interface TabTitleContextProps {
5
5
  }
6
6
 
7
7
  export interface TabTitleProps {
8
+ /** Identifier used for testing purposes */
9
+ "data-role"?: string;
8
10
  title: string;
9
11
  id?: string;
10
12
  dataTabId?: string;
@@ -22,6 +22,7 @@ const Tab = ({
22
22
  updateInfos,
23
23
  href,
24
24
  title,
25
+ titleProps,
25
26
  ...rest
26
27
  }) => {
27
28
  const [tabErrors, setTabErrors] = useState({});
@@ -124,7 +125,13 @@ Tab.propTypes = { ...paddingPropTypes,
124
125
  titlePosition: PropTypes.oneOf(["before", "after"]),
125
126
 
126
127
  /** Allows Tab to be a link */
127
- href: PropTypes.string
128
+ href: PropTypes.string,
129
+
130
+ /** Additional props to be passed to the Tab's corresponding title */
131
+ titleProps: PropTypes.shape({
132
+ /** Identifier used for testing purposes */
133
+ "data-role": PropTypes.string
134
+ })
128
135
  };
129
136
  export { TabContext };
130
137
  export default Tab;
@@ -32,6 +32,11 @@ export interface TabProps extends PaddingProps {
32
32
  href?: string;
33
33
  /** Overrides default layout with a one defined in this prop */
34
34
  customLayout?: React.ReactNode;
35
+ /** Additional props to be passed to the Tab's corresponding title. */
36
+ titleProps?: {
37
+ /** Identifier used for testing purposes */
38
+ "data-role"?: string;
39
+ };
35
40
  }
36
41
 
37
42
  export interface TabAllProps {
@@ -170,7 +170,8 @@ const Tabs = ({
170
170
  warningMessage,
171
171
  infoMessage,
172
172
  href,
173
- customLayout
173
+ customLayout,
174
+ titleProps
174
175
  } = child.props;
175
176
  const refId = `${tabId}-tab`;
176
177
  const errors = tabsErrors[tabId];
@@ -201,7 +202,7 @@ const Tabs = ({
201
202
  return summaryOfMessages.map(value => `• ${value}`).join("\n");
202
203
  };
203
204
 
204
- const tabTitle = /*#__PURE__*/React.createElement(TabTitle, {
205
+ return /*#__PURE__*/React.createElement(TabTitle, _extends({}, titleProps, {
205
206
  position: isInSidebar ? "left" : position,
206
207
  className: child.props.className || "",
207
208
  dataTabId: tabId,
@@ -230,8 +231,7 @@ const Tabs = ({
230
231
  customLayout: customLayout,
231
232
  isInSidebar: isInSidebar,
232
233
  align: align
233
- });
234
- return tabTitle;
234
+ }));
235
235
  });
236
236
  return /*#__PURE__*/React.createElement(TabsHeader, {
237
237
  align: align,
@@ -243,22 +243,6 @@ const Tabs = ({
243
243
  isInSidebar: isInSidebar
244
244
  }, tabTitles);
245
245
  };
246
- /** Builds the single currently selected tab */
247
-
248
-
249
- const visibleTab = () => {
250
- const tab = filteredChildren.find(child => isTabSelected(child.props.tabId));
251
- return tab && /*#__PURE__*/cloneElement(tab, { ...tab.props,
252
- role: "tabpanel",
253
- position,
254
- isTabSelected: isTabSelected(tab.props.tabId),
255
- key: `${tab.props.tabId}-tab`,
256
- ariaLabelledby: `${tab.props.tabId}-tab`,
257
- updateErrors,
258
- updateWarnings,
259
- updateInfos
260
- });
261
- };
262
246
  /** Builds all tabs where non selected tabs have class of hidden */
263
247
 
264
248
 
@@ -266,10 +250,20 @@ const Tabs = ({
266
250
  if (isInSidebar) return null;
267
251
 
268
252
  if (!renderHiddenTabs) {
269
- return visibleTab();
253
+ const tab = filteredChildren.find(child => isTabSelected(child.props.tabId));
254
+ return tab && /*#__PURE__*/cloneElement(tab, { ...tab.props,
255
+ role: "tabpanel",
256
+ position,
257
+ isTabSelected: isTabSelected(tab.props.tabId),
258
+ key: `${tab.props.tabId}-tab`,
259
+ ariaLabelledby: `${tab.props.tabId}-tab`,
260
+ updateErrors,
261
+ updateWarnings,
262
+ updateInfos
263
+ });
270
264
  }
271
265
 
272
- const tabs = filteredChildren.map(child => {
266
+ return filteredChildren.map(child => {
273
267
  return /*#__PURE__*/cloneElement(child, { ...child.props,
274
268
  role: "tabpanel",
275
269
  position,
@@ -281,7 +275,6 @@ const Tabs = ({
281
275
  updateInfos
282
276
  });
283
277
  });
284
- return tabs;
285
278
  };
286
279
 
287
280
  return /*#__PURE__*/React.createElement(StyledTabs, _extends({
@@ -94,6 +94,6 @@ export interface TextareaProps extends ValidationProps, MarginProps, Omit<Common
94
94
  Pass true boolean to only display orange border */
95
95
  warning?: boolean | string;
96
96
  }
97
- export declare const Textarea: ({ autoFocus, fieldHelp, label, size, children, characterLimit, enforceCharacterLimit, warnOverLimit, onChange, disabled, labelInline, labelAlign, labelHelp, labelSpacing, inputIcon, id: idProp, error, warning, info, name, readOnly, placeholder, expandable, rows, cols, validationOnLabel, adaptiveLabelBreakpoint, inputWidth, maxWidth, labelWidth, tooltipPosition, value, "data-component": dataComponent, "data-element": dataElement, "data-role": dataRole, helpAriaLabel, ...props }: TextareaProps) => JSX.Element;
97
+ export declare const Textarea: React.ForwardRefExoticComponent<TextareaProps & React.RefAttributes<HTMLTextAreaElement>>;
98
98
  export { Textarea as OriginalTextarea };
99
99
  export default Textarea;
@@ -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, { useRef, useEffect, useContext } from "react";
3
+ import React, { useRef, useEffect, useContext, useCallback } from "react";
4
4
  import PropTypes from "prop-types";
5
5
  import { InputPresentation } from "../../__internal__/input";
6
6
  import FormField from "../../__internal__/form-field";
@@ -16,9 +16,11 @@ import useInputAccessibility from "../../hooks/__internal__/useInputAccessibilit
16
16
  import { NewValidationContext } from "../carbon-provider/carbon-provider.component";
17
17
  import { ErrorBorder, StyledHintText } from "../textbox/textbox.style";
18
18
  import ValidationMessage from "../../__internal__/validation-message";
19
- import Box from "../box"; // TODO: Change characterLimit type to number - batch with other breaking changes
19
+ import Box from "../box";
20
+ import Logger from "../../__internal__/utils/logger"; // TODO: Change characterLimit type to number - batch with other breaking changes
20
21
 
21
- const Textarea = ({
22
+ let deprecateInputRefWarnTriggered = false;
23
+ const Textarea = /*#__PURE__*/React.forwardRef(({
22
24
  autoFocus,
23
25
  fieldHelp,
24
26
  label,
@@ -55,8 +57,9 @@ const Textarea = ({
55
57
  "data-element": dataElement,
56
58
  "data-role": dataRole,
57
59
  helpAriaLabel,
60
+ inputRef,
58
61
  ...props
59
- }) => {
62
+ }, ref) => {
60
63
  const {
61
64
  validationRedesignOptIn
62
65
  } = useContext(NewValidationContext);
@@ -66,11 +69,30 @@ const Textarea = ({
66
69
  const {
67
70
  current: id
68
71
  } = useRef(idProp || guid());
69
- const inputRef = useRef(null);
72
+ const internalRef = useRef(null);
73
+ const callbackRef = useCallback(inputElement => {
74
+ internalRef.current = inputElement;
75
+
76
+ if (!ref) {
77
+ return;
78
+ }
79
+
80
+ if ("current" in ref) {
81
+ ref.current = inputElement;
82
+ } else {
83
+ ref(inputElement);
84
+ }
85
+ }, [ref]);
86
+
87
+ if (!deprecateInputRefWarnTriggered && inputRef) {
88
+ deprecateInputRefWarnTriggered = true;
89
+ Logger.deprecate("The `inputRef` prop in `Textarea` component is deprecated and will soon be removed. Please use `ref` instead.");
90
+ }
91
+
70
92
  const minHeight = useRef(MIN_HEIGHT);
71
93
 
72
94
  const expandTextarea = () => {
73
- const textarea = inputRef.current;
95
+ const textarea = internalRef.current;
74
96
 
75
97
  if (textarea !== null && textarea !== void 0 && textarea.scrollHeight && (textarea === null || textarea === void 0 ? void 0 : textarea.scrollHeight) > minHeight.current) {
76
98
  textarea.style.height = "0px"; // Set the height so all content is shown
@@ -97,9 +119,9 @@ const Textarea = ({
97
119
  typeof characterLimit === "string" ? parseInt(characterLimit, 10) : characterLimit, warnOverLimit, enforceCharacterLimit);
98
120
  useEffect(() => {
99
121
  if (rows) {
100
- var _inputRef$current;
122
+ var _internalRef$current;
101
123
 
102
- minHeight.current = (inputRef === null || inputRef === void 0 ? void 0 : (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.scrollHeight) || 0;
124
+ minHeight.current = (internalRef === null || internalRef === void 0 ? void 0 : (_internalRef$current = internalRef.current) === null || _internalRef$current === void 0 ? void 0 : _internalRef$current.scrollHeight) || 0;
103
125
  }
104
126
  }, [rows]);
105
127
  useEffect(() => {
@@ -109,10 +131,10 @@ const Textarea = ({
109
131
  });
110
132
  useEffect(() => {
111
133
  if (expandable) {
112
- var _inputRef$current2;
134
+ var _internalRef$current2;
113
135
 
114
136
  window.addEventListener("resize", expandTextarea);
115
- minHeight.current = (inputRef === null || inputRef === void 0 ? void 0 : (_inputRef$current2 = inputRef.current) === null || _inputRef$current2 === void 0 ? void 0 : _inputRef$current2.clientHeight) || 0;
137
+ minHeight.current = (internalRef === null || internalRef === void 0 ? void 0 : (_internalRef$current2 = internalRef.current) === null || _internalRef$current2 === void 0 ? void 0 : _internalRef$current2.clientHeight) || 0;
116
138
  }
117
139
 
118
140
  return () => {
@@ -138,7 +160,7 @@ const Textarea = ({
138
160
  autoFocus: autoFocus,
139
161
  name: name,
140
162
  value: value,
141
- ref: inputRef,
163
+ ref: callbackRef,
142
164
  maxLength: maxLength,
143
165
  onChange: onChange,
144
166
  disabled: disabled,
@@ -147,7 +169,8 @@ const Textarea = ({
147
169
  rows: rows,
148
170
  cols: cols,
149
171
  id: id,
150
- as: "textarea"
172
+ as: "textarea",
173
+ inputRef: inputRef
151
174
  }, props)), children, /*#__PURE__*/React.createElement(InputIconToggle, {
152
175
  disabled: disabled,
153
176
  readOnly: readOnly,
@@ -195,8 +218,7 @@ const Textarea = ({
195
218
  }), (error || warning) && /*#__PURE__*/React.createElement(ErrorBorder, {
196
219
  warning: !!(!error && warning)
197
220
  }), input) : input), characterCount)));
198
- };
199
-
221
+ });
200
222
  Textarea.propTypes = {
201
223
  "about": PropTypes.string,
202
224
  "accept": PropTypes.string,
@@ -724,5 +746,6 @@ Textarea.propTypes = {
724
746
  "width": PropTypes.oneOfType([PropTypes.number, PropTypes.string])
725
747
  };
726
748
  export { Textarea };
749
+ Textarea.displayName = "Textarea";
727
750
  export { Textarea as OriginalTextarea };
728
751
  export default Textarea;
@@ -93,5 +93,5 @@ export interface TextboxProps extends CommonTextboxProps {
93
93
  /** Whether to display the character count message in red */
94
94
  warnOverLimit?: boolean;
95
95
  }
96
- export declare const Textbox: ({ align, autoFocus, children, disabled, inputIcon, leftChildren, labelId: externalLabelId, label, labelAlign, labelHelp, labelInline, labelSpacing, id, formattedValue, fieldHelp, error, warning, info, name, reverse, size, value, readOnly, placeholder, inputRef, onBlur, onClick, onFocus, onChange, onMouseDown, onChangeDeferred, deferTimeout, isOptional, iconOnClick, iconOnMouseDown, iconTabIndex, validationOnLabel, labelWidth, inputWidth, maxWidth, prefix, adaptiveLabelBreakpoint, required, positionedChildren, tooltipPosition, "data-component": dataComponent, "data-element": dataElement, "data-role": dataRole, enforceCharacterLimit, characterLimit, warnOverLimit, helpAriaLabel, ...props }: TextboxProps) => JSX.Element;
96
+ export declare const Textbox: React.ForwardRefExoticComponent<TextboxProps & React.RefAttributes<HTMLInputElement>>;
97
97
  export default Textbox;
@@ -17,8 +17,9 @@ import ValidationMessage from "../../__internal__/validation-message";
17
17
  import { NewValidationContext } from "../carbon-provider/carbon-provider.component";
18
18
  import NumeralDateContext from "../numeral-date/numeral-date-context";
19
19
  import Box from "../box";
20
-
21
- const Textbox = ({
20
+ import Logger from "../../__internal__/utils/logger";
21
+ let deprecateInputRefWarnTriggered = false;
22
+ const Textbox = /*#__PURE__*/React.forwardRef(({
22
23
  align = "left",
23
24
  autoFocus,
24
25
  children,
@@ -72,7 +73,7 @@ const Textbox = ({
72
73
  warnOverLimit = false,
73
74
  helpAriaLabel,
74
75
  ...props
75
- }) => {
76
+ }, ref) => {
76
77
  const characterCountValue = typeof value === "string" ? value : "";
77
78
  const [maxLength, characterCount] = useCharacterCount(characterCountValue, // TODO: Can be removed after the characterLimit type is changed to number
78
79
  typeof characterLimit === "string" ? parseInt(characterLimit, 10) : characterLimit, warnOverLimit, enforceCharacterLimit);
@@ -86,6 +87,12 @@ const Textbox = ({
86
87
  const computeLabelPropValues = prop => validationRedesignOptIn ? undefined : prop;
87
88
 
88
89
  const [uniqueId, uniqueName] = useUniqueId(id, name);
90
+
91
+ if (!deprecateInputRefWarnTriggered && inputRef) {
92
+ deprecateInputRefWarnTriggered = true;
93
+ Logger.deprecate("The `inputRef` prop in `Textbox` component is deprecated and will soon be removed. Please use `ref` instead.");
94
+ }
95
+
89
96
  const {
90
97
  labelId: internalLabelId,
91
98
  validationIconId,
@@ -128,6 +135,7 @@ const Textbox = ({
128
135
  disabled: disabled,
129
136
  id: uniqueId,
130
137
  inputRef: inputRef,
138
+ ref: ref,
131
139
  name: uniqueName,
132
140
  onBlur: onBlur,
133
141
  onChange: onChange,
@@ -190,8 +198,7 @@ const Textbox = ({
190
198
  }), !disableErrorBorder && (error || warning) && /*#__PURE__*/React.createElement(ErrorBorder, {
191
199
  warning: !!(!error && warning)
192
200
  }), input) : input), characterCount));
193
- };
194
-
201
+ });
195
202
  Textbox.propTypes = {
196
203
  "about": PropTypes.string,
197
204
  "accept": PropTypes.string,
@@ -726,4 +733,5 @@ Textbox.propTypes = {
726
733
  "width": PropTypes.oneOfType([PropTypes.number, PropTypes.string])
727
734
  };
728
735
  export { Textbox };
736
+ Textbox.displayName = "Textbox";
729
737
  export default Textbox;
@@ -9,6 +9,7 @@ import createGuid from "../../__internal__/utils/helpers/guid";
9
9
  import Button from "../button";
10
10
  import Box from "../box";
11
11
  import Accordion from "./__internal__/accordion";
12
+ import Logger from "../../__internal__/utils/logger";
12
13
  import { StyledTileSelectContainer, StyledTileSelect, StyledTileSelectInput, StyledTitleContainer, StyledTitle, StyledSubtitle, StyledAdornment, StyledDescription, StyledDeselectWrapper, StyledFooterWrapper, StyledFocusWrapper, StyledAccordionFooterWrapper } from "./tile-select.style";
13
14
  import { filterStyledSystemMarginProps } from "../../style/utils";
14
15
  const marginPropTypes = filterStyledSystemMarginProps(styledSystemPropTypes.space);
@@ -17,7 +18,8 @@ const checkPropTypeIsNode = prop => typeof prop !== "string" && {
17
18
  as: "div"
18
19
  };
19
20
 
20
- const TileSelect = ({
21
+ let deprecateInputRefWarnTriggered = false;
22
+ const TileSelect = /*#__PURE__*/React.forwardRef(({
21
23
  onChange,
22
24
  onBlur,
23
25
  onFocus,
@@ -40,8 +42,9 @@ const TileSelect = ({
40
42
  accordionContent,
41
43
  accordionControl,
42
44
  accordionExpanded,
45
+ inputRef,
43
46
  ...rest
44
- }) => {
47
+ }, ref) => {
45
48
  const l = useLocale();
46
49
  const [hasFocus, setHasFocus] = useState(false);
47
50
 
@@ -57,6 +60,11 @@ const TileSelect = ({
57
60
  }
58
61
  });
59
62
 
63
+ if (!deprecateInputRefWarnTriggered && inputRef) {
64
+ deprecateInputRefWarnTriggered = true;
65
+ Logger.deprecate("The `inputRef` prop in `TileSelect` component is deprecated and will soon be removed. Please use `ref` instead.");
66
+ }
67
+
60
68
  const renderActionButton = () => /*#__PURE__*/React.createElement(StyledDeselectWrapper, {
61
69
  hasActionAdornment: !!actionButtonAdornment
62
70
  }, customActionButton && customActionButton(handleDeselect), !customActionButton && checked && /*#__PURE__*/React.createElement(Button, {
@@ -101,7 +109,9 @@ const TileSelect = ({
101
109
  value: value,
102
110
  disabled: disabled,
103
111
  "aria-checked": checked,
104
- id: id
112
+ id: id,
113
+ inputRef: inputRef,
114
+ ref: ref
105
115
  }, rest)), /*#__PURE__*/React.createElement(StyledTileSelect, {
106
116
  disabled: disabled,
107
117
  checked: checked
@@ -124,8 +134,7 @@ const TileSelect = ({
124
134
  controlId: controlId,
125
135
  expanded: accordionExpanded
126
136
  }, accordionContent)));
127
- };
128
-
137
+ });
129
138
  TileSelect.defaultProps = {
130
139
  checked: false,
131
140
  type: "checkbox"
@@ -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: ({ ariaLabelledBy: externalAriaLabelledBy, autoFocus, checked, children, disabled, error, fieldHelp, fieldHelpInline, info, id: inputId, inputRef, type, value, inputWidth, label, labelAlign, labelHelp, labelInline, labelSpacing, labelWidth, name, onBlur, onChange, onFocus, required, reverse, validationOnLabel, warning, ...props }: CheckableInputProps) => JSX.Element;
49
+ declare const CheckableInput: React.ForwardRefExoticComponent<CheckableInputProps & React.RefAttributes<HTMLInputElement>>;
50
50
  export default CheckableInput;
@@ -27,7 +27,7 @@ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return
27
27
 
28
28
  function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
29
29
 
30
- const CheckableInput = ({
30
+ const CheckableInput = /*#__PURE__*/_react.default.forwardRef(({
31
31
  ariaLabelledBy: externalAriaLabelledBy,
32
32
  autoFocus,
33
33
  checked,
@@ -38,7 +38,6 @@ const CheckableInput = ({
38
38
  fieldHelpInline,
39
39
  info,
40
40
  id: inputId,
41
- inputRef,
42
41
  type,
43
42
  value,
44
43
  inputWidth,
@@ -57,7 +56,7 @@ const CheckableInput = ({
57
56
  validationOnLabel,
58
57
  warning,
59
58
  ...props
60
- }) => {
59
+ }, ref) => {
61
60
  const {
62
61
  current: id
63
62
  } = (0, _react.useRef)(inputId || (0, _guid.default)());
@@ -108,7 +107,6 @@ const CheckableInput = ({
108
107
  checked,
109
108
  disabled,
110
109
  id,
111
- inputRef,
112
110
  type,
113
111
  value,
114
112
  name,
@@ -116,6 +114,7 @@ const CheckableInput = ({
116
114
  onChange,
117
115
  onFocus,
118
116
  required,
117
+ ref,
119
118
  ...props
120
119
  };
121
120
  return /*#__PURE__*/_react.default.createElement(_checkableInput.StyledCheckableInputWrapper, {
@@ -126,7 +125,7 @@ const CheckableInput = ({
126
125
  labelInline: labelInline,
127
126
  reverse: reverse
128
127
  }, /*#__PURE__*/_react.default.createElement(_inputBehaviour.InputBehaviour, null, /*#__PURE__*/_react.default.createElement(_formField.default, formFieldProps, /*#__PURE__*/_react.default.createElement(_checkableInput.StyledCheckableInput, null, /*#__PURE__*/_react.default.createElement(_hiddenCheckableInput.default, inputProps), children))));
129
- };
128
+ });
130
129
 
131
130
  CheckableInput.propTypes = {
132
131
  "about": _propTypes.default.string,
@@ -223,9 +222,6 @@ CheckableInput.propTypes = {
223
222
  "info": _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.bool]),
224
223
  "inlist": _propTypes.default.any,
225
224
  "inputMode": _propTypes.default.oneOf(["decimal", "email", "none", "numeric", "search", "tel", "text", "url"]),
226
- "inputRef": _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.shape({
227
- "current": _propTypes.default.oneOfType([_propTypes.default.oneOf([null]), _propTypes.default.object]).isRequired
228
- })]),
229
225
  "inputWidth": _propTypes.default.number,
230
226
  "is": _propTypes.default.string,
231
227
  "itemID": _propTypes.default.string,
@@ -489,5 +485,6 @@ CheckableInput.propTypes = {
489
485
  "warning": _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.bool]),
490
486
  "width": _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string])
491
487
  };
488
+ CheckableInput.displayName = "CheckableInput";
492
489
  var _default = CheckableInput;
493
490
  exports.default = _default;
@@ -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<({ name, checked, type, value, inputRef, onChange, autoFocus, role, ...props }: HiddenCheckableInputProps) => JSX.Element>;
28
+ declare const _default: React.MemoExoticComponent<React.ForwardRefExoticComponent<HiddenCheckableInputProps & React.RefAttributes<HTMLInputElement>>>;
31
29
  export default _default;
@@ -21,17 +21,16 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
21
21
 
22
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); }
23
23
 
24
- const HiddenCheckableInput = ({
24
+ const HiddenCheckableInput = /*#__PURE__*/_react.default.forwardRef(({
25
25
  name,
26
26
  checked,
27
27
  type,
28
28
  value,
29
- inputRef,
30
29
  onChange,
31
30
  autoFocus,
32
31
  role,
33
32
  ...props
34
- }) => {
33
+ }, ref) => {
35
34
  const {
36
35
  onBlur,
37
36
  onFocus,
@@ -86,9 +85,9 @@ const HiddenCheckableInput = ({
86
85
  onMouseEnter: handleMouseEnter,
87
86
  onMouseLeave: handleMouseLeave,
88
87
  onChange: onChange,
89
- ref: inputRef
88
+ ref: ref
90
89
  }));
91
- };
90
+ });
92
91
 
93
92
  HiddenCheckableInput.propTypes = {
94
93
  "about": _propTypes.default.string,
@@ -180,9 +179,6 @@ HiddenCheckableInput.propTypes = {
180
179
  "id": _propTypes.default.string,
181
180
  "inlist": _propTypes.default.any,
182
181
  "inputMode": _propTypes.default.oneOf(["decimal", "email", "none", "numeric", "search", "tel", "text", "url"]),
183
- "inputRef": _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.shape({
184
- "current": _propTypes.default.oneOfType([_propTypes.default.oneOf([null]), _propTypes.default.object]).isRequired
185
- })]),
186
182
  "is": _propTypes.default.string,
187
183
  "itemID": _propTypes.default.string,
188
184
  "itemProp": _propTypes.default.string,
@@ -385,6 +381,7 @@ HiddenCheckableInput.propTypes = {
385
381
  "vocab": _propTypes.default.string,
386
382
  "width": _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string])
387
383
  };
384
+ HiddenCheckableInput.displayName = "HiddenCheckableInput";
388
385
 
389
386
  var _default = /*#__PURE__*/_react.default.memo(HiddenCheckableInput);
390
387
 
@@ -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;
@@ -49,6 +49,7 @@ const Input = /*#__PURE__*/_react.default.forwardRef(({
49
49
  disabled,
50
50
  readOnly,
51
51
  autoFocus,
52
+ // TODO: remove inputRef prop from this component (and props interface) when it has been removed from all exposed input components
52
53
  inputRef,
53
54
  onClick,
54
55
  onChangeDeferred,
@@ -66,15 +67,21 @@ const Input = /*#__PURE__*/_react.default.forwardRef(({
66
67
  const deferredTimeout = (0, _react.useRef)(null);
67
68
  let input = (0, _react.useRef)(null);
68
69
 
69
- if (ref) {
70
+ if (ref && "current" in ref) {
70
71
  input = ref;
71
72
  }
72
73
 
73
- (0, _react.useEffect)(() => {
74
- if (autoFocus && input.current) {
75
- input.current.focus();
74
+ const callbackRef = (0, _react.useCallback)(element => {
75
+ input.current = element;
76
+
77
+ if (typeof ref === "function") {
78
+ ref(element);
79
+ }
80
+
81
+ if (autoFocus && element) {
82
+ element.focus();
76
83
  }
77
- }, [autoFocus, input]);
84
+ }, [autoFocus, ref]);
78
85
  (0, _react.useEffect)(() => {
79
86
  if (inputRef) {
80
87
  inputRef(input);
@@ -162,7 +169,7 @@ const Input = /*#__PURE__*/_react.default.forwardRef(({
162
169
  name: name,
163
170
  type: type,
164
171
  id: id || name,
165
- ref: input,
172
+ ref: callbackRef,
166
173
  "data-element": "input",
167
174
  onFocus: handleFocus,
168
175
  onBlur: handleBlur,
@@ -7,7 +7,7 @@ export interface InputContextProps {
7
7
  onMouseEnter?: () => void;
8
8
  onMouseLeave?: () => void;
9
9
  inputRef?: (input: {
10
- current: HTMLInputElement | null;
10
+ current: HTMLInputElement | HTMLTextAreaElement | null;
11
11
  }) => void;
12
12
  ariaLabelledBy?: string;
13
13
  }
@@ -159,9 +159,7 @@ const AdvancedColorPicker = ({
159
159
  "aria-label": label,
160
160
  id: value,
161
161
  defaultChecked: value === currentColor,
162
- inputRef: input => {
163
- ref.current = input.current;
164
- }
162
+ ref: ref
165
163
  })))));
166
164
  };
167
165
 
@@ -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;