@carbon/react 1.87.1 → 1.89.0-rc.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 (97) hide show
  1. package/.playwright/INTERNAL_AVT_REPORT_DO_NOT_USE.json +804 -804
  2. package/es/components/AILabel/index.d.ts +4 -3
  3. package/es/components/AILabel/index.js +3 -1
  4. package/es/components/Button/Button.js +3 -1
  5. package/es/components/CodeSnippet/CodeSnippet.d.ts +9 -5
  6. package/es/components/CodeSnippet/CodeSnippet.js +3 -1
  7. package/es/components/ComboBox/ComboBox.d.ts +2 -1
  8. package/es/components/ComboBox/ComboBox.js +2 -1
  9. package/es/components/ContainedList/ContainedList.d.ts +2 -2
  10. package/es/components/ContentSwitcher/ContentSwitcher.d.ts +1 -6
  11. package/es/components/Copy/Copy.d.ts +9 -5
  12. package/es/components/Copy/Copy.js +3 -1
  13. package/es/components/CopyButton/CopyButton.d.ts +9 -5
  14. package/es/components/CopyButton/CopyButton.js +3 -1
  15. package/es/components/Dropdown/Dropdown.d.ts +4 -1
  16. package/es/components/Dropdown/Dropdown.js +4 -1
  17. package/es/components/FileUploader/FileUploaderButton.js +6 -3
  18. package/es/components/IconButton/index.d.ts +6 -4
  19. package/es/components/IconButton/index.js +3 -4
  20. package/es/components/MultiSelect/FilterableMultiSelect.d.ts +5 -2
  21. package/es/components/MultiSelect/FilterableMultiSelect.js +101 -22
  22. package/es/components/MultiSelect/MultiSelect.d.ts +2 -1
  23. package/es/components/MultiSelect/MultiSelect.js +2 -1
  24. package/es/components/Notification/Notification.d.ts +9 -1
  25. package/es/components/Notification/Notification.js +9 -1
  26. package/es/components/NumberInput/NumberInput.d.ts +4 -0
  27. package/es/components/NumberInput/NumberInput.js +12 -7
  28. package/es/components/OverflowMenu/next/index.d.ts +6 -2
  29. package/es/components/OverflowMenu/next/index.js +4 -1
  30. package/es/components/Popover/index.d.ts +4 -1
  31. package/es/components/Popover/index.js +15 -22
  32. package/es/components/Switch/IconSwitch.d.ts +44 -2
  33. package/es/components/Switch/IconSwitch.js +34 -27
  34. package/es/components/Switch/Switch.js +1 -0
  35. package/es/components/TextArea/TextArea.js +21 -4
  36. package/es/components/Toggletip/index.d.ts +4 -1
  37. package/es/components/Toggletip/index.js +4 -1
  38. package/es/components/Tooltip/DefinitionTooltip.d.ts +4 -2
  39. package/es/components/Tooltip/DefinitionTooltip.js +3 -1
  40. package/es/components/Tooltip/Tooltip.d.ts +0 -3
  41. package/es/components/Tooltip/Tooltip.js +2 -10
  42. package/es/components/TreeView/TreeNode.d.ts +4 -2
  43. package/es/components/TreeView/TreeNode.js +2 -1
  44. package/es/components/UIShell/Header.d.ts +3 -3
  45. package/es/components/UIShell/Header.js +7 -4
  46. package/es/components/UIShell/HeaderPanel.js +1 -1
  47. package/es/internal/Selection.d.ts +1 -0
  48. package/es/internal/Selection.js +10 -0
  49. package/lib/components/AILabel/index.d.ts +4 -3
  50. package/lib/components/AILabel/index.js +3 -1
  51. package/lib/components/Button/Button.js +3 -1
  52. package/lib/components/CodeSnippet/CodeSnippet.d.ts +9 -5
  53. package/lib/components/CodeSnippet/CodeSnippet.js +3 -1
  54. package/lib/components/ComboBox/ComboBox.d.ts +2 -1
  55. package/lib/components/ComboBox/ComboBox.js +2 -1
  56. package/lib/components/ContainedList/ContainedList.d.ts +2 -2
  57. package/lib/components/ContentSwitcher/ContentSwitcher.d.ts +1 -6
  58. package/lib/components/Copy/Copy.d.ts +9 -5
  59. package/lib/components/Copy/Copy.js +3 -1
  60. package/lib/components/CopyButton/CopyButton.d.ts +9 -5
  61. package/lib/components/CopyButton/CopyButton.js +3 -1
  62. package/lib/components/Dropdown/Dropdown.d.ts +4 -1
  63. package/lib/components/Dropdown/Dropdown.js +4 -1
  64. package/lib/components/FileUploader/FileUploaderButton.js +6 -3
  65. package/lib/components/IconButton/index.d.ts +6 -4
  66. package/lib/components/IconButton/index.js +3 -4
  67. package/lib/components/MultiSelect/FilterableMultiSelect.d.ts +5 -2
  68. package/lib/components/MultiSelect/FilterableMultiSelect.js +100 -21
  69. package/lib/components/MultiSelect/MultiSelect.d.ts +2 -1
  70. package/lib/components/MultiSelect/MultiSelect.js +2 -1
  71. package/lib/components/Notification/Notification.d.ts +9 -1
  72. package/lib/components/Notification/Notification.js +9 -1
  73. package/lib/components/NumberInput/NumberInput.d.ts +4 -0
  74. package/lib/components/NumberInput/NumberInput.js +12 -7
  75. package/lib/components/OverflowMenu/next/index.d.ts +6 -2
  76. package/lib/components/OverflowMenu/next/index.js +4 -1
  77. package/lib/components/Popover/index.d.ts +4 -1
  78. package/lib/components/Popover/index.js +14 -21
  79. package/lib/components/Switch/IconSwitch.d.ts +44 -2
  80. package/lib/components/Switch/IconSwitch.js +35 -28
  81. package/lib/components/Switch/Switch.js +1 -0
  82. package/lib/components/TextArea/TextArea.js +21 -4
  83. package/lib/components/Toggletip/index.d.ts +4 -1
  84. package/lib/components/Toggletip/index.js +4 -1
  85. package/lib/components/Tooltip/DefinitionTooltip.d.ts +4 -2
  86. package/lib/components/Tooltip/DefinitionTooltip.js +3 -1
  87. package/lib/components/Tooltip/Tooltip.d.ts +0 -3
  88. package/lib/components/Tooltip/Tooltip.js +2 -10
  89. package/lib/components/TreeView/TreeNode.d.ts +4 -2
  90. package/lib/components/TreeView/TreeNode.js +2 -1
  91. package/lib/components/UIShell/Header.d.ts +3 -3
  92. package/lib/components/UIShell/Header.js +7 -4
  93. package/lib/components/UIShell/HeaderPanel.js +2 -2
  94. package/lib/internal/Selection.d.ts +1 -0
  95. package/lib/internal/Selection.js +10 -0
  96. package/package.json +8 -8
  97. package/telemetry.yml +2 -9
