@carbon/react 1.87.1-rc.0 → 1.88.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 (95) hide show
  1. package/.playwright/INTERNAL_AVT_REPORT_DO_NOT_USE.json +792 -792
  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/ContentSwitcher/ContentSwitcher.d.ts +1 -6
  10. package/es/components/Copy/Copy.d.ts +9 -5
  11. package/es/components/Copy/Copy.js +3 -1
  12. package/es/components/CopyButton/CopyButton.d.ts +9 -5
  13. package/es/components/CopyButton/CopyButton.js +3 -1
  14. package/es/components/Dropdown/Dropdown.d.ts +4 -1
  15. package/es/components/Dropdown/Dropdown.js +4 -1
  16. package/es/components/FileUploader/FileUploaderButton.js +6 -3
  17. package/es/components/IconButton/index.d.ts +6 -4
  18. package/es/components/IconButton/index.js +3 -4
  19. package/es/components/MultiSelect/FilterableMultiSelect.d.ts +5 -2
  20. package/es/components/MultiSelect/FilterableMultiSelect.js +101 -22
  21. package/es/components/MultiSelect/MultiSelect.d.ts +2 -1
  22. package/es/components/MultiSelect/MultiSelect.js +2 -1
  23. package/es/components/Notification/Notification.d.ts +9 -1
  24. package/es/components/Notification/Notification.js +9 -1
  25. package/es/components/NumberInput/NumberInput.d.ts +4 -0
  26. package/es/components/NumberInput/NumberInput.js +12 -7
  27. package/es/components/OverflowMenu/next/index.d.ts +6 -2
  28. package/es/components/OverflowMenu/next/index.js +4 -1
  29. package/es/components/Popover/index.d.ts +4 -1
  30. package/es/components/Popover/index.js +12 -2
  31. package/es/components/Switch/IconSwitch.d.ts +44 -2
  32. package/es/components/Switch/IconSwitch.js +34 -27
  33. package/es/components/Switch/Switch.js +1 -0
  34. package/es/components/Toggletip/index.d.ts +4 -1
  35. package/es/components/Toggletip/index.js +4 -1
  36. package/es/components/Tooltip/DefinitionTooltip.d.ts +4 -2
  37. package/es/components/Tooltip/DefinitionTooltip.js +3 -1
  38. package/es/components/Tooltip/Tooltip.d.ts +0 -3
  39. package/es/components/Tooltip/Tooltip.js +2 -10
  40. package/es/components/TreeView/TreeContext.d.ts +1 -2
  41. package/es/components/TreeView/TreeNode.d.ts +12 -8
  42. package/es/components/TreeView/TreeNode.js +3 -9
  43. package/es/components/TreeView/TreeView.d.ts +7 -5
  44. package/es/components/TreeView/TreeView.js +20 -22
  45. package/es/components/UIShell/HeaderPanel.js +1 -1
  46. package/es/internal/Selection.d.ts +1 -0
  47. package/es/internal/Selection.js +10 -0
  48. package/lib/components/AILabel/index.d.ts +4 -3
  49. package/lib/components/AILabel/index.js +3 -1
  50. package/lib/components/Button/Button.js +3 -1
  51. package/lib/components/CodeSnippet/CodeSnippet.d.ts +9 -5
  52. package/lib/components/CodeSnippet/CodeSnippet.js +3 -1
  53. package/lib/components/ComboBox/ComboBox.d.ts +2 -1
  54. package/lib/components/ComboBox/ComboBox.js +2 -1
  55. package/lib/components/ContentSwitcher/ContentSwitcher.d.ts +1 -6
  56. package/lib/components/Copy/Copy.d.ts +9 -5
  57. package/lib/components/Copy/Copy.js +3 -1
  58. package/lib/components/CopyButton/CopyButton.d.ts +9 -5
  59. package/lib/components/CopyButton/CopyButton.js +3 -1
  60. package/lib/components/Dropdown/Dropdown.d.ts +4 -1
  61. package/lib/components/Dropdown/Dropdown.js +4 -1
  62. package/lib/components/FileUploader/FileUploaderButton.js +6 -3
  63. package/lib/components/IconButton/index.d.ts +6 -4
  64. package/lib/components/IconButton/index.js +3 -4
  65. package/lib/components/MultiSelect/FilterableMultiSelect.d.ts +5 -2
  66. package/lib/components/MultiSelect/FilterableMultiSelect.js +100 -21
  67. package/lib/components/MultiSelect/MultiSelect.d.ts +2 -1
  68. package/lib/components/MultiSelect/MultiSelect.js +2 -1
  69. package/lib/components/Notification/Notification.d.ts +9 -1
  70. package/lib/components/Notification/Notification.js +9 -1
  71. package/lib/components/NumberInput/NumberInput.d.ts +4 -0
  72. package/lib/components/NumberInput/NumberInput.js +12 -7
  73. package/lib/components/OverflowMenu/next/index.d.ts +6 -2
  74. package/lib/components/OverflowMenu/next/index.js +4 -1
  75. package/lib/components/Popover/index.d.ts +4 -1
  76. package/lib/components/Popover/index.js +12 -2
  77. package/lib/components/Switch/IconSwitch.d.ts +44 -2
  78. package/lib/components/Switch/IconSwitch.js +35 -28
  79. package/lib/components/Switch/Switch.js +1 -0
  80. package/lib/components/Toggletip/index.d.ts +4 -1
  81. package/lib/components/Toggletip/index.js +4 -1
  82. package/lib/components/Tooltip/DefinitionTooltip.d.ts +4 -2
  83. package/lib/components/Tooltip/DefinitionTooltip.js +3 -1
  84. package/lib/components/Tooltip/Tooltip.d.ts +0 -3
  85. package/lib/components/Tooltip/Tooltip.js +2 -10
  86. package/lib/components/TreeView/TreeContext.d.ts +1 -2
  87. package/lib/components/TreeView/TreeNode.d.ts +12 -8
  88. package/lib/components/TreeView/TreeNode.js +3 -9
  89. package/lib/components/TreeView/TreeView.d.ts +7 -5
  90. package/lib/components/TreeView/TreeView.js +20 -22
  91. package/lib/components/UIShell/HeaderPanel.js +2 -2
  92. package/lib/internal/Selection.d.ts +1 -0
  93. package/lib/internal/Selection.js +10 -0
  94. package/package.json +7 -7
  95. package/telemetry.yml +2 -9
