@carbon/react 1.80.0-rc.0 → 1.80.1

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 (44) hide show
  1. package/.playwright/INTERNAL_AVT_REPORT_DO_NOT_USE.json +822 -822
  2. package/es/components/ComposedModal/ComposedModal.js +16 -8
  3. package/es/components/InlineLoading/InlineLoading.js +10 -2
  4. package/es/components/Menu/MenuItem.d.ts +3 -3
  5. package/es/components/Menu/MenuItem.js +1 -1
  6. package/es/components/Modal/Modal.js +17 -5
  7. package/es/components/OverflowMenu/OverflowMenu.js +2 -2
  8. package/es/components/Tag/DismissibleTag.d.ts +1 -55
  9. package/es/components/Tag/DismissibleTag.js +6 -4
  10. package/es/components/Tag/OperationalTag.d.ts +1 -1
  11. package/es/components/Tag/SelectableTag.d.ts +1 -43
  12. package/es/components/Tag/SelectableTag.js +7 -5
  13. package/es/components/TreeView/TreeNode.d.ts +1 -1
  14. package/es/components/TreeView/TreeNode.js +11 -4
  15. package/es/components/TreeView/TreeView.d.ts +1 -1
  16. package/es/components/TreeView/TreeView.js +6 -6
  17. package/es/internal/ClickListener.d.ts +13 -0
  18. package/es/internal/ClickListener.js +33 -60
  19. package/es/internal/useControllableState.d.ts +34 -0
  20. package/es/internal/useControllableState.js +15 -30
  21. package/es/internal/useOutsideClick.d.ts +8 -0
  22. package/es/internal/useOutsideClick.js +9 -6
  23. package/lib/components/ComposedModal/ComposedModal.js +14 -6
  24. package/lib/components/InlineLoading/InlineLoading.js +10 -2
  25. package/lib/components/Menu/MenuItem.d.ts +3 -3
  26. package/lib/components/Menu/MenuItem.js +1 -1
  27. package/lib/components/Modal/Modal.js +15 -3
  28. package/lib/components/OverflowMenu/OverflowMenu.js +2 -2
  29. package/lib/components/Tag/DismissibleTag.d.ts +1 -55
  30. package/lib/components/Tag/DismissibleTag.js +5 -3
  31. package/lib/components/Tag/OperationalTag.d.ts +1 -1
  32. package/lib/components/Tag/SelectableTag.d.ts +1 -43
  33. package/lib/components/Tag/SelectableTag.js +6 -4
  34. package/lib/components/TreeView/TreeNode.d.ts +1 -1
  35. package/lib/components/TreeView/TreeNode.js +11 -4
  36. package/lib/components/TreeView/TreeView.d.ts +1 -1
  37. package/lib/components/TreeView/TreeView.js +6 -6
  38. package/lib/internal/ClickListener.d.ts +13 -0
  39. package/lib/internal/ClickListener.js +32 -64
  40. package/lib/internal/useControllableState.d.ts +34 -0
  41. package/lib/internal/useControllableState.js +15 -30
  42. package/lib/internal/useOutsideClick.d.ts +8 -0
  43. package/lib/internal/useOutsideClick.js +9 -6
  44. package/package.json +8 -7
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Copyright IBM Corp. 2016, 2025
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
+ */
7
+ interface UseControllableStateConfig<T> {
8
+ /** The name of the component. */
9
+ name?: string;
10
+ /**
11
+ * The default value for the component. This value is used when the component
12
+ * is uncontrolled (i.e., when `value` is not provided).
13
+ */
14
+ defaultValue: T;
15
+ /**
16
+ * This callback is called whenever the state changes. It's useful for
17
+ * communicating state updates to parent components of controlled components.
18
+ */
19
+ onChange?: (value: T) => void;
20
+ /**
21
+ * Controlled value. If this prop is omitted, the state will be uncontrolled.
22
+ */
23
+ value?: T;
24
+ }
25
+ /**
26
+ * This hook simplifies the behavior of a component that has state which can be
27
+ * both controlled and uncontrolled. It works like `useState`. You can use the
28
+ * `onChange` callback to communicate state updates to parent components.
29
+ *
30
+ * Note: This hook will warn if the component switches between controlled and
31
+ * uncontrolled states.
32
+ */
33
+ export declare const useControllableState: <T>({ defaultValue, name, onChange, value, }: UseControllableStateConfig<T>) => [T, (stateOrUpdater: T | ((prev: T) => T)) => void];
34
+ export {};
@@ -9,58 +9,43 @@ import { useState, useRef, useEffect } from 'react';
9
9
  import { warning } from './warning.js';