@@ -472,6 +472,7 @@ function ActionableNotification({
472
472
  ['aria-label']: ariaLabel,
473
473
  // @ts-expect-error: deprecated prop
474
474
  ariaLabel: deprecatedAriaLabel,
475
+ caption,
475
476
  children,
476
477
  role = 'alertdialog',
477
478
  onActionButtonClick,
@@ -586,7 +587,10 @@ function ActionableNotification({
586
587
  as: "div",
587
588
  className: `${prefix}--actionable-notification__subtitle`,
588
589
  id: subtitleId
589
- }, subtitle), children))), /*#__PURE__*/React.createElement("div", {
590
+ }, subtitle), caption && /*#__PURE__*/React.createElement(Text, {
591
+ as: "div",
592
+ className: `${prefix}--actionable-notification__caption`
593
+ }, caption), children))), /*#__PURE__*/React.createElement("div", {
590
594
  className: `${prefix}--actionable-notification__button-wrapper`,
591
595
  ref: innerModal
592
596
  }, actionButtonLabel && /*#__PURE__*/React.createElement(NotificationActionButton, {
@@ -617,6 +621,10 @@ ActionableNotification.propTypes = {
617
621
  * Provide a description for "close" icon button that can be read by screen readers
618
622
  */
619
623
  ariaLabel: deprecate(PropTypes.string, 'This prop syntax has been deprecated. Please use the new `aria-label`.'),
624
+ /**
625
+ * Specify the caption
626
+ */
627
+ caption: PropTypes.string,
620
628
  /**
621
629
  * Specify the content
622
630
  */
@@ -51,6 +51,10 @@ export interface NumberInputProps extends Omit<React.InputHTMLAttributes<HTMLInp
51
51
  * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options
52
52
  */
53
53
  formatOptions?: NumberFormatOptions;
54
+ /**
55
+ * Provide the value stepping should begin at when the input is empty
56
+ */
57
+ stepStartValue?: number;
54
58
  /**
55
59
  * Provide text that is used alongside the control label for additional help
56
60
  */
@@ -76,6 +76,7 @@ const NumberInput = /*#__PURE__*/React.forwardRef(function NumberInput(props, fo
76
76
  defaultValue = type === 'number' ? 0 : NaN,
77
77
  warn = false,
78
78
  warnText = '',
79
+ stepStartValue = 0,
79
80
  value: controlledValue,
80
81
  ...rest
81
82
  } = props;
@@ -236,14 +237,14 @@ const NumberInput = /*#__PURE__*/React.forwardRef(function NumberInput(props, fo
236
237
  if (inputRef.current) {
237
238
  const currentValue = type === 'number' ? Number(inputRef.current.value) : numberValue;
238
239
  let rawValue;
239
- if (Number.isNaN(currentValue)) {
240
- // When the field is empty (NaN), incrementing begins at min,
241
- // decrementing begins at max.
242
- // When there's no min or max to use, it begins at 0.
243
- if (direction === `up` && min) {
240
+ if (Number.isNaN(currentValue) || !currentValue) {
241
+ if (typeof stepStartValue === 'number' && stepStartValue) {
242
+ rawValue = stepStartValue;
243
+ } else if (min && min < 0 && max && max > 0 || !max && !min || max) {
244
+ if (direction === `up`) rawValue = 1;
245
+ if (direction === `down`) rawValue = -1;
246
+ } else if (min && min > 0 && max && max > 0 || min) {
244
247
  rawValue = min;
245
- } else if (direction === `down` && max) {
246
- rawValue = max;
247
248
  } else {
248
249
  rawValue = 0;
249
250
  }
@@ -532,6 +533,10 @@ NumberInput.propTypes = {
532
533
  * The minimum value.
533
534
  */
534
535
  min: PropTypes.number,
536
+ /**
537
+ * Provide the value stepping should begin at when the input is empty
538
+ */
539
+ stepStartValue: PropTypes.number,
535
540
  /**
536
541
  * Provide an optional handler that is called when the input or stepper
537
542
  * buttons are blurred.
@@ -5,9 +5,13 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import React, { type ElementType } from 'react';
8
+ import type { PopoverAlignment } from '../../Popover';
8
9
  interface OverflowMenuProps {
9
10
  /**
10
- * **Experimental**: Will attempt to automatically align the floating element to avoid collisions with the viewport and being clipped by ancestor elements.
11
+ * **Experimental**: Will attempt to automatically align the floating element
12
+ * to avoid collisions with the viewport and being clipped by ancestor
13
+ * elements. Requires React v17+
14
+ * @see https://github.com/carbon-design-system/carbon/issues/18714
11
15
  */
12
16
  autoAlign?: boolean;
13
17
  /**
@@ -37,7 +41,7 @@ interface OverflowMenuProps {
37
41
  /**
38
42
  * Specify how the trigger tooltip should be aligned.
39
43
  */
40
- tooltipAlignment?: 'top' | 'top-left' | 'top-right' | 'bottom' | 'bottom-left' | 'bottom-right' | 'left' | 'right';
44
+ tooltipAlignment?: PopoverAlignment;
41
45
  /**
42
46
  * Specify a DOM node where the Menu should be rendered in. Defaults to document.body.
43
47
  */
@@ -132,7 +132,10 @@ const OverflowMenu = /*#__PURE__*/React.forwardRef(function OverflowMenu({
132
132
  });
133
133
  OverflowMenu.propTypes = {
134
134
  /**
135
- * **Experimental**: Will attempt to automatically align the floating element to avoid collisions with the viewport and being clipped by ancestor elements.
135
+ * **Experimental**: Will attempt to automatically align the floating element
136
+ * to avoid collisions with the viewport and being clipped by ancestor
137
+ * elements. Requires React v17+
138
+ * @see https://github.com/carbon-design-system/carbon/issues/18714
136
139
  */
137
140
  autoAlign: PropTypes.bool,
138
141
  /**
@@ -26,7 +26,10 @@ export interface PopoverBaseProps {
26
26
  */
27
27
  align?: PopoverAlignment;
28
28
  /**
29
- * Will auto-align the popover on first render if it is not visible. This prop is currently experimental and is subject to future changes.
29
+ * Will auto-align the popover on first render if it is not visible. This prop
30
+ * is currently experimental and is subject to future changes. Requires
31
+ * React v17+
32
+ * @see https://github.com/carbon-design-system/carbon/issues/18714
30
33
  */
31
34
  autoAlign?: boolean;
32
35
  /**
@@ -9,7 +9,7 @@ import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js
9
9
  import cx from 'classnames';
10
10
  import PropTypes from 'prop-types';
11
11
  import deprecateValuesWithin from '../../prop-types/deprecateValuesWithin.js';
12
- import React, { useRef, useEffect, useMemo } from 'react';
12
+ import React, { useRef, useMemo, useEffect } from 'react';
13
13
  import useIsomorphicEffect from '../../internal/useIsomorphicEffect.js';
14
14
  import { useMergedRefs } from '../../internal/useMergedRefs.js';
15
15
  import { usePrefix } from '../../internal/usePrefix.js';
@@ -62,7 +62,14 @@ forwardRef) {
62
62
  // The `Popover` should close whenever it and its children loses focus
63
63
  useEvent(popover, 'focusout', event => {
64
64
  const relatedTarget = event.relatedTarget;
65
- if (!popover.current?.contains(relatedTarget)) {
65
+ if (!relatedTarget) {
66
+ return;
67
+ }
68
+ const isOutsideMainContainer = !popover.current?.contains(relatedTarget);
69
+ const isOutsideFloating = enableFloatingStyles && refs.floating.current ? !refs.floating.current.contains(relatedTarget) : true;
70
+
71
+ // Only close if focus moved outside both containers
72
+ if (isOutsideMainContainer && isOutsideFloating) {
66
73
  onRequestClose?.();
67
74
  }
68
75
  });
@@ -291,7 +298,10 @@ Popover.propTypes = {
291
298
  */
292
299
  as: PropTypes.oneOfType([PropTypes.string, PropTypes.elementType]),
293
300
  /**
294
- * Will auto-align the popover on first render if it is not visible. This prop is currently experimental and is subject to future changes.
301
+ * Will auto-align the popover on first render if it is not visible. This prop
302
+ * is currently experimental and is subject to future changes. Requires
303
+ * React v17+
304
+ * @see https://github.com/carbon-design-system/carbon/issues/18714
295
305
  */
296
306
  autoAlign: PropTypes.bool,
297
307
  /**
@@ -351,29 +361,12 @@ function PopoverContentRenderFunction(
351
361
  caretRef,
352
362
  autoAlign
353
363
  } = React.useContext(PopoverContext);
354
- const textRef = useRef(null);
355
- const [isMultiLine, setIsMultiLine] = React.useState(false);
356
- const ref = useMergedRefs([setFloating, textRef, forwardRef]);
364
+ const ref = useMergedRefs([setFloating, forwardRef]);
357
365
  const enableFloatingStyles = useFeatureFlag('enable-v12-dynamic-floating-styles') || autoAlign;
358
- useEffect(() => {
359
- checkIfMultiLine();
360
- }, [children]);
361
- const checkIfMultiLine = () => {
362
- const el = textRef.current;
363
- if (el) {
364
- const style = getComputedStyle(el);
365
- const lineHeight = parseFloat(style.lineHeight);
366
- const height = el.offsetHeight;
367
- const lines = Math.floor(height / lineHeight);
368
- setIsMultiLine(lines > 1);
369
- }
370
- };
371
366
  return /*#__PURE__*/React.createElement("span", _extends({}, rest, {
372
367
  className: `${prefix}--popover`
373
368
  }), /*#__PURE__*/React.createElement("span", {
374
- className: cx(`${prefix}--popover-content`, className, {
375
- [`${prefix}--tooltip-content--multiline`]: isMultiLine
376
- }),
369
+ className: cx(`${prefix}--popover-content`, className),
377
370
  ref: ref
378
371
  }, children, enableFloatingStyles && /*#__PURE__*/React.createElement("span", {
379
372
  className: cx({
@@ -1,3 +1,45 @@
1
- export default IconSwitch;
2
- declare const IconSwitch: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
1
+ /**
2
+ * Copyright IBM Corp. 2016, 2023
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
3
7
  import React from 'react';
8
+ import { type IconButtonProps } from '../IconButton';
9
+ import type { SwitchEventHandlersParams } from './Switch';
10
+ interface IconSwitchProps extends Omit<IconButtonProps, 'onClick' | 'onKeyDown' | 'label' | 'name'> {
11
+ /**
12
+ * The index of the `IconSwitch`.
13
+ *
14
+ * Reserved for usage in `ContentSwitcher`.
15
+ */
16
+ index?: number;
17
+ /**
18
+ * The name of the `IconSwitch`.
19
+ */
20
+ name?: string | number;
21
+ /**
22
+ * A handler that is invoked when a user clicks on the control.
23
+ *
24
+ * Reserved for usage in `ContentSwitcher`.
25
+ */
26
+ onClick?: (params: SwitchEventHandlersParams) => void;
27
+ /**
28
+ * A handler that is invoked on the key down event for the control.
29
+ *
30
+ * Reserved for usage in `ContentSwitcher`.
31
+ */
32
+ onKeyDown?: (params: SwitchEventHandlersParams) => void;
33
+ /**
34
+ * Whether the `IconSwitch` is selected.
35
+ *
36
+ * Reserved for usage in `ContentSwitcher`.
37
+ */
38
+ selected?: boolean;
39
+ /**
40
+ * `Tooltip` text.
41
+ */
42
+ text?: string;
43
+ }
44
+ declare const IconSwitch: React.ForwardRefExoticComponent<IconSwitchProps & React.RefAttributes<HTMLButtonElement>>;
45
+ export default IconSwitch;
@@ -7,13 +7,14 @@
7
7
 
8
8
  import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
9
  import PropTypes from 'prop-types';
10
- import React, { useState } from 'react';
10
+ import React, { forwardRef, useState } from 'react';
11
11
  import cx from 'classnames';
12
12
  import { IconButton } from '../IconButton/index.js';
13
13
  import { usePrefix } from '../../internal/usePrefix.js';
14
+ import { noopFn } from '../../internal/noopFn.js';
14
15
 
15
- const noopFn = () => {};
16
- const IconSwitch = /*#__PURE__*/React.forwardRef(function Switch(props, tabRef) {
16
+ const frFn = forwardRef;
17
+ const IconSwitch = frFn((props, ref) => {
17
18
  const {
18
19
  align,
19
20
  children,
@@ -32,8 +33,8 @@ const IconSwitch = /*#__PURE__*/React.forwardRef(function Switch(props, tabRef)
32
33
  } = props;
33
34
  const prefix = usePrefix();
34
35
  const [isHovered, setIsHovered] = useState(false);
35
- const handleClick = e => {
36
- e.preventDefault();
36
+ const handleClick = event => {
37
+ event.preventDefault();
37
38
  onClick({
38
39
  index,
39
40
  name,
@@ -41,6 +42,7 @@ const IconSwitch = /*#__PURE__*/React.forwardRef(function Switch(props, tabRef)
41
42
  });
42
43
  };
43
44
  const handleKeyDown = event => {
45
+ // TODO: `which` was deprecated years ago. When can its usage be deleted?
44
46
  const key = event.key || event.which;
45
47
  onKeyDown({
46
48
  index,
@@ -62,20 +64,10 @@ const IconSwitch = /*#__PURE__*/React.forwardRef(function Switch(props, tabRef)
62
64
  [`${prefix}--content-switcher-popover--selected`]: selected,
63
65
  [`${prefix}--content-switcher-popover--disabled`]: disabled
64
66
  });
65
- const commonProps = {
66
- onClick: handleClick,
67
- onKeyDown: handleKeyDown,
68
- className: classes,
69
- disabled,
70
- align,
71
- enterDelayMs,
72
- leaveDelayMs,
73
- size
74
- };
75
67
  return /*#__PURE__*/React.createElement(IconButton, _extends({
76
68
  label: text,
77
69
  type: "button",
78
- ref: tabRef,
70
+ ref: ref,
79
71
  role: "tab",
80
72
  tabIndex: selected || isHovered ? 0 : -1,
81
73
  onMouseEnter: handleMouseEnter,
@@ -85,7 +77,16 @@ const IconSwitch = /*#__PURE__*/React.forwardRef(function Switch(props, tabRef)
85
77
  "aria-selected": selected,
86
78
  "aria-label": text,
87
79
  wrapperClasses: iconButtonClasses
88
- }, other, commonProps), children);
80
+ }, other, {
81
+ align: align,
82
+ className: classes,
83
+ disabled: disabled,
84
+ enterDelayMs: enterDelayMs,
85
+ leaveDelayMs: leaveDelayMs,
86
+ onClick: handleClick,
87
+ onKeyDown: handleKeyDown,
88
+ size: size
89
+ }), children);
89
90
  });
90
91
  IconSwitch.displayName = 'IconSwitch';
91
92
  IconSwitch.propTypes = {
@@ -94,15 +95,15 @@ IconSwitch.propTypes = {
94
95
  */
95
96
  align: PropTypes.oneOf(['top', 'top-left', 'top-right', 'bottom', 'bottom-left', 'bottom-right', 'left', 'right']),
96
97
  /**
97
- * Provide child elements to be rendered inside of the Switch
98
+ * Children to be rendered inside of the `IconSwitch`.
98
99
  */
99
100
  children: PropTypes.node,
100
101
  /**
101
- * Specify an optional className to be added to your Switch
102
+ * Specify an optional className to be added to your `IconSwitch`.
102
103
  */
103
104
  className: PropTypes.string,
104
105
  /**
105
- * Specify whether or not the Switch should be disabled
106
+ * Whether the `IconSwitch` should be disabled.
106
107
  */
107
108
  disabled: PropTypes.bool,
108
109
  /**
@@ -110,8 +111,9 @@ IconSwitch.propTypes = {
110
111
  */
111
112
  enterDelayMs: PropTypes.number,
112
113
  /**
113
- * The index of your Switch in your ContentSwitcher that is used for event handlers.
114
- * Reserved for usage in ContentSwitcher
114
+ * The index of the `IconSwitch`.
115
+ *
116
+ * Reserved for usage in `ContentSwitcher`.
115
117
  */
116
118
  index: PropTypes.number,
117
119
  /**
@@ -119,29 +121,34 @@ IconSwitch.propTypes = {
119
121
  */
120
122
  leaveDelayMs: PropTypes.number,
121
123
  /**
122
- * Provide the name of your Switch that is used for event handlers
124
+ * The name of the `IconSwitch`.
123
125
  */
124
126
  name: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
125
127
  /**
126
128
  * A handler that is invoked when a user clicks on the control.
127
- * Reserved for usage in ContentSwitcher
129
+ *
130
+ * Reserved for usage in `ContentSwitcher`.
128
131
  */
129
132
  onClick: PropTypes.func,
130
133
  /**
131
134
  * A handler that is invoked on the key down event for the control.
132
- * Reserved for usage in ContentSwitcher
135
+ *
136
+ * Reserved for usage in `ContentSwitcher`.
133
137
  */
134
138
  onKeyDown: PropTypes.func,
135
139
  /**
136
- * Whether your Switch is selected. Reserved for usage in ContentSwitcher
140
+ * Whether the `IconSwitch` is selected.
141
+ *
142
+ * Reserved for usage in `ContentSwitcher`.
137
143
  */
138
144
  selected: PropTypes.bool,
145
+ // TODO: Icon only variant of what? Isn't the `IconSwitch` always icon only?
139
146
  /**
140
147
  * Passed in from `ContentSwitcher` to render icon-only variant
141
148
  */
142
149
  size: PropTypes.oneOf(['sm', 'md', 'lg']),
143
150
  /**
144
- * Provide the visible text displayed by the Tooltip
151
+ * `Tooltip` text.
145
152
  */
146
153
  text: PropTypes.string
147
154
  };
@@ -35,6 +35,7 @@ const Switch = /*#__PURE__*/React.forwardRef(function Switch(props, tabRef) {
35
35
  });
36
36
  };
37
37
  const handleKeyDown = event => {
38
+ // TODO: `which` was deprecated years ago. When can its usage be deleted?
38
39
  const key = event.key || event.which;
39
40
  onKeyDown?.({
40
41
  index,
@@ -59,7 +59,11 @@ const TextArea = frFn((props, forwardRef) => {
59
59
  value
60
60
  } = other;
61
61
  const textAreaInstanceId = useId();
62
+ const wrapperRef = useRef(null);
62
63
  const textareaRef = useRef(null);
64
+ const helperTextRef = useRef(null);
65
+ const errorTextRef = useRef(null);
66
+ const warnTextRef = useRef(null);
63
67
  const ref = useMergedRefs([forwardRef, textareaRef]);
64
68
  function getInitialTextCount() {
65
69
  const targetValue = defaultValue || value || textareaRef.current?.value || '';
@@ -76,13 +80,20 @@ const TextArea = frFn((props, forwardRef) => {
76
80
  // eslint-disable-next-line react-hooks/exhaustive-deps
77
81
  }, [value, defaultValue, counterMode]);
78
82
  useIsomorphicEffect(() => {
83
+ const measuredWidth = wrapperRef.current?.scrollWidth;
79
84
  if (other.cols && textareaRef.current) {
80
85
  textareaRef.current.style.width = '';
81
86
  textareaRef.current.style.resize = 'none';
82
87
  } else if (textareaRef.current) {
83
88
  textareaRef.current.style.width = `100%`;
84
89
  }
85
- }, [other.cols]);
90
+ [helperTextRef, errorTextRef, warnTextRef].forEach(r => {
91
+ if (r.current) {
92
+ r.current.style.maxWidth = `${measuredWidth}px`;
93
+ r.current.style.overflowWrap = 'break-word';
94
+ }
95
+ });
96
+ }, [other.cols, invalid, warn]);
86
97
  const textareaProps = {
87
98
  id,
88
99
  onKeyDown: evt => {
@@ -190,21 +201,26 @@ const TextArea = frFn((props, forwardRef) => {
190
201
  const helper = helperText ? /*#__PURE__*/React.createElement(Text, {
191
202
  as: "div",
192
203
  id: helperId,
193
- className: helperTextClasses
204
+ className: helperTextClasses,
205
+ ref: helperTextRef
194
206
  }, helperText) : null;
195
207
  const errorId = id + '-error-msg';
196
208
  const error = invalid ? /*#__PURE__*/React.createElement(Text, {
197
209
  as: "div",
198
210
  role: "alert",
199
211
  className: `${prefix}--form-requirement`,
200
- id: errorId
212
+ id: errorId,
213
+ ref: errorTextRef
201
214
  }, invalidText, isFluid && /*#__PURE__*/React.createElement(WarningFilled, {
202
215
  className: `${prefix}--text-area__invalid-icon`
203
216
  })) : null;
217
+ const warnId = id + '-warn-msg';
204
218
  const warning = warn ? /*#__PURE__*/React.createElement(Text, {
205
219
  as: "div",
206
220
  role: "alert",
207
- className: `${prefix}--form-requirement`
221
+ className: `${prefix}--form-requirement`,
222
+ id: warnId,
223
+ ref: warnTextRef
208
224
  }, warnText, isFluid && /*#__PURE__*/React.createElement(WarningAltFilled, {
209
225
  className: `${prefix}--text-area__invalid-icon ${prefix}--text-area__invalid-icon--warning`
210
226
  })) : null;
@@ -270,6 +286,7 @@ const TextArea = frFn((props, forwardRef) => {
270
286
  }, /*#__PURE__*/React.createElement("div", {
271
287
  className: `${prefix}--text-area__label-wrapper`
272
288
  }, label, counter), /*#__PURE__*/React.createElement("div", {
289
+ ref: wrapperRef,
273
290
  className: textAreaWrapperClasses,
274
291
  "data-invalid": invalid || null
275
292
  }, invalid && !isFluid && /*#__PURE__*/React.createElement(WarningFilled, {
@@ -67,7 +67,10 @@ export declare namespace Toggletip {
67
67
  */
68
68
  as: PropTypes.Requireable<PropTypes.ReactComponentLike>;
69
69
  /**
70
- * Will auto-align the popover on first render if it is not visible. This prop is currently experimental and is subject to future changes.
70
+ * Will auto-align the popover on first render if it is not visible. This prop
71
+ * is currently experimental and is subject to future changes. Requires
72
+ * React v17+
73
+ * @see https://github.com/carbon-design-system/carbon/issues/18714
71
74
  */
72
75
  autoAlign: PropTypes.Requireable<boolean>;
73
76
  /**
@@ -185,7 +185,10 @@ Toggletip.propTypes = {
185
185
  */
186
186
  as: PropTypes.elementType,
187
187
  /**
188
- * Will auto-align the popover on first render if it is not visible. This prop is currently experimental and is subject to future changes.
188
+ * Will auto-align the popover on first render if it is not visible. This prop
189
+ * is currently experimental and is subject to future changes. Requires
190
+ * React v17+
191
+ * @see https://github.com/carbon-design-system/carbon/issues/18714
189
192
  */
190
193
  autoAlign: PropTypes.bool,
191
194
  /**
@@ -12,13 +12,15 @@ export interface DefinitionTooltipProps extends Omit<React.ButtonHTMLAttributes<
12
12
  */
13
13
  align?: PopoverAlignment;
14
14
  /**
15
- * Will auto-align Definition Tooltip. This prop is currently experimental and is subject to future changes.
15
+ * Will auto-align Definition Tooltip. This prop is currently experimental
16
+ * and is subject to future changes. Requires React v17+
17
+ * @see https://github.com/carbon-design-system/carbon/issues/18714
16
18
  */
17
19
  autoAlign?: boolean;
18
20
  /**
19
21
  * The `children` prop will be used as the value that is being defined
20
22
  */
21
- children?: React.ReactNode;
23
+ children: React.ReactNode;
22
24
  /**
23
25
  * Specify an optional className to be applied to the container node
24
26
  */
@@ -101,7 +101,9 @@ DefinitionTooltip.propTypes = {
101
101
  // new values to match floating-ui
102
102
  'top-start', 'top-end', 'bottom-start', 'bottom-end', 'left-end', 'left-start', 'right-end', 'right-start']),
103
103
  /**
104
- * Will auto-align the popover. This prop is currently experimental and is subject to future changes.
104
+ * Will auto-align the popover. This prop is currently experimental and is
105
+ * subject to future changes. Requires React v17+
106
+ * @see https://github.com/carbon-design-system/carbon/issues/18714
105
107
  */
106
108
  autoAlign: PropTypes.bool,
107
109
  /**
@@ -54,9 +54,6 @@ interface TooltipBaseProps {
54
54
  /**
55
55
  * Provide the label to be rendered inside of the Tooltip. The label will use
56
56
  * `aria-labelledby` and will fully describe the child node that is provided.
57
- * If the child already has an `aria-label`, the tooltip will not apply
58
- * `aria-labelledby`. If the child has its own `aria-labelledby`, that value
59
- * will be kept. Otherwise, the tooltip will use its own ID to label the child.
60
57
  * This means that if you have text in the child node, that it will not be
61
58
  * announced to the screen reader.
62
59
  *
@@ -46,20 +46,12 @@ const Tooltip = /*#__PURE__*/React.forwardRef(({
46
46
  const prefix = usePrefix();
47
47
  const child = React.Children.only(children);
48
48
  const {
49
- 'aria-label': ariaLabel,
50
49
  'aria-labelledby': ariaLabelledBy,
51
50
  'aria-describedby': ariaDescribedBy
52
51
  } = child?.props ?? {};
53
52
  const hasLabel = !!label;
54
- const hasAriaLabel = typeof ariaLabel === 'string' ? ariaLabel.trim() !== '' : false;
55
-
56
- // An `aria-label` takes precedence over `aria-describedby`, but when it's
57
- // needed and the user doesn't specify one, the fallback `id` is used.
58
- const labelledBy = hasAriaLabel ? undefined : hasLabel ? ariaLabelledBy ?? id : undefined;
59
-
60
- // If `aria-label` is present, use any provided `aria-describedby`.
61
- // If not, fallback to child's `aria-describedby` or the tooltip `id` if needed.
62
- const describedBy = hasAriaLabel ? ariaDescribedBy : ariaDescribedBy ?? (!hasLabel && !ariaLabelledBy ? id : undefined);
53
+ const labelledBy = ariaLabelledBy ?? (hasLabel ? id : undefined);
54
+ const describedBy = ariaDescribedBy ?? (!hasLabel ? id : undefined);
63
55
  const triggerProps = {
64
56
  onFocus: () => !focusByMouse && setOpen(true),
65
57
  onBlur: () => {
@@ -88,7 +88,8 @@ export type TreeNodeProps = {
88
88
  /**
89
89
  * **Experimental**: Will attempt to automatically align the floating
90
90
  * element to avoid collisions with the viewport and being clipped by
91
- * ancestor elements.
91
+ * ancestor elements. Requires React v17+
92
+ * @see https://github.com/carbon-design-system/carbon/issues/18714
92
93
  */
93
94
  autoAlign?: boolean;
94
95
  } & Omit<React.LiHTMLAttributes<HTMLElement>, 'onSelect'>;
@@ -173,7 +174,8 @@ declare const TreeNode: React.ForwardRefExoticComponent<{
173
174
  /**
174
175
  * **Experimental**: Will attempt to automatically align the floating
175
176
  * element to avoid collisions with the viewport and being clipped by
176
- * ancestor elements.
177
+ * ancestor elements. Requires React v17+
178
+ * @see https://github.com/carbon-design-system/carbon/issues/18714
177
179
  */
178
180
  autoAlign?: boolean;
179
181
  } & Omit<React.LiHTMLAttributes<HTMLElement>, "onSelect"> & React.RefAttributes<HTMLElement>>;
@@ -490,7 +490,8 @@ TreeNode.propTypes = {
490
490
  /**
491
491
  * **Experimental**: Will attempt to automatically align the floating
492
492
  * element to avoid collisions with the viewport and being clipped by
493
- * ancestor elements.
493
+ * ancestor elements. Requires React v17+
494
+ * @see https://github.com/carbon-design-system/carbon/issues/18714
494
495
  */
495
496
  autoAlign: PropTypes.bool
496
497
  };
@@ -8,15 +8,15 @@ import React, { ReactNode } from 'react';
8
8
  export interface HeaderProps {
9
9
  children?: ReactNode;
10
10
  /**
11
- * Required props for the accessibility label of the header
11
+ * Optionally provide aria-label
12
12
  */
13
13
  'aria-label'?: string;
14
14
  /**
15
- * Required props for the accessibility label of the header
15
+ * Optionally provide aria-labelledby
16
16
  */
17
17
  'aria-labelledby'?: string;
18
18
  /**
19
- * Optionally provide a custom class name that is applied to the underlying <header>
19
+ * Optionally provide a custom class name that is applied to the underlying header
20
20
  */
21
21
  className?: string;
22
22
  }
@@ -9,7 +9,6 @@ import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js
9
9
  import cx from 'classnames';
10
10
  import PropTypes from 'prop-types';
11
11
  import React from 'react';
12
- import { AriaLabelPropType } from '../../prop-types/AriaPropTypes.js';
13
12
  import { usePrefix } from '../../internal/usePrefix.js';
14
13
 
15
14
  const Header = ({
@@ -25,11 +24,15 @@ const Header = ({
25
24
  };
26
25
  Header.propTypes = {
27
26
  /**
28
- * Required props for the accessibility label of the header
27
+ * Optionally provide aria-label
29
28
  */
30
- ...AriaLabelPropType,
29
+ 'aria-label': PropTypes.string,
31
30
  /**
32
- * Optionally provide a custom class name that is applied to the underlying <header>
31
+ * Optionally provide aria-labelledby
32
+ */
33
+ 'aria-labelledby': PropTypes.string,
34
+ /**
35
+ * Optionally provide a custom class name that is applied to the underlying header
33
36
  */
34
37
  className: PropTypes.string
35
38
  };
@@ -15,8 +15,8 @@ import { match } from '../../internal/keyboard/match.js';
15
15
  import { useWindowEvent } from '../../internal/useEvent.js';
16
16
  import { useMergedRefs } from '../../internal/useMergedRefs.js';
17
17
  import Switcher from './Switcher.js';
18
+ import { noopFn } from '../../internal/noopFn.js';
18
19
 
19
- const noopFn = () => {};
20
20
  const HeaderPanel = /*#__PURE__*/React.forwardRef(function HeaderPanel({
21
21
  children,
22
22
  className: customClassName,