@@ -367,6 +367,10 @@ export interface ActionableNotificationProps extends HTMLAttributes<HTMLDivEleme
367
367
  * Provide a description for "close" icon button that can be read by screen readers
368
368
  */
369
369
  'aria-label'?: string;
370
+ /**
371
+ * Specify the caption
372
+ */
373
+ caption?: string;
370
374
  /**
371
375
  * Specify the content
372
376
  */
@@ -430,7 +434,7 @@ export interface ActionableNotificationProps extends HTMLAttributes<HTMLDivEleme
430
434
  */
431
435
  title?: string;
432
436
  }
433
- export declare function ActionableNotification({ actionButtonLabel, ['aria-label']: ariaLabel, ariaLabel: deprecatedAriaLabel, children, role, onActionButtonClick, onClose, onCloseButtonClick, statusIconDescription, className, inline, kind, lowContrast, hideCloseButton, hasFocus, closeOnEscape, title, subtitle, ...rest }: ActionableNotificationProps): import("react/jsx-runtime").JSX.Element | null;
437
+ export declare function ActionableNotification({ actionButtonLabel, ['aria-label']: ariaLabel, ariaLabel: deprecatedAriaLabel, caption, children, role, onActionButtonClick, onClose, onCloseButtonClick, statusIconDescription, className, inline, kind, lowContrast, hideCloseButton, hasFocus, closeOnEscape, title, subtitle, ...rest }: ActionableNotificationProps): import("react/jsx-runtime").JSX.Element | null;
434
438
  export declare namespace ActionableNotification {
435
439
  var propTypes: {
436
440
  /**
@@ -446,6 +450,10 @@ export declare namespace ActionableNotification {
446
450
  * Provide a description for "close" icon button that can be read by screen readers
447
451
  */
448
452
  ariaLabel: (props: Record<string, any>, propName: string, componentName: string, ...rest: any[]) => any;
453
+ /**
454
+ * Specify the caption
455
+ */
456
+ caption: PropTypes.Requireable<string>;
449
457
  /**
450
458
  * Specify the content
451
459
  */
@@ -474,6 +474,7 @@ function ActionableNotification({
474
474
  ['aria-label']: ariaLabel,
475
475
  // @ts-expect-error: deprecated prop
476
476
  ariaLabel: deprecatedAriaLabel,
477
+ caption,
477
478
  children,
478
479
  role = 'alertdialog',
479
480
  onActionButtonClick,
@@ -588,7 +589,10 @@ function ActionableNotification({
588
589
  as: "div",
589
590
  className: `${prefix}--actionable-notification__subtitle`,
590
591
  id: subtitleId
591
- }, subtitle), children))), /*#__PURE__*/React.createElement("div", {
592
+ }, subtitle), caption && /*#__PURE__*/React.createElement(Text.Text, {
593
+ as: "div",
594
+ className: `${prefix}--actionable-notification__caption`
595
+ }, caption), children))), /*#__PURE__*/React.createElement("div", {
592
596
  className: `${prefix}--actionable-notification__button-wrapper`,
593
597
  ref: innerModal
594
598
  }, actionButtonLabel && /*#__PURE__*/React.createElement(NotificationActionButton, {
@@ -619,6 +623,10 @@ ActionableNotification.propTypes = {
619
623
  * Provide a description for "close" icon button that can be read by screen readers
620
624
  */
621
625
  ariaLabel: deprecate.deprecate(PropTypes.string, 'This prop syntax has been deprecated. Please use the new `aria-label`.'),
626
+ /**
627
+ * Specify the caption
628
+ */
629
+ caption: PropTypes.string,
622
630
  /**
623
631
  * Specify the content
624
632
  */
@@ -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
  */
@@ -78,6 +78,7 @@ const NumberInput = /*#__PURE__*/React.forwardRef(function NumberInput(props, fo
78
78
  defaultValue = type === 'number' ? 0 : NaN,
79
79
  warn = false,
80
80
  warnText = '',
81
+ stepStartValue = 0,
81
82
  value: controlledValue,
82
83
  ...rest
83
84
  } = props;
@@ -238,14 +239,14 @@ const NumberInput = /*#__PURE__*/React.forwardRef(function NumberInput(props, fo
238
239
  if (inputRef.current) {
239
240
  const currentValue = type === 'number' ? Number(inputRef.current.value) : numberValue;
240
241
  let rawValue;
241
- if (Number.isNaN(currentValue)) {
242
- // When the field is empty (NaN), incrementing begins at min,
243
- // decrementing begins at max.
244
- // When there's no min or max to use, it begins at 0.
245
- if (direction === `up` && min) {
242
+ if (Number.isNaN(currentValue) || !currentValue) {
243
+ if (typeof stepStartValue === 'number' && stepStartValue) {
244
+ rawValue = stepStartValue;
245
+ } else if (min && min < 0 && max && max > 0 || !max && !min || max) {
246
+ if (direction === `up`) rawValue = 1;
247
+ if (direction === `down`) rawValue = -1;
248
+ } else if (min && min > 0 && max && max > 0 || min) {
246
249
  rawValue = min;
247
- } else if (direction === `down` && max) {
248
- rawValue = max;
249
250
  } else {
250
251
  rawValue = 0;
251
252
  }
@@ -534,6 +535,10 @@ NumberInput.propTypes = {
534
535
  * The minimum value.
535
536
  */
536
537
  min: PropTypes.number,
538
+ /**
539
+ * Provide the value stepping should begin at when the input is empty
540
+ */
541
+ stepStartValue: PropTypes.number,
537
542
  /**
538
543
  * Provide an optional handler that is called when the input or stepper
539
544
  * 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
  */
@@ -134,7 +134,10 @@ const OverflowMenu = /*#__PURE__*/React.forwardRef(function OverflowMenu({
134
134
  });
135
135
  OverflowMenu.propTypes = {
136
136
  /**
137
- * **Experimental**: Will attempt to automatically align the floating element to avoid collisions with the viewport and being clipped by ancestor elements.
137
+ * **Experimental**: Will attempt to automatically align the floating element
138
+ * to avoid collisions with the viewport and being clipped by ancestor
139
+ * elements. Requires React v17+
140
+ * @see https://github.com/carbon-design-system/carbon/issues/18714
138
141
  */
139
142
  autoAlign: PropTypes.bool,
140
143
  /**
@@ -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
  /**
@@ -64,7 +64,14 @@ forwardRef) {
64
64
  // The `Popover` should close whenever it and its children loses focus
65
65
  useEvent.useEvent(popover, 'focusout', event => {
66
66
  const relatedTarget = event.relatedTarget;
67
- if (!popover.current?.contains(relatedTarget)) {
67
+ if (!relatedTarget) {
68
+ return;
69
+ }
70
+ const isOutsideMainContainer = !popover.current?.contains(relatedTarget);
71
+ const isOutsideFloating = enableFloatingStyles && refs.floating.current ? !refs.floating.current.contains(relatedTarget) : true;
72
+
73
+ // Only close if focus moved outside both containers
74
+ if (isOutsideMainContainer && isOutsideFloating) {
68
75
  onRequestClose?.();
69
76
  }
70
77
  });
@@ -293,7 +300,10 @@ Popover.propTypes = {
293
300
  */
294
301
  as: PropTypes.oneOfType([PropTypes.string, PropTypes.elementType]),
295
302
  /**
296
- * Will auto-align the popover on first render if it is not visible. This prop is currently experimental and is subject to future changes.
303
+ * Will auto-align the popover on first render if it is not visible. This prop
304
+ * is currently experimental and is subject to future changes. Requires
305
+ * React v17+
306
+ * @see https://github.com/carbon-design-system/carbon/issues/18714
297
307
  */
298
308
  autoAlign: PropTypes.bool,
299
309
  /**
@@ -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;
@@ -15,9 +15,10 @@ var React = require('react');
15
15
  var cx = require('classnames');
16
16
  var index = require('../IconButton/index.js');
17
17
  var usePrefix = require('../../internal/usePrefix.js');
18
+ var noopFn = require('../../internal/noopFn.js');
18
19
 
19
- const noopFn = () => {};
20
- const IconSwitch = /*#__PURE__*/React.forwardRef(function Switch(props, tabRef) {
20
+ const frFn = React.forwardRef;
21
+ const IconSwitch = frFn((props, ref) => {
21
22
  const {
22
23
  align,
23
24
  children,
@@ -27,8 +28,8 @@ const IconSwitch = /*#__PURE__*/React.forwardRef(function Switch(props, tabRef)
27
28
  index: index$1,
28
29
  leaveDelayMs = 0,
29
30
  name,
30
- onClick = noopFn,
31
- onKeyDown = noopFn,
31
+ onClick = noopFn.noopFn,
32
+ onKeyDown = noopFn.noopFn,
32
33
  selected = false,
33
34
  size,
34
35
  text,
@@ -36,8 +37,8 @@ const IconSwitch = /*#__PURE__*/React.forwardRef(function Switch(props, tabRef)
36
37
  } = props;
37
38
  const prefix = usePrefix.usePrefix();
38
39
  const [isHovered, setIsHovered] = React.useState(false);
39
- const handleClick = e => {
40
- e.preventDefault();
40
+ const handleClick = event => {
41
+ event.preventDefault();
41
42
  onClick({
42
43
  index: index$1,
43
44
  name,
@@ -45,6 +46,7 @@ const IconSwitch = /*#__PURE__*/React.forwardRef(function Switch(props, tabRef)
45
46
  });
46
47
  };
47
48
  const handleKeyDown = event => {
49
+ // TODO: `which` was deprecated years ago. When can its usage be deleted?
48
50
  const key = event.key || event.which;
49
51
  onKeyDown({
50
52
  index: index$1,
@@ -66,20 +68,10 @@ const IconSwitch = /*#__PURE__*/React.forwardRef(function Switch(props, tabRef)
66
68
  [`${prefix}--content-switcher-popover--selected`]: selected,
67
69
  [`${prefix}--content-switcher-popover--disabled`]: disabled
68
70
  });
69
- const commonProps = {
70
- onClick: handleClick,
71
- onKeyDown: handleKeyDown,
72
- className: classes,
73
- disabled,
74
- align,
75
- enterDelayMs,
76
- leaveDelayMs,
77
- size
78
- };
79
71
  return /*#__PURE__*/React.createElement(index.IconButton, _rollupPluginBabelHelpers.extends({
80
72
  label: text,
81
73
  type: "button",
82
- ref: tabRef,
74
+ ref: ref,
83
75
  role: "tab",
84
76
  tabIndex: selected || isHovered ? 0 : -1,
85
77
  onMouseEnter: handleMouseEnter,
@@ -89,7 +81,16 @@ const IconSwitch = /*#__PURE__*/React.forwardRef(function Switch(props, tabRef)
89
81
  "aria-selected": selected,
90
82
  "aria-label": text,
91
83
  wrapperClasses: iconButtonClasses
92
- }, other, commonProps), children);
84
+ }, other, {
85
+ align: align,
86
+ className: classes,
87
+ disabled: disabled,
88
+ enterDelayMs: enterDelayMs,
89
+ leaveDelayMs: leaveDelayMs,
90
+ onClick: handleClick,
91
+ onKeyDown: handleKeyDown,
92
+ size: size
93
+ }), children);
93
94
  });
94
95
  IconSwitch.displayName = 'IconSwitch';
95
96
  IconSwitch.propTypes = {
@@ -98,15 +99,15 @@ IconSwitch.propTypes = {
98
99
  */
99
100
  align: PropTypes.oneOf(['top', 'top-left', 'top-right', 'bottom', 'bottom-left', 'bottom-right', 'left', 'right']),
100
101
  /**
101
- * Provide child elements to be rendered inside of the Switch
102
+ * Children to be rendered inside of the `IconSwitch`.
102
103
  */
103
104
  children: PropTypes.node,
104
105
  /**
105
- * Specify an optional className to be added to your Switch
106
+ * Specify an optional className to be added to your `IconSwitch`.
106
107
  */
107
108
  className: PropTypes.string,
108
109
  /**
109
- * Specify whether or not the Switch should be disabled
110
+ * Whether the `IconSwitch` should be disabled.
110
111
  */
111
112
  disabled: PropTypes.bool,
112
113
  /**
@@ -114,8 +115,9 @@ IconSwitch.propTypes = {
114
115
  */
115
116
  enterDelayMs: PropTypes.number,
116
117
  /**
117
- * The index of your Switch in your ContentSwitcher that is used for event handlers.
118
- * Reserved for usage in ContentSwitcher
118
+ * The index of the `IconSwitch`.
119
+ *
120
+ * Reserved for usage in `ContentSwitcher`.
119
121
  */
120
122
  index: PropTypes.number,
121
123
  /**
@@ -123,29 +125,34 @@ IconSwitch.propTypes = {
123
125
  */
124
126
  leaveDelayMs: PropTypes.number,
125
127
  /**
126
- * Provide the name of your Switch that is used for event handlers
128
+ * The name of the `IconSwitch`.
127
129
  */
128
130
  name: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
129
131
  /**
130
132
  * A handler that is invoked when a user clicks on the control.
131
- * Reserved for usage in ContentSwitcher
133
+ *
134
+ * Reserved for usage in `ContentSwitcher`.
132
135
  */
133
136
  onClick: PropTypes.func,
134
137
  /**
135
138
  * A handler that is invoked on the key down event for the control.
136
- * Reserved for usage in ContentSwitcher
139
+ *
140
+ * Reserved for usage in `ContentSwitcher`.
137
141
  */
138
142
  onKeyDown: PropTypes.func,
139
143
  /**
140
- * Whether your Switch is selected. Reserved for usage in ContentSwitcher
144
+ * Whether the `IconSwitch` is selected.
145
+ *
146
+ * Reserved for usage in `ContentSwitcher`.
141
147
  */
142
148
  selected: PropTypes.bool,
149
+ // TODO: Icon only variant of what? Isn't the `IconSwitch` always icon only?
143
150
  /**
144
151
  * Passed in from `ContentSwitcher` to render icon-only variant
145
152
  */
146
153
  size: PropTypes.oneOf(['sm', 'md', 'lg']),
147
154
  /**
148
- * Provide the visible text displayed by the Tooltip
155
+ * `Tooltip` text.
149
156
  */
150
157
  text: PropTypes.string
151
158
  };
@@ -39,6 +39,7 @@ const Switch = /*#__PURE__*/React.forwardRef(function Switch(props, tabRef) {
39
39
  });
40
40
  };
41
41
  const handleKeyDown = event => {
42
+ // TODO: `which` was deprecated years ago. When can its usage be deleted?
42
43
  const key = event.key || event.which;
43
44
  onKeyDown?.({
44
45
  index,
@@ -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
  /**
@@ -187,7 +187,10 @@ Toggletip.propTypes = {
187
187
  */
188
188
  as: PropTypes.elementType,
189
189
  /**
190
- * Will auto-align the popover on first render if it is not visible. This prop is currently experimental and is subject to future changes.
190
+ * Will auto-align the popover on first render if it is not visible. This prop
191
+ * is currently experimental and is subject to future changes. Requires
192
+ * React v17+
193
+ * @see https://github.com/carbon-design-system/carbon/issues/18714
191
194
  */
192
195
  autoAlign: PropTypes.bool,
193
196
  /**
@@ -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
  */
@@ -103,7 +103,9 @@ DefinitionTooltip.propTypes = {
103
103
  // new values to match floating-ui
104
104
  'top-start', 'top-end', 'bottom-start', 'bottom-end', 'left-end', 'left-start', 'right-end', 'right-start']),
105
105
  /**
106
- * Will auto-align the popover. This prop is currently experimental and is subject to future changes.
106
+ * Will auto-align the popover. This prop is currently experimental and is
107
+ * subject to future changes. Requires React v17+
108
+ * @see https://github.com/carbon-design-system/carbon/issues/18714
107
109
  */
108
110
  autoAlign: PropTypes.bool,
109
111
  /**
@@ -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
  *
@@ -48,20 +48,12 @@ const Tooltip = /*#__PURE__*/React.forwardRef(({
48
48
  const prefix = usePrefix.usePrefix();
49
49
  const child = React.Children.only(children);
50
50
  const {
51
- 'aria-label': ariaLabel,
52
51
  'aria-labelledby': ariaLabelledBy,
53
52
  'aria-describedby': ariaDescribedBy
54
53
  } = child?.props ?? {};
55
54
  const hasLabel = !!label;
56
- const hasAriaLabel = typeof ariaLabel === 'string' ? ariaLabel.trim() !== '' : false;
57
-
58
- // An `aria-label` takes precedence over `aria-describedby`, but when it's
59
- // needed and the user doesn't specify one, the fallback `id` is used.
60
- const labelledBy = hasAriaLabel ? undefined : hasLabel ? ariaLabelledBy ?? id : undefined;
61
-
62
- // If `aria-label` is present, use any provided `aria-describedby`.
63
- // If not, fallback to child's `aria-describedby` or the tooltip `id` if needed.
64
- const describedBy = hasAriaLabel ? ariaDescribedBy : ariaDescribedBy ?? (!hasLabel && !ariaLabelledBy ? id : undefined);
55
+ const labelledBy = ariaLabelledBy ?? (hasLabel ? id : undefined);
56
+ const describedBy = ariaDescribedBy ?? (!hasLabel ? id : undefined);
65
57
  const triggerProps = {
66
58
  onFocus: () => !focusByMouse && setOpen(true),
67
59
  onBlur: () => {
@@ -4,13 +4,12 @@
4
4
  * This source code is licensed under the Apache-2.0 license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import { type MouseEvent } from 'react';
8
7
  import type { TreeNodeProps } from './TreeNode';
9
8
  interface TreeContextProps {
10
9
  active?: string | number;
11
10
  multiselect?: boolean;
12
11
  onActivate?: (nodeId?: string | number) => void;
13
- onTreeSelect?: (event: MouseEvent, node?: Partial<TreeNodeProps>) => void;
12
+ onTreeSelect?: TreeNodeProps['onTreeSelect'];
14
13
  selected?: Array<string | number>;
15
14
  size?: 'xs' | 'sm';
16
15
  }
@@ -5,6 +5,8 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import React, { type ComponentType, type FunctionComponent } from 'react';
8
+ type UncontrolledOnToggle = (event: React.MouseEvent | React.KeyboardEvent, node: Pick<TreeNodeProps, 'id' | 'label' | 'value' | 'isExpanded'>) => void;
9
+ type ControlledOnToggle = (isExpanded: TreeNodeProps['isExpanded']) => void;
8
10
  export type TreeNodeProps = {
9
11
  /**
10
12
  * **Note:** this is controlled by the parent TreeView component, do not set manually.
@@ -52,15 +54,15 @@ export type TreeNodeProps = {
52
54
  /**
53
55
  * Callback function for when the node is selected
54
56
  */
55
- onSelect?: (event: React.MouseEvent, node?: Omit<TreeNodeProps, 'children'>) => void;
57
+ onSelect?: (event: React.MouseEvent | React.KeyboardEvent, node: Pick<TreeNodeProps, 'id' | 'label' | 'value'>) => void;
56
58
  /**
57
59
  * Callback function for when a parent node is expanded or collapsed
58
60
  */
59
- onToggle?: (event: React.MouseEvent | React.KeyboardEvent, node?: Omit<TreeNodeProps, 'children'>) => void;
61
+ onToggle?: UncontrolledOnToggle | ControlledOnToggle;
60
62
  /**
61
63
  * Callback function for when any node in the tree is selected
62
64
  */
63
- onTreeSelect?: (event: React.MouseEvent, node?: TreeNodeProps) => void;
65
+ onTreeSelect?: (event: React.MouseEvent | React.KeyboardEvent, node: Pick<TreeNodeProps, 'id' | 'label' | 'value'>) => void;
64
66
  /**
65
67
  * A component used to render an icon.
66
68
  */
@@ -86,7 +88,8 @@ export type TreeNodeProps = {
86
88
  /**
87
89
  * **Experimental**: Will attempt to automatically align the floating
88
90
  * element to avoid collisions with the viewport and being clipped by
89
- * ancestor elements.
91
+ * ancestor elements. Requires React v17+
92
+ * @see https://github.com/carbon-design-system/carbon/issues/18714
90
93
  */
91
94
  autoAlign?: boolean;
92
95
  } & Omit<React.LiHTMLAttributes<HTMLElement>, 'onSelect'>;
@@ -137,15 +140,15 @@ declare const TreeNode: React.ForwardRefExoticComponent<{
137
140
  /**
138
141
  * Callback function for when the node is selected
139
142
  */
140
- onSelect?: (event: React.MouseEvent, node?: Omit<TreeNodeProps, "children">) => void;
143
+ onSelect?: (event: React.MouseEvent | React.KeyboardEvent, node: Pick<TreeNodeProps, "id" | "label" | "value">) => void;
141
144
  /**
142
145
  * Callback function for when a parent node is expanded or collapsed
143
146
  */
144
- onToggle?: (event: React.MouseEvent | React.KeyboardEvent, node?: Omit<TreeNodeProps, "children">) => void;
147
+ onToggle?: UncontrolledOnToggle | ControlledOnToggle;
145
148
  /**
146
149
  * Callback function for when any node in the tree is selected
147
150
  */
148
- onTreeSelect?: (event: React.MouseEvent, node?: TreeNodeProps) => void;
151
+ onTreeSelect?: (event: React.MouseEvent | React.KeyboardEvent, node: Pick<TreeNodeProps, "id" | "label" | "value">) => void;
149
152
  /**
150
153
  * A component used to render an icon.
151
154
  */
@@ -171,7 +174,8 @@ declare const TreeNode: React.ForwardRefExoticComponent<{
171
174
  /**
172
175
  * **Experimental**: Will attempt to automatically align the floating
173
176
  * element to avoid collisions with the viewport and being clipped by
174
- * ancestor elements.
177
+ * ancestor elements. Requires React v17+
178
+ * @see https://github.com/carbon-design-system/carbon/issues/18714
175
179
  */
176
180
  autoAlign?: boolean;
177
181
  } & Omit<React.LiHTMLAttributes<HTMLElement>, "onSelect"> & React.RefAttributes<HTMLElement>>;
@@ -134,14 +134,7 @@ const TreeNode = /*#__PURE__*/React.forwardRef(({
134
134
  } = React.useRef(nodeId || useId.useId());
135
135
  const controllableExpandedState = useControllableState.useControllableState({
136
136
  value: isExpanded,
137
- onChange: newValue => {
138
- onToggle?.(undefined, {
139
- id,
140
- isExpanded: newValue,
141
- label,
142
- value
143
- });
144
- },
137
+ onChange: onToggle,
145
138
  defaultValue: defaultIsExpanded ?? false
146
139
  });
147
140
  const uncontrollableExpandedState = React.useState(isExpanded ?? false);
@@ -501,7 +494,8 @@ TreeNode.propTypes = {
501
494
  /**
502
495
  * **Experimental**: Will attempt to automatically align the floating
503
496
  * element to avoid collisions with the viewport and being clipped by
504
- * ancestor elements.
497
+ * ancestor elements. Requires React v17+
498
+ * @see https://github.com/carbon-design-system/carbon/issues/18714
505
499
  */
506
500
  autoAlign: PropTypes.bool
507
501
  };
@@ -5,7 +5,11 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import React, { type JSX } from 'react';
8
- import TreeNode, { TreeNodeProps } from './TreeNode';
8
+ import TreeNode, { type TreeNodeProps } from './TreeNode';
9
+ type UncontrolledOnSelect = (event: React.MouseEvent | React.KeyboardEvent, payload: Parameters<NonNullable<TreeNodeProps['onSelect']>>[1] & {
10
+ activeNodeId?: TreeViewProps['active'];
11
+ }) => void;
12
+ type ControlledOnSelect = (selected: TreeViewProps['selected']) => void;
9
13
  export type TreeViewProps = {
10
14
  /**
11
15
  * Mark the active node in the tree, represented by its ID
@@ -36,13 +40,11 @@ export type TreeViewProps = {
36
40
  * **[Experimental]** Callback function that is called when any node is activated.
37
41
  * *This is only supported with the `enable-treeview-controllable` feature flag!*
38
42
  */
39
- onActivate?: (activated?: string | number) => void;
43
+ onActivate?: (active: TreeViewProps['active']) => void;
40
44
  /**
41
45
  * Callback function that is called when any node is selected
42
46
  */
43
- onSelect?: (event: React.SyntheticEvent<HTMLUListElement>, payload?: Partial<TreeNodeProps> & {
44
- activeNodeId?: string | number;
45
- }) => void;
47
+ onSelect?: UncontrolledOnSelect | ControlledOnSelect;
46
48
  /**
47
49
  * Array representing all selected node IDs in the tree
48
50
  */