10
10
 
11
11
  /**
12
- * This custom hook simplifies the behavior of a component if it has state that
13
- * can be both controlled and uncontrolled. It functions identical to a
14
- * useState() hook and provides [state, setState] for you to use. You can use
15
- * the `onChange` argument to allow updates to the `state` to be communicated to
16
- * owners of controlled components.
12
+ * This hook simplifies the behavior of a component that has state which can be
13
+ * both controlled and uncontrolled. It works like `useState`. You can use the
14
+ * `onChange` callback to communicate state updates to parent components.
17
15
  *
18
- * Note: this hook will warn if a component is switching from controlled to
19
- * uncontrolled, or vice-versa.
20
- *
21
- * @param {object} config
22
- * @param {string} [config.name] - the name of the custom component
23
- * @param {any} config.defaultValue - the default value used for the state. This will be
24
- * the fallback value used if `value` is not defined.
25
- * @param {Function|undefined} config.onChange - an optional function that is called when
26
- * the value of the state changes. This is useful for communicating to parents of
27
- * controlled components that the value is requesting to be changed.
28
- * @param {any} config.value - a controlled value. Omitting this means that the state is
29
- * uncontrolled
30
- * @returns {[any, (v: any) => void]}
16
+ * Note: This hook will warn if the component switches between controlled and
17
+ * uncontrolled states.
31
18
  */
32
- function useControllableState(_ref) {
19
+ const useControllableState = _ref => {
33
20
  let {
34
21
  defaultValue,
35
22
  name = 'custom',
36
23
  onChange,
37
24
  value
38
25
  } = _ref;
39
- const [state, internalSetState] = useState(value ?? defaultValue);
26
+ const [state, internalSetState] = useState(typeof value !== 'undefined' ? value : defaultValue);
40
27
  const controlled = useRef(null);
41
28
  if (controlled.current === null) {
42
- controlled.current = value !== undefined;
29
+ controlled.current = typeof value !== 'undefined';
43
30
  }
44
- function setState(stateOrUpdater) {
45
- const value = typeof stateOrUpdater === 'function' ? stateOrUpdater(state) : stateOrUpdater;
31
+ const setState = stateOrUpdater => {
32
+ const newValue = typeof stateOrUpdater === 'function' ? stateOrUpdater(state) : stateOrUpdater;
46
33
  if (controlled.current === false) {
47
- internalSetState(value);
34
+ internalSetState(newValue);
48
35
  }
49
36
  if (onChange) {
50
- onChange(value);
37
+ onChange(newValue);
51
38
  }
52
- }
39
+ };
53
40
  useEffect(() => {
54
- const controlledValue = value !== undefined;
41
+ const controlledValue = typeof value !== 'undefined';
55
42
 
56
43
  // Uncontrolled -> Controlled
57
- // If the component prop is uncontrolled, the prop value should be undefined
58
44
  if (controlled.current === false && controlledValue) {
59
45
  process.env.NODE_ENV !== "production" ? warning(false, `A component is changing an uncontrolled ${name} component to be controlled. ` + 'This is likely caused by the value changing to a defined value ' + 'from undefined. Decide between using a controlled or uncontrolled ' + 'value for the lifetime of the component. ' + 'More info: https://reactjs.org/link/controlled-components') : void 0;
60
46
  }
61
47
 
62
48
  // Controlled -> Uncontrolled
63
- // If the component prop is controlled, the prop value should be defined
64
49
  if (controlled.current === true && !controlledValue) {
65
50
  process.env.NODE_ENV !== "production" ? warning(false, `A component is changing a controlled ${name} component to be uncontrolled. ` + 'This is likely caused by the value changing to an undefined value ' + 'from a defined one. Decide between using a controlled or ' + 'uncontrolled value for the lifetime of the component. ' + 'More info: https://reactjs.org/link/controlled-components') : void 0;
66
51
  }
@@ -69,6 +54,6 @@ function useControllableState(_ref) {
69
54
  return [value, setState];
70
55
  }
71
56
  return [state, setState];
72
- }
57
+ };
73
58
 
74
59
  export { useControllableState };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Copyright IBM Corp. 2016, 2025
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
+ */
7
+ import { type RefObject } from 'react';
8
+ export declare const useOutsideClick: <T extends HTMLElement>(ref: RefObject<T>, callback: (event: MouseEvent) => void) => void;
@@ -6,26 +6,29 @@
6
6
  */
7
7
 
8
8
  import { useRef, useEffect } from 'react';
9
- import { useEvent } from './useEvent.js';
10
9
  import { canUseDOM } from './environment.js';
10
+ import { useWindowEvent } from './useEvent.js';
11
11
 
12
- function useOutsideClick(ref, callback) {
12
+ const useOutsideClick = (ref, callback) => {
13
13
  const savedCallback = useRef(callback);
14
14
  useEffect(() => {
15
15
  savedCallback.current = callback;
16
- });
16
+ }, [callback]);
17
17
 
18
18
  // We conditionally guard the `useEvent` hook for SSR. `canUseDOM` can be
19
19
  // treated as a constant as it will be false when executed in a Node.js
20
20
  // environment and true when executed in the browser
21
21
  if (canUseDOM) {
22
22
  // eslint-disable-next-line react-hooks/rules-of-hooks
23
- useEvent(window, 'click', event => {
24
- if (ref.current && !ref.current.contains(event.target)) {
23
+ useWindowEvent('click', event => {
24
+ const {
25
+ target
26
+ } = event;
27
+ if (target instanceof Node && ref.current && !ref.current.contains(target)) {
25
28
  savedCallback.current(event);
26
29
  }
27
30
  });
28
31
  }
29
- }
32
+ };
30
33
 
31
34
  export { useOutsideClick };
@@ -29,6 +29,7 @@ var index$1 = require('../FeatureFlags/index.js');
29
29
  var events = require('../../tools/events.js');
30
30
  var deprecate = require('../../prop-types/deprecate.js');
31
31
  var index$2 = require('../Dialog/index.js');
32
+ var warning = require('../../internal/warning.js');
32
33
  var debounce = require('../../node_modules/es-toolkit/dist/compat/function/debounce.mjs.js');
33
34
 
34
35
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -131,9 +132,9 @@ const ComposedModal = /*#__PURE__*/React__default["default"].forwardRef(function
131
132
  const startSentinel = React.useRef(null);
132
133
  const endSentinel = React.useRef(null);
133
134
  const onMouseDownTarget = React.useRef(null);
134
- const enableDialogElement =
135
- // useFeatureFlag('enable-experimental-focus-wrap-without-sentinels') ||
136
- index$1.useFeatureFlag('enable-dialog-element');
135
+ const enableDialogElement = index$1.useFeatureFlag('enable-dialog-element');
136
+ const focusTrapWithoutSentinels = index$1.useFeatureFlag('enable-experimental-focus-wrap-without-sentinels');
137
+ process.env.NODE_ENV !== "production" ? warning.warning(!(focusTrapWithoutSentinels && enableDialogElement), '`<Modal>` detected both `focusTrapWithoutSentinels` and ' + '`enableDialogElement` feature flags are enabled. The native dialog ' + 'element handles focus, so `enableDialogElement` must be off for ' + '`focusTrapWithoutSentinels` to have any effect.') : void 0;
137
138
 
138
139
  // Keep track of modal open/close state
139
140
  // and propagate it to the document.body
@@ -159,6 +160,13 @@ const ComposedModal = /*#__PURE__*/React__default["default"].forwardRef(function
159
160
  if (match.match(event, keys.Escape)) {
160
161
  closeModal(event);
161
162
  }
163
+ if (focusTrapWithoutSentinels && open && match.match(event, keys.Tab) && innerModal.current) {
164
+ wrapFocus.wrapFocusWithoutSentinels({
165
+ containerNode: innerModal.current,
166
+ currentActiveNode: event.target,
167
+ event: event
168
+ });
169
+ }
162
170
  }
163
171
  onKeyDown?.(event);
164
172
  }
@@ -293,7 +301,7 @@ const ComposedModal = /*#__PURE__*/React__default["default"].forwardRef(function
293
301
  "aria-modal": "true",
294
302
  "aria-label": ariaLabel ? ariaLabel : generatedAriaLabel,
295
303
  "aria-labelledby": ariaLabelledBy
296
- }, /*#__PURE__*/React__default["default"].createElement("button", {
304
+ }, !focusTrapWithoutSentinels && /*#__PURE__*/React__default["default"].createElement("button", {
297
305
  type: "button",
298
306
  ref: startSentinel,
299
307
  className: `${prefix}--visually-hidden`
@@ -302,7 +310,7 @@ const ComposedModal = /*#__PURE__*/React__default["default"].forwardRef(function
302
310
  className: `${prefix}--modal-container-body`
303
311
  }, slug ? normalizedDecorator : decorator ? /*#__PURE__*/React__default["default"].createElement("div", {
304
312
  className: `${prefix}--modal--inner__decorator`
305
- }, normalizedDecorator) : '', childrenWithProps), /*#__PURE__*/React__default["default"].createElement("button", {
313
+ }, normalizedDecorator) : '', childrenWithProps), !focusTrapWithoutSentinels && /*#__PURE__*/React__default["default"].createElement("button", {
306
314
  type: "button",
307
315
  ref: endSentinel,
308
316
  className: `${prefix}--visually-hidden`
@@ -312,7 +320,7 @@ const ComposedModal = /*#__PURE__*/React__default["default"].forwardRef(function
312
320
  role: "presentation",
313
321
  ref: ref,
314
322
  "aria-hidden": !open,
315
- onBlur: !enableDialogElement ? handleBlur : () => {},
323
+ onBlur: !enableDialogElement && !focusTrapWithoutSentinels ? handleBlur : () => {},
316
324
  onClick: events.composeEventHandlers([rest?.onClick, handleOnClick]),
317
325
  onMouseDown: events.composeEventHandlers([rest?.onMouseDown, handleOnMouseDown]),
318
326
  onKeyDown: handleKeyDown,
@@ -63,9 +63,9 @@ const InlineLoading = _ref => {
63
63
  className: `${prefix}--inline-loading__checkmark-container`
64
64
  }, /*#__PURE__*/React__default["default"].createElement("title", null, iconLabel));
65
65
  }
66
- if (status === 'inactive' || status === 'active') {
66
+ if (status === 'active') {
67
67
  if (!iconDescription) {
68
- iconLabel = status === 'active' ? 'loading' : 'not loading';
68
+ iconLabel = 'loading';
69
69
  }
70
70
  return /*#__PURE__*/React__default["default"].createElement(Loading["default"], {
71
71
  small: true,
@@ -74,6 +74,14 @@ const InlineLoading = _ref => {
74
74
  active: status === 'active'
75
75
  });
76
76
  }
77
+ if (status === 'inactive') {
78
+ if (!iconDescription) {
79
+ iconLabel = 'not loading';
80
+ }
81
+ return /*#__PURE__*/React__default["default"].createElement("title", {
82
+ className: `${prefix}--inline-loading__inactive-status`
83
+ }, iconLabel);
84
+ }
77
85
  return undefined;
78
86
  };
79
87
  const loadingText = description && /*#__PURE__*/React__default["default"].createElement("div", {
@@ -4,7 +4,7 @@
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 React, { ChangeEventHandler, ComponentProps, FC, KeyboardEvent, LiHTMLAttributes, MouseEvent, ReactNode } from 'react';
7
+ import React, { ComponentProps, FC, KeyboardEvent, LiHTMLAttributes, MouseEvent, ReactNode } from 'react';
8
8
  export interface MenuItemProps extends LiHTMLAttributes<HTMLLIElement> {
9
9
  /**
10
10
  * Optionally provide another Menu to create a submenu. props.children can't be used to specify the content of the MenuItem itself. Use props.label instead.
@@ -48,7 +48,7 @@ export interface MenuItemSelectableProps extends Omit<MenuItemProps, 'onChange'>
48
48
  /**
49
49
  * Provide an optional function to be called when the selection state changes.
50
50
  */
51
- onChange?: ChangeEventHandler<HTMLLIElement>;
51
+ onChange?: (checked: boolean) => void;
52
52
  /**
53
53
  * Controls the state of this option.
54
54
  */
@@ -94,7 +94,7 @@ export interface MenuItemRadioGroupProps<Item> extends Omit<ComponentProps<'ul'>
94
94
  /**
95
95
  * Provide an optional function to be called when the selection changes.
96
96
  */
97
- onChange?: ChangeEventHandler<HTMLLIElement>;
97
+ onChange?: (selectedItem: Item) => void;
98
98
  /**
99
99
  * Provide props.selectedItem to control the state of this radio group. Must match the type of props.items.
100
100
  */
@@ -343,7 +343,7 @@ const MenuItemRadioGroup = /*#__PURE__*/React.forwardRef(function MenuItemRadioG
343
343
  const [selection, setSelection] = useControllableState.useControllableState({
344
344
  value: selectedItem,
345
345
  onChange,
346
- defaultValue: defaultSelectedItem
346
+ defaultValue: defaultSelectedItem ?? {}
347
347
  });
348
348
  function handleClick(item, e) {
349
349
  setSelection(item);
@@ -34,6 +34,7 @@ var index = require('../FeatureFlags/index.js');
34
34
  var events = require('../../tools/events.js');
35
35
  var deprecate = require('../../prop-types/deprecate.js');
36
36
  var index$1 = require('../Dialog/index.js');
37
+ var warning = require('../../internal/warning.js');
37
38
  var debounce = require('../../node_modules/es-toolkit/dist/compat/function/debounce.mjs.js');
38
39
  var Text = require('../Text/Text.js');
39
40
 
@@ -97,7 +98,9 @@ const Modal = /*#__PURE__*/React__default["default"].forwardRef(function Modal(_
97
98
  [`${prefix}--btn--loading`]: loadingStatus !== 'inactive'
98
99
  });
99
100
  const loadingActive = loadingStatus !== 'inactive';
100
- const enableDialogElement = index.useFeatureFlag('enable-experimental-focus-wrap-without-sentinels') || index.useFeatureFlag('enable-dialog-element');
101
+ const focusTrapWithoutSentinels = index.useFeatureFlag('enable-experimental-focus-wrap-without-sentinels');
102
+ const enableDialogElement = index.useFeatureFlag('enable-dialog-element');
103
+ process.env.NODE_ENV !== "production" ? warning.warning(!(focusTrapWithoutSentinels && enableDialogElement), '`<Modal>` detected both `focusTrapWithoutSentinels` and ' + '`enableDialogElement` feature flags are enabled. The native dialog ' + 'element handles focus, so `enableDialogElement` must be off for ' + '`focusTrapWithoutSentinels` to have any effect.') : void 0;
101
104
  function isCloseButton(element) {
102
105
  return !onSecondarySubmit && element === secondaryButton.current || element.classList.contains(modalCloseButtonClass);
103
106
  }
@@ -110,6 +113,15 @@ const Modal = /*#__PURE__*/React__default["default"].forwardRef(function Modal(_
110
113
  if (match.match(evt, keys.Enter) && shouldSubmitOnEnter && !isCloseButton(evt.target)) {
111
114
  onRequestSubmit(evt);
112
115
  }
116
+ if (focusTrapWithoutSentinels && !enableDialogElement && match.match(evt, keys.Tab) && innerModal.current) {
117
+ wrapFocus.wrapFocusWithoutSentinels({
118
+ containerNode: innerModal.current,
119
+ currentActiveNode: evt.target,
120
+ // TODO: Delete type assertion following util rewrite.
121
+ // https://github.com/carbon-design-system/carbon/pull/18913
122
+ event: evt
123
+ });
124
+ }
113
125
  }
114
126
  }
115
127
  function handleOnClick(evt) {
@@ -336,7 +348,7 @@ const Modal = /*#__PURE__*/React__default["default"].forwardRef(function Modal(_
336
348
  iconDescription: loadingIconDescription,
337
349
  className: `${prefix}--inline-loading--btn`,
338
350
  onSuccess: onLoadingSuccess
339
- })))) : /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, !enableDialogElement && /*#__PURE__*/React__default["default"].createElement("span", {
351
+ })))) : /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, !enableDialogElement && !focusTrapWithoutSentinels && /*#__PURE__*/React__default["default"].createElement("span", {
340
352
  ref: startTrap,
341
353
  tabIndex: 0,
342
354
  role: "link",
@@ -395,7 +407,7 @@ const Modal = /*#__PURE__*/React__default["default"].forwardRef(function Modal(_
395
407
  iconDescription: loadingIconDescription,
396
408
  className: `${prefix}--inline-loading--btn`,
397
409
  onSuccess: onLoadingSuccess
398
- })))), !enableDialogElement && /*#__PURE__*/React__default["default"].createElement("span", {
410
+ })))), !enableDialogElement && !focusTrapWithoutSentinels && /*#__PURE__*/React__default["default"].createElement("span", {
399
411
  ref: endTrap,
400
412
  tabIndex: 0,
401
413
  role: "link",
@@ -212,7 +212,7 @@ const OverflowMenu = /*#__PURE__*/React.forwardRef((_ref, ref) => {
212
212
  }
213
213
  };
214
214
  const handleClickOutside = evt => {
215
- if (open && (!menuBodyRef.current || !menuBodyRef.current.contains(evt.target))) {
215
+ if (open && (!menuBodyRef.current || evt.target instanceof Node && !menuBodyRef.current.contains(evt.target))) {
216
216
  closeMenu();
217
217
  }
218
218
  };
@@ -325,7 +325,7 @@ const OverflowMenu = /*#__PURE__*/React.forwardRef((_ref, ref) => {
325
325
  }, /*#__PURE__*/React.cloneElement(menuBody, {
326
326
  'data-floating-menu-direction': direction
327
327
  }));
328
- return /*#__PURE__*/React__default["default"].createElement(ClickListener["default"], {
328
+ return /*#__PURE__*/React__default["default"].createElement(ClickListener.ClickListener, {
329
329
  onClickOutside: handleClickOutside
330
330
  }, /*#__PURE__*/React__default["default"].createElement("span", {
331
331
  className: `${prefix}--overflow-menu__wrapper`,
@@ -4,7 +4,6 @@
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 PropTypes from 'prop-types';
8
7
  import React, { ReactNode } from 'react';
9
8
  import { PolymorphicProps } from '../../types/common';
10
9
  import { SIZES, TYPES } from './Tag';
@@ -61,59 +60,6 @@ export interface DismissibleTagBaseProps {
61
60
  type?: keyof typeof TYPES;
62
61
  }
63
62
  export type DismissibleTagProps<T extends React.ElementType> = PolymorphicProps<T, DismissibleTagBaseProps>;
64
- declare const DismissibleTag: {
65
- <T extends React.ElementType>({ className, decorator, disabled, id, renderIcon, title, onClose, slug, size, text, tagTitle, type, ...other }: DismissibleTagProps<T>): import("react/jsx-runtime").JSX.Element;
66
- propTypes: {
67
- /**
68
- * Provide a custom className that is applied to the containing <span>
69
- */
70
- className: PropTypes.Requireable<string>;
71
- /**
72
- * **Experimental:** Provide a `decorator` component to be rendered inside the `DismissibleTag` component
73
- */
74
- decorator: PropTypes.Requireable<PropTypes.ReactNodeLike>;
75
- /**
76
- * Specify if the `DismissibleTag` is disabled
77
- */
78
- disabled: PropTypes.Requireable<boolean>;
79
- /**
80
- * Specify the id for the tag.
81
- */
82
- id: PropTypes.Requireable<string>;
83
- /**
84
- * Click handler for filter tag close button.
85
- */
86
- onClose: PropTypes.Requireable<(...args: any[]) => any>;
87
- /**
88
- * A component used to render an icon.
89
- */
90
- renderIcon: PropTypes.Requireable<object>;
91
- /**
92
- * Specify the size of the Tag. Currently supports either `sm`,
93
- * `md` (default) or `lg` sizes.
94
- */
95
- size: PropTypes.Requireable<string>;
96
- /**
97
- * **Experimental:** Provide a `Slug` component to be rendered inside the `DismissibleTag` component
98
- */
99
- slug: (props: any, propName: any, componentName: any, ...rest: any[]) => any;
100
- /**
101
- * Provide text to be rendered inside of a the tag.
102
- */
103
- text: PropTypes.Requireable<string>;
104
- /**
105
- * Provide a custom `title` to be inserted in the tag.
106
- */
107
- tagTitle: PropTypes.Requireable<string>;
108
- /**
109
- * Text to show on clear filters
110
- */
111
- title: PropTypes.Requireable<string>;
112
- /**
113
- * Specify the type of the `Tag`
114
- */
115
- type: PropTypes.Requireable<string>;
116
- };
117
- };
63
+ declare const DismissibleTag: React.ForwardRefExoticComponent<Omit<DismissibleTagProps<React.ElementType<any, keyof React.JSX.IntrinsicElements>>, "ref"> & React.RefAttributes<HTMLDivElement>>;
118
64
  export declare const types: string[];
119
65
  export default DismissibleTag;
@@ -22,6 +22,7 @@ require('../Tooltip/DefinitionTooltip.js');
22
22
  var Tooltip = require('../Tooltip/Tooltip.js');
23
23
  require('../Text/index.js');
24
24
  var isEllipsisActive = require('./isEllipsisActive.js');
25
+ var mergeRefs = require('../../tools/mergeRefs.js');
25
26
  var Text = require('../Text/Text.js');
26
27
 
27
28
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -31,7 +32,7 @@ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
31
32
  var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
32
33
 
33
34
  var _Close;
34
- const DismissibleTag = _ref => {
35
+ const DismissibleTag = /*#__PURE__*/React.forwardRef((_ref, forwardRef) => {
35
36
  let {
36
37
  className,
37
38
  decorator,
@@ -56,6 +57,7 @@ const DismissibleTag = _ref => {
56
57
  const newElement = tagLabelRef.current?.getElementsByClassName(`${prefix}--tag__label`)[0];
57
58
  setIsEllipsisApplied(isEllipsisActive.isEllipsisActive(newElement));
58
59
  }, [prefix, tagLabelRef]);
60
+ const combinedRef = mergeRefs["default"](tagLabelRef, forwardRef);
59
61
  const handleClose = event => {
60
62
  if (onClose) {
61
63
  event.stopPropagation();
@@ -79,7 +81,7 @@ const DismissibleTag = _ref => {
79
81
  } = other;
80
82
  const dismissLabel = `Dismiss "${text}"`;
81
83
  return /*#__PURE__*/React__default["default"].createElement(Tag["default"], _rollupPluginBabelHelpers["extends"]({
82
- ref: tagLabelRef,
84
+ ref: combinedRef,
83
85
  type: type,
84
86
  size: size,
85
87
  renderIcon: renderIcon,
@@ -106,7 +108,7 @@ const DismissibleTag = _ref => {
106
108
  disabled: disabled,
107
109
  "aria-label": title
108
110
  }, _Close || (_Close = /*#__PURE__*/React__default["default"].createElement(iconsReact.Close, null))))));
109
- };
111
+ });
110
112
  DismissibleTag.propTypes = {
111
113
  /**
112
114
  * Provide a custom className that is applied to the containing <span>
@@ -52,6 +52,6 @@ export interface OperationalTagBaseProps {
52
52
  type?: keyof typeof TYPES;
53
53
  }
54
54
  export type OperationalTagProps<T extends React.ElementType> = PolymorphicProps<T, OperationalTagBaseProps>;
55
- declare const OperationalTag: React.ForwardRefExoticComponent<Omit<OperationalTagProps<React.ElementType<any, keyof React.JSX.IntrinsicElements>>, "ref"> & React.RefAttributes<HTMLLIElement>>;
55
+ declare const OperationalTag: React.ForwardRefExoticComponent<Omit<OperationalTagProps<React.ElementType<any, keyof React.JSX.IntrinsicElements>>, "ref"> & React.RefAttributes<HTMLButtonElement>>;
56
56
  export declare const types: string[];
57
57
  export default OperationalTag;
@@ -4,7 +4,6 @@
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 PropTypes from 'prop-types';
8
7
  import React, { MouseEvent } from 'react';
9
8
  import { PolymorphicProps } from '../../types/common';
10
9
  import { SIZES } from './Tag';
@@ -48,46 +47,5 @@ export interface SelectableTagBaseProps {
48
47
  text?: string;
49
48
  }
50
49
  export type SelectableTagProps<T extends React.ElementType> = PolymorphicProps<T, SelectableTagBaseProps>;
51
- declare const SelectableTag: {
52
- <T extends React.ElementType>({ className, disabled, id, renderIcon, onChange, onClick, selected, size, text, ...other }: SelectableTagProps<T>): import("react/jsx-runtime").JSX.Element;
53
- propTypes: {
54
- /**
55
- * Provide a custom className that is applied to the containing <span>
56
- */
57
- className: PropTypes.Requireable<string>;
58
- /**
59
- * Specify if the `SelectableTag` is disabled
60
- */
61
- disabled: PropTypes.Requireable<boolean>;
62
- /**
63
- * Specify the id for the tag.
64
- */
65
- id: PropTypes.Requireable<string>;
66
- /**
67
- * A component used to render an icon.
68
- */
69
- renderIcon: PropTypes.Requireable<object>;
70
- /**
71
- * Provide an optional hook that is called when selected is changed
72
- */
73
- onChange: PropTypes.Requireable<(...args: any[]) => any>;
74
- /**
75
- * Provide an optional function to be called when the tag is clicked.
76
- */
77
- onClick: PropTypes.Requireable<(...args: any[]) => any>;
78
- /**
79
- * Specify the state of the selectable tag.
80
- */
81
- selected: PropTypes.Requireable<boolean>;
82
- /**
83
- * Specify the size of the Tag. Currently supports either `sm`,
84
- * `md` (default) or `lg` sizes.
85
- */
86
- size: PropTypes.Requireable<string>;
87
- /**
88
- * Provide text to be rendered inside of a the tag.
89
- */
90
- text: PropTypes.Requireable<string>;
91
- };
92
- };
50
+ declare const SelectableTag: React.ForwardRefExoticComponent<Omit<SelectableTagProps<React.ElementType<any, keyof React.JSX.IntrinsicElements>>, "ref"> & React.RefAttributes<HTMLButtonElement>>;
93
51
  export default SelectableTag;
@@ -20,6 +20,7 @@ require('../Tooltip/DefinitionTooltip.js');
20
20
  var Tooltip = require('../Tooltip/Tooltip.js');
21
21
  require('../Text/index.js');
22
22
  var isEllipsisActive = require('./isEllipsisActive.js');
23
+ var mergeRefs = require('../../tools/mergeRefs.js');
23
24
  var Text = require('../Text/Text.js');
24
25
 
25
26
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -28,7 +29,7 @@ var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
28
29
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
29
30
  var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
30
31
 
31
- const SelectableTag = _ref => {
32
+ const SelectableTag = /*#__PURE__*/React.forwardRef((_ref, forwardRef) => {
32
33
  let {
33
34
  className,
34
35
  disabled,
@@ -54,6 +55,7 @@ const SelectableTag = _ref => {
54
55
  setIsEllipsisApplied(isEllipsisActive.isEllipsisActive(newElement));
55
56
  }, [prefix, tagRef]);
56
57
  const tooltipClasses = cx__default["default"](`${prefix}--icon-tooltip`, `${prefix}--tag-label-tooltip`);
58
+ const combinedRef = mergeRefs["default"](tagRef, forwardRef);
57
59
  const handleClick = e => {
58
60
  setSelectedTag(!selectedTag);
59
61
  onChange?.(!selectedTag);
@@ -68,7 +70,7 @@ const SelectableTag = _ref => {
68
70
  onMouseEnter: () => false
69
71
  }, /*#__PURE__*/React__default["default"].createElement(Tag["default"], _rollupPluginBabelHelpers["extends"]({
70
72
  "aria-pressed": selectedTag !== false,
71
- ref: tagRef,
73
+ ref: combinedRef,
72
74
  size: size,
73
75
  renderIcon: renderIcon,
74
76
  disabled: disabled,
@@ -82,7 +84,7 @@ const SelectableTag = _ref => {
82
84
  }
83
85
  return /*#__PURE__*/React__default["default"].createElement(Tag["default"], _rollupPluginBabelHelpers["extends"]({
84
86
  "aria-pressed": selectedTag !== false,
85
- ref: tagRef,
87
+ ref: combinedRef,
86
88
  size: size,
87
89
  renderIcon: renderIcon,
88
90
  disabled: disabled,
@@ -93,7 +95,7 @@ const SelectableTag = _ref => {
93
95
  title: text,
94
96
  className: `${prefix}--tag__label`
95
97
  }, text));
96
- };
98
+ });
97
99
  SelectableTag.propTypes = {
98
100
  /**
99
101
  * Provide a custom className that is applied to the containing <span>
@@ -4,7 +4,7 @@
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 React, { ComponentType, FunctionComponent } from 'react';
7
+ import React, { type ComponentType, type FunctionComponent } from 'react';
8
8
  export type TreeNodeProps = {
9
9
  /**
10
10
  * **Note:** this is controlled by the parent TreeView component, do not set manually.
@@ -57,10 +57,17 @@ const TreeNode = /*#__PURE__*/React__default["default"].forwardRef((_ref, forwar
57
57
  } = React.useRef(nodeId || uniqueId["default"]());
58
58
  const controllableExpandedState = useControllableState.useControllableState({
59
59
  value: isExpanded,
60
- onChange: onToggle,
61
- defaultValue: defaultIsExpanded
60
+ onChange: newValue => {
61
+ onToggle?.(undefined, {
62
+ id,
63
+ isExpanded: newValue,
64
+ label,
65
+ value
66
+ });
67
+ },
68
+ defaultValue: defaultIsExpanded ?? false
62
69
  });
63
- const uncontrollableExpandedState = React.useState(isExpanded);
70
+ const uncontrollableExpandedState = React.useState(isExpanded ?? false);
64
71
  const [expanded, setExpanded] = enableTreeviewControllable ? controllableExpandedState : uncontrollableExpandedState;
65
72
  const currentNode = React.useRef(null);
66
73
  const currentNodeLabel = React.useRef(null);
@@ -254,7 +261,7 @@ const TreeNode = /*#__PURE__*/React__default["default"].forwardRef((_ref, forwar
254
261
  }
255
262
  if (!enableTreeviewControllable) {
256
263
  // sync props and state
257
- setExpanded(isExpanded);
264
+ setExpanded(isExpanded ?? false);
258
265
  }
259
266
  }, [children, depth, Icon, isExpanded, enableTreeviewControllable, setExpanded]);
260
267
  const treeNodeProps = {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright IBM Corp. 2016, 2023
2
+ * Copyright IBM Corp. 2016, 2025
3
3
  *
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.