@carbon/react 1.58.0 → 1.59.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 (46) hide show
  1. package/.playwright/INTERNAL_AVT_REPORT_DO_NOT_USE.json +1255 -1097
  2. package/es/components/Accordion/Accordion.Skeleton.d.ts +6 -1
  3. package/es/components/Accordion/Accordion.Skeleton.js +3 -1
  4. package/es/components/Accordion/Accordion.d.ts +11 -1
  5. package/es/components/Accordion/Accordion.js +8 -1
  6. package/es/components/CheckboxGroup/CheckboxGroup.js +7 -0
  7. package/es/components/ComboButton/index.d.ts +2 -1
  8. package/es/components/ComboButton/index.js +51 -31
  9. package/es/components/ContainedList/index.js +4 -0
  10. package/es/components/ListBox/ListBoxMenuItem.js +1 -1
  11. package/es/components/RadioTile/RadioTile.d.ts +9 -0
  12. package/es/components/RadioTile/RadioTile.js +24 -3
  13. package/es/components/Tag/DismissibleTag.js +7 -9
  14. package/es/components/Tag/OperationalTag.js +9 -10
  15. package/es/components/Tag/SelectableTag.js +9 -10
  16. package/es/components/Tag/Tag.d.ts +4 -60
  17. package/es/components/Tag/Tag.js +14 -14
  18. package/es/components/Tag/isEllipsisActive.d.ts +7 -0
  19. package/es/components/Tag/isEllipsisActive.js +15 -0
  20. package/es/components/Tooltip/Tooltip.js +42 -22
  21. package/es/components/UIShell/Content.d.ts +3 -3
  22. package/es/components/UIShell/SwitcherItem.d.ts +5 -1
  23. package/es/components/UIShell/SwitcherItem.js +7 -1
  24. package/lib/components/Accordion/Accordion.Skeleton.d.ts +6 -1
  25. package/lib/components/Accordion/Accordion.Skeleton.js +3 -1
  26. package/lib/components/Accordion/Accordion.d.ts +11 -1
  27. package/lib/components/Accordion/Accordion.js +8 -1
  28. package/lib/components/CheckboxGroup/CheckboxGroup.js +7 -0
  29. package/lib/components/ComboButton/index.d.ts +2 -1
  30. package/lib/components/ComboButton/index.js +45 -25
  31. package/lib/components/ContainedList/index.js +4 -0
  32. package/lib/components/ListBox/ListBoxMenuItem.js +1 -1
  33. package/lib/components/RadioTile/RadioTile.d.ts +9 -0
  34. package/lib/components/RadioTile/RadioTile.js +24 -3
  35. package/lib/components/Tag/DismissibleTag.js +6 -8
  36. package/lib/components/Tag/OperationalTag.js +8 -9
  37. package/lib/components/Tag/SelectableTag.js +8 -9
  38. package/lib/components/Tag/Tag.d.ts +4 -60
  39. package/lib/components/Tag/Tag.js +13 -13
  40. package/lib/components/Tag/isEllipsisActive.d.ts +7 -0
  41. package/lib/components/Tag/isEllipsisActive.js +19 -0
  42. package/lib/components/Tooltip/Tooltip.js +42 -22
  43. package/lib/components/UIShell/Content.d.ts +3 -3
  44. package/lib/components/UIShell/SwitcherItem.d.ts +5 -1
  45. package/lib/components/UIShell/SwitcherItem.js +7 -1
  46. package/package.json +3 -3
@@ -28,8 +28,13 @@ interface AccordionSkeletonProps {
28
28
  * `false` to not display the first item opened.
29
29
  */
30
30
  open?: boolean;
31
+ /**
32
+ * Specify if the Accordion should be an ordered list,
33
+ * default is `false`
34
+ */
35
+ ordered?: boolean;
31
36
  }
32
- declare function AccordionSkeleton({ align, className, count, isFlush, open, ...rest }: AccordionSkeletonProps): import("react/jsx-runtime").JSX.Element;
37
+ declare function AccordionSkeleton({ align, className, count, isFlush, open, ordered, ...rest }: AccordionSkeletonProps): import("react/jsx-runtime").JSX.Element;
33
38
  declare namespace AccordionSkeleton {
34
39
  var propTypes: {
35
40
  /**
@@ -21,6 +21,7 @@ function AccordionSkeleton(_ref) {
21
21
  count = 4,
22
22
  isFlush,
23
23
  open = true,
24
+ ordered = false,
24
25
  ...rest
25
26
  } = _ref;
26
27
  const prefix = usePrefix();
@@ -29,7 +30,8 @@ function AccordionSkeleton(_ref) {
29
30
  [`${prefix}--accordion--flush`]: isFlush && align !== 'start'
30
31
  });
31
32
  const numSkeletonItems = open ? count - 1 : count;
32
- return /*#__PURE__*/React__default.createElement("ul", _extends({
33
+ const ListTag = ordered ? 'ol' : 'ul';
34
+ return /*#__PURE__*/React__default.createElement(ListTag, _extends({
33
35
  className: classes
34
36
  }, rest), open && /*#__PURE__*/React__default.createElement("li", {
35
37
  className: `${prefix}--accordion__item ${prefix}--accordion__item--active`
@@ -27,13 +27,18 @@ export interface AccordionProps {
27
27
  * default is `false`, does not work with `align="start"`.
28
28
  */
29
29
  isFlush?: boolean;
30
+ /**
31
+ * Specify if the Accordion should be an ordered list,
32
+ * default is `false`
33
+ */
34
+ ordered?: boolean;
30
35
  /**
31
36
  * Specify the size of the Accordion. Currently
32
37
  * supports the following: `sm`, `md`, `lg`
33
38
  */
34
39
  size?: 'sm' | 'md' | 'lg';
35
40
  }
36
- declare function Accordion({ align, children, className: customClassName, disabled, isFlush, size, ...rest }: PropsWithChildren<AccordionProps>): import("react/jsx-runtime").JSX.Element;
41
+ declare function Accordion({ align, children, className: customClassName, disabled, isFlush, ordered, size, ...rest }: PropsWithChildren<AccordionProps>): import("react/jsx-runtime").JSX.Element;
37
42
  declare namespace Accordion {
38
43
  var propTypes: {
39
44
  /**
@@ -56,6 +61,11 @@ declare namespace Accordion {
56
61
  * Specify whether Accordion text should be flush, default is false, does not work with align="start"
57
62
  */
58
63
  isFlush: PropTypes.Requireable<boolean>;
64
+ /**
65
+ * Specify if the Accordion should be an ordered list,
66
+ * default is `false`
67
+ */
68
+ ordered: PropTypes.Requireable<boolean>;
59
69
  /**
60
70
  * Specify the size of the Accordion. Currently supports the following:
61
71
  */
@@ -19,6 +19,7 @@ function Accordion(_ref) {
19
19
  className: customClassName,
20
20
  disabled = false,
21
21
  isFlush = false,
22
+ ordered = false,
22
23
  size,
23
24
  ...rest
24
25
  } = _ref;
@@ -30,9 +31,10 @@ function Accordion(_ref) {
30
31
  [`${prefix}--layout--size-${size}`]: size,
31
32
  [`${prefix}--accordion--flush`]: isFlush && align !== 'start'
32
33
  });
34
+ const ListTag = ordered ? 'ol' : 'ul';
33
35
  return /*#__PURE__*/React__default.createElement(AccordionProvider, {
34
36
  disabled: disabled
35
- }, /*#__PURE__*/React__default.createElement("ul", _extends({
37
+ }, /*#__PURE__*/React__default.createElement(ListTag, _extends({
36
38
  className: className
37
39
  }, rest), children));
38
40
  }
@@ -57,6 +59,11 @@ Accordion.propTypes = {
57
59
  * Specify whether Accordion text should be flush, default is false, does not work with align="start"
58
60
  */
59
61
  isFlush: PropTypes.bool,
62
+ /**
63
+ * Specify if the Accordion should be an ordered list,
64
+ * default is `false`
65
+ */
66
+ ordered: PropTypes.bool,
60
67
  /**
61
68
  * Specify the size of the Accordion. Currently supports the following:
62
69
  */
@@ -27,6 +27,7 @@ function CheckboxGroup(_ref) {
27
27
  warn,
28
28
  warnText,
29
29
  slug,
30
+ orientation = 'vertical',
30
31
  ...rest
31
32
  } = _ref;
32
33
  const prefix = usePrefix();
@@ -39,6 +40,7 @@ function CheckboxGroup(_ref) {
39
40
  className: `${prefix}--form__helper-text`
40
41
  }, helperText) : null;
41
42
  const fieldsetClasses = cx(`${prefix}--checkbox-group`, className, {
43
+ [`${prefix}--checkbox-group--${orientation}`]: orientation === 'horizontal',
42
44
  [`${prefix}--checkbox-group--readonly`]: readOnly,
43
45
  [`${prefix}--checkbox-group--invalid`]: !readOnly && invalid,
44
46
  [`${prefix}--checkbox-group--warning`]: showWarning,
@@ -58,6 +60,7 @@ function CheckboxGroup(_ref) {
58
60
  "data-invalid": invalid ? true : undefined,
59
61
  "aria-labelledby": rest['aria-labelledby'] || legendId,
60
62
  "aria-readonly": readOnly,
63
+ orientation: "vertical",
61
64
  "aria-describedby": !invalid && !warn && helper ? helperId : undefined
62
65
  }, rest), /*#__PURE__*/React__default.createElement("legend", {
63
66
  className: `${prefix}--label`,
@@ -104,6 +107,10 @@ CheckboxGroup.propTypes = {
104
107
  * Provide the text to be rendered inside of the fieldset <legend>
105
108
  */
106
109
  legendText: PropTypes.node.isRequired,
110
+ /**
111
+ * Provide the orientation for how the checkbox should be displayed
112
+ */
113
+ orientation: PropTypes.oneOf(['horizontal', 'vertical']),
107
114
  /**
108
115
  * Whether the CheckboxGroup should be read-only
109
116
  */
@@ -8,6 +8,7 @@ import React from 'react';
8
8
  import { IconButton } from '../IconButton';
9
9
  import Button from '../Button';
10
10
  import { Menu } from '../Menu';
11
+ export type MenuAlignment = 'top' | 'top-start' | 'top-end' | 'bottom' | 'bottom-start' | 'bottom-end';
11
12
  interface ComboButtonProps {
12
13
  /**
13
14
  * A collection of `MenuItems` to be rendered as additional actions for this `ComboButton`.
@@ -28,7 +29,7 @@ interface ComboButtonProps {
28
29
  /**
29
30
  * Experimental property. Specify how the menu should align with the button element
30
31
  */
31
- menuAlignment?: React.ComponentProps<typeof Menu>['menuAlignment'];
32
+ menuAlignment?: MenuAlignment;
32
33
  /**
33
34
  * Provide an optional function to be called when the primary action element is clicked.
34
35
  */
@@ -6,7 +6,7 @@
6
6
  */
7
7
 
8
8
  import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
- import React__default, { useRef, useState } from 'react';
9
+ import React__default, { useRef, useLayoutEffect } from 'react';
10
10
  import PropTypes from 'prop-types';
11
11
  import cx from 'classnames';
12
12
  import { ChevronDown } from '@carbon/icons-react';
@@ -17,11 +17,11 @@ import { Menu } from '../Menu/Menu.js';
17
17
  import '../Menu/MenuItem.js';
18
18
  import { useAttachedMenu } from '../../internal/useAttachedMenu.js';
19
19
  import { useId } from '../../internal/useId.js';
20
- import { useMergedRefs } from '../../internal/useMergedRefs.js';
21
20
  import { usePrefix } from '../../internal/usePrefix.js';
21
+ import { flip, size, useFloating, autoUpdate } from '@floating-ui/react';
22
+ import mergeRefs from '../../tools/mergeRefs.js';
22
23
 
23
24
  var _ChevronDown;
24
- const spacing = 0; // top and bottom spacing between the button and the menu. in px
25
25
  const defaultTranslations = {
26
26
  'carbon.combo-button.additional-actions': 'Additional actions'
27
27
  };
@@ -35,7 +35,7 @@ const ComboButton = /*#__PURE__*/React__default.forwardRef(function ComboButton(
35
35
  disabled,
36
36
  label,
37
37
  onClick,
38
- size = 'lg',
38
+ size: size$1 = 'lg',
39
39
  menuAlignment = 'bottom',
40
40
  tooltipAlignment,
41
41
  translateWithId: t = defaultTranslateWithId,
@@ -44,23 +44,54 @@ const ComboButton = /*#__PURE__*/React__default.forwardRef(function ComboButton(
44
44
  const id = useId('combobutton');
45
45
  const prefix = usePrefix();
46
46
  const containerRef = useRef(null);
47
- const menuRef = useRef(null);
48
- const ref = useMergedRefs([forwardRef, containerRef]);
49
- const [width, setWidth] = useState(0);
47
+ const middlewares = [flip({
48
+ crossAxis: false
49
+ })];
50
+ if (menuAlignment === 'bottom' || menuAlignment === 'top') {
51
+ middlewares.push(size({
52
+ apply(_ref2) {
53
+ let {
54
+ rects,
55
+ elements
56
+ } = _ref2;
57
+ Object.assign(elements.floating.style, {
58
+ width: `${rects.reference.width}px`
59
+ });
60
+ }
61
+ }));
62
+ }
63
+ const {
64
+ refs,
65
+ floatingStyles,
66
+ placement,
67
+ middlewareData
68
+ } = useFloating({
69
+ placement: menuAlignment,
70
+ // The floating element is positioned relative to its nearest
71
+ // containing block (usually the viewport). It will in many cases also
72
+ // “break” the floating element out of a clipping ancestor.
73
+ // https://floating-ui.com/docs/misc#clipping
74
+ strategy: 'fixed',
75
+ // Middleware order matters, arrow should be last
76
+ middleware: middlewares,
77
+ whileElementsMounted: autoUpdate
78
+ });
79
+ const ref = mergeRefs(forwardRef, containerRef, refs.setReference);
50
80
  const {
51
81
  open,
52
- x,
53
- y,
54
82
  handleClick: hookOnClick,
55
83
  handleMousedown: handleTriggerMousedown,
56
84
  handleClose
57
85
  } = useAttachedMenu(containerRef);
86
+ useLayoutEffect(() => {
87
+ Object.keys(floatingStyles).forEach(style => {
88
+ if (refs.floating.current) {
89
+ refs.floating.current.style[style] = floatingStyles[style];
90
+ }
91
+ });
92
+ }, [floatingStyles, refs.floating, middlewareData, placement, open]);
58
93
  function handleTriggerClick() {
59
94
  if (containerRef.current) {
60
- const {
61
- width: w
62
- } = containerRef.current.getBoundingClientRect();
63
- setWidth(w);
64
95
  hookOnClick();
65
96
  }
66
97
  }
@@ -69,16 +100,7 @@ const ComboButton = /*#__PURE__*/React__default.forwardRef(function ComboButton(
69
100
  onClick(e);
70
101
  }
71
102
  }
72
- function handleOpen() {
73
- if (menuRef.current) {
74
- menuRef.current.style.inlineSize = `${width}px`;
75
- menuRef.current.style.minInlineSize = `${width}px`;
76
- if (menuAlignment !== 'bottom' && menuAlignment !== 'top') {
77
- menuRef.current.style.inlineSize = `fit-content`;
78
- }
79
- }
80
- }
81
- const containerClasses = cx(`${prefix}--combo-button__container`, `${prefix}--combo-button__container--${size}`, {
103
+ const containerClasses = cx(`${prefix}--combo-button__container`, `${prefix}--combo-button__container--${size$1}`, {
82
104
  [`${prefix}--combo-button__container--open`]: open
83
105
  }, className);
84
106
  const menuClasses = cx(`${prefix}--combo-button__${menuAlignment}`);
@@ -92,13 +114,14 @@ const ComboButton = /*#__PURE__*/React__default.forwardRef(function ComboButton(
92
114
  className: primaryActionClasses
93
115
  }, /*#__PURE__*/React__default.createElement(Button, {
94
116
  title: label,
95
- size: size,
117
+ size: size$1,
96
118
  disabled: disabled,
97
119
  onClick: handlePrimaryActionClick
98
120
  }, label)), /*#__PURE__*/React__default.createElement(IconButton, {
121
+ ref: refs.setReference,
99
122
  className: triggerClasses,
100
123
  label: t('carbon.combo-button.additional-actions'),
101
- size: size,
124
+ size: size$1,
102
125
  disabled: disabled,
103
126
  align: tooltipAlignment,
104
127
  "aria-haspopup": true,
@@ -110,16 +133,13 @@ const ComboButton = /*#__PURE__*/React__default.forwardRef(function ComboButton(
110
133
  containerRef: containerRef,
111
134
  menuAlignment: menuAlignment,
112
135
  className: menuClasses,
113
- ref: menuRef,
136
+ ref: refs.setFloating,
114
137
  id: id,
115
138
  label: t('carbon.combo-button.additional-actions'),
116
139
  mode: "basic",
117
- size: size,
140
+ size: size$1,
118
141
  open: open,
119
- onClose: handleClose,
120
- onOpen: handleOpen,
121
- x: x,
122
- y: [y[0] - spacing, y[1] + spacing]
142
+ onClose: handleClose
123
143
  }, children));
124
144
  });
125
145
  ComboButton.propTypes = {
@@ -5,9 +5,13 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
+ import { deprecateFieldOnObject } from '../../internal/deprecateFieldOnObject.js';
8
9
  import ContainedList from './ContainedList.js';
9
10
  export { default as ContainedList, default } from './ContainedList.js';
10
11
  import ContainedListItem from './ContainedListItem/ContainedListItem.js';
11
12
  export { default as ContainedListItem } from './ContainedListItem/ContainedListItem.js';
12
13
 
13
14
  ContainedList.ContainedListItem = ContainedListItem;
15
+ if (process.env.NODE_ENV !== "production") {
16
+ deprecateFieldOnObject(ContainedList, 'ContainedListItem', ContainedListItem);
17
+ }
@@ -18,7 +18,7 @@ function useIsTruncated(ref) {
18
18
  const {
19
19
  offsetWidth,
20
20
  scrollWidth
21
- } = element.lastElementChild?.lastElementChild || element;
21
+ } = element;
22
22
  setIsTruncated(offsetWidth < scrollWidth);
23
23
  }, [ref, setIsTruncated]);
24
24
  return isTruncated;
@@ -22,6 +22,11 @@ export interface RadioTileProps {
22
22
  * Specify whether the `RadioTile` should be disabled.
23
23
  */
24
24
  disabled?: boolean;
25
+ /**
26
+ * **Experimental**: Specify if the `ExpandableTile` component should be rendered with rounded corners.
27
+ * Only valid when `slug` prop is present
28
+ */
29
+ hasRoundedCorners?: boolean;
25
30
  /**
26
31
  * Provide a unique id for the underlying `<input>`.
27
32
  */
@@ -42,6 +47,10 @@ export interface RadioTileProps {
42
47
  * the underlying `<input>` changes.
43
48
  */
44
49
  onChange?: (value: string | number, name: string | undefined, event: React.ChangeEvent<HTMLInputElement> | React.KeyboardEvent<HTMLInputElement>) => void;
50
+ /**
51
+ * **Experimental**: Provide a `Slug` component to be rendered inside the `SelectableTile` component
52
+ */
53
+ slug?: React.ReactNode;
45
54
  /**
46
55
  * Specify the tab index of the underlying `<input>`.
47
56
  */
@@ -33,15 +33,19 @@ const RadioTile = /*#__PURE__*/React__default.forwardRef(function RadioTile(_ref
33
33
  id,
34
34
  onChange = noopFn,
35
35
  tabIndex = 0,
36
+ hasRoundedCorners,
37
+ slug,
36
38
  required,
37
39
  ...rest
38
40
  } = _ref;
39
41
  const prefix = usePrefix();
40
42
  const inputId = useFallbackId(id);
41
- const className = cx(customClassName, `${prefix}--tile`, `${prefix}--tile--selectable`, {
43
+ const className = cx(customClassName, `${prefix}--tile`, `${prefix}--tile--selectable`, `${prefix}--tile--radio`, {
42
44
  [`${prefix}--tile--is-selected`]: checked,
43
45
  [`${prefix}--tile--light`]: light,
44
- [`${prefix}--tile--disabled`]: disabled
46
+ [`${prefix}--tile--disabled`]: disabled,
47
+ [`${prefix}--tile--slug`]: slug,
48
+ [`${prefix}--tile--slug-rounded`]: slug && hasRoundedCorners
45
49
  });
46
50
  const v12TileRadioIcons = useFeatureFlag('enable-v12-tile-radio-icons');
47
51
  function icon() {
@@ -64,6 +68,14 @@ const RadioTile = /*#__PURE__*/React__default.forwardRef(function RadioTile(_ref
64
68
  onChange(value, name, evt);
65
69
  }
66
70
  }
71
+
72
+ // Slug is always size `xs`
73
+ let normalizedSlug;
74
+ if (slug && slug['type']?.displayName === 'Slug') {
75
+ normalizedSlug = /*#__PURE__*/React__default.cloneElement(slug, {
76
+ size: 'xs'
77
+ });
78
+ }
67
79
  return /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement("input", {
68
80
  checked: checked,
69
81
  className: `${prefix}--tile-input`,
@@ -84,7 +96,7 @@ const RadioTile = /*#__PURE__*/React__default.forwardRef(function RadioTile(_ref
84
96
  className: `${prefix}--tile__checkmark`
85
97
  }, icon()), /*#__PURE__*/React__default.createElement(Text, {
86
98
  className: `${prefix}--tile-content`
87
- }, children)));
99
+ }, children), normalizedSlug));
88
100
  });
89
101
  RadioTile.displayName = 'RadioTile';
90
102
  RadioTile.propTypes = {
@@ -104,6 +116,11 @@ RadioTile.propTypes = {
104
116
  * Specify whether the `RadioTile` should be disabled.
105
117
  */
106
118
  disabled: PropTypes.bool,
119
+ /**
120
+ * Specify if the `ExpandableTile` component should be rendered with rounded corners.
121
+ * Only valid when `slug` prop is present
122
+ */
123
+ hasRoundedCorners: PropTypes.bool,
107
124
  /**
108
125
  * Provide a unique id for the underlying `<input>`.
109
126
  */
@@ -126,6 +143,10 @@ RadioTile.propTypes = {
126
143
  * `true` to specify if the control is required.
127
144
  */
128
145
  required: PropTypes.bool,
146
+ /**
147
+ * **Experimental**: Provide a `Slug` component to be rendered inside the `SelectableTile` component
148
+ */
149
+ slug: PropTypes.node,
129
150
  /**
130
151
  * Specify the tab index of the underlying `<input>`.
131
152
  */
@@ -7,7 +7,7 @@
7
7
 
8
8
  import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
9
  import PropTypes from 'prop-types';
10
- import React__default, { useState, useLayoutEffect } from 'react';
10
+ import React__default, { useRef, useState, useLayoutEffect } from 'react';
11
11
  import cx from 'classnames';
12
12
  import setupGetInstanceId from '../../tools/setupGetInstanceId.js';
13
13
  import { usePrefix } from '../../internal/usePrefix.js';
@@ -16,6 +16,7 @@ import { Close } from '@carbon/icons-react';
16
16
  import '../Tooltip/DefinitionTooltip.js';
17
17
  import { Tooltip } from '../Tooltip/Tooltip.js';
18
18
  import '../Text/index.js';
19
+ import { isEllipsisActive } from './isEllipsisActive.js';
19
20
  import { Text } from '../Text/Text.js';
20
21
 
21
22
  var _Close;
@@ -35,18 +36,14 @@ const DismissibleTag = _ref => {
35
36
  ...other
36
37
  } = _ref;
37
38
  const prefix = usePrefix();
39
+ const tagLabelRef = useRef();
38
40
  const tagId = id || `tag-${getInstanceId()}`;
39
41
  const tagClasses = cx(`${prefix}--tag--filter`, className);
40
42
  const [isEllipsisApplied, setIsEllipsisApplied] = useState(false);
41
- const isEllipsisActive = element => {
42
- setIsEllipsisApplied(element.offsetWidth < element.scrollWidth);
43
- return element.offsetWidth < element.scrollWidth;
44
- };
45
43
  useLayoutEffect(() => {
46
- const elementTagId = document.querySelector(`#${tagId}`);
47
- const newElement = elementTagId?.getElementsByClassName(`${prefix}--tag__label`)[0];
48
- isEllipsisActive(newElement);
49
- }, [prefix, tagId]);
44
+ const newElement = tagLabelRef.current?.getElementsByClassName(`${prefix}--tag__label`)[0];
45
+ setIsEllipsisApplied(isEllipsisActive(newElement));
46
+ }, [prefix, tagLabelRef]);
50
47
  const handleClose = event => {
51
48
  if (onClose) {
52
49
  event.stopPropagation();
@@ -70,6 +67,7 @@ const DismissibleTag = _ref => {
70
67
  } = other;
71
68
  const dismissLabel = `Dismiss "${text}"`;
72
69
  return /*#__PURE__*/React__default.createElement(Tag, _extends({
70
+ ref: tagLabelRef,
73
71
  type: type,
74
72
  size: size,
75
73
  renderIcon: renderIcon,
@@ -7,7 +7,7 @@
7
7
 
8
8
  import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
9
  import PropTypes from 'prop-types';
10
- import React__default, { useState, useLayoutEffect } from 'react';
10
+ import React__default, { useRef, useState, useLayoutEffect } from 'react';
11
11
  import cx from 'classnames';
12
12
  import setupGetInstanceId from '../../tools/setupGetInstanceId.js';
13
13
  import { usePrefix } from '../../internal/usePrefix.js';
@@ -15,6 +15,7 @@ import Tag, { SIZES } from './Tag.js';
15
15
  import '../Tooltip/DefinitionTooltip.js';
16
16
  import { Tooltip } from '../Tooltip/Tooltip.js';
17
17
  import '../Text/index.js';
18
+ import { isEllipsisActive } from './isEllipsisActive.js';
18
19
  import { Text } from '../Text/Text.js';
19
20
 
20
21
  const getInstanceId = setupGetInstanceId();
@@ -43,18 +44,14 @@ const OperationalTag = _ref => {
43
44
  ...other
44
45
  } = _ref;
45
46
  const prefix = usePrefix();
47
+ const tagRef = useRef();
46
48
  const tagId = id || `tag-${getInstanceId()}`;
47
49
  const tagClasses = cx(`${prefix}--tag--operational`, className);
48
50
  const [isEllipsisApplied, setIsEllipsisApplied] = useState(false);
49
- const isEllipsisActive = element => {
50
- setIsEllipsisApplied(element.offsetWidth < element.scrollWidth);
51
- return element.offsetWidth < element.scrollWidth;
52
- };
53
51
  useLayoutEffect(() => {
54
- const elementTagId = document.querySelector(`#${tagId}`);
55
- const newElement = elementTagId?.getElementsByClassName(`${prefix}--tag__label`)[0];
56
- isEllipsisActive(newElement);
57
- }, [prefix, tagId]);
52
+ const newElement = tagRef.current?.getElementsByClassName(`${prefix}--tag__label`)[0];
53
+ setIsEllipsisApplied(isEllipsisActive(newElement));
54
+ }, [prefix, tagRef]);
58
55
  let normalizedSlug;
59
56
  if (slug && slug['type']?.displayName === 'Slug') {
60
57
  normalizedSlug = /*#__PURE__*/React__default.cloneElement(slug, {
@@ -69,9 +66,10 @@ const OperationalTag = _ref => {
69
66
  align: "bottom",
70
67
  className: tooltipClasses,
71
68
  leaveDelayMs: 0,
72
- onMouseEnter: false,
69
+ onMouseEnter: () => false,
73
70
  closeOnActivation: true
74
71
  }, /*#__PURE__*/React__default.createElement(Tag, _extends({
72
+ ref: tagRef,
75
73
  type: type,
76
74
  size: size,
77
75
  renderIcon: renderIcon,
@@ -84,6 +82,7 @@ const OperationalTag = _ref => {
84
82
  }, text), normalizedSlug));
85
83
  }
86
84
  return /*#__PURE__*/React__default.createElement(Tag, _extends({
85
+ ref: tagRef,
87
86
  type: type,
88
87
  size: size,
89
88
  renderIcon: renderIcon,
@@ -7,7 +7,7 @@
7
7
 
8
8
  import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
9
  import PropTypes from 'prop-types';
10
- import React__default, { useState, useLayoutEffect } from 'react';
10
+ import React__default, { useRef, useState, useLayoutEffect } from 'react';
11
11
  import cx from 'classnames';
12
12
  import setupGetInstanceId from '../../tools/setupGetInstanceId.js';
13
13
  import { usePrefix } from '../../internal/usePrefix.js';
@@ -15,6 +15,7 @@ import Tag, { SIZES } from './Tag.js';
15
15
  import '../Tooltip/DefinitionTooltip.js';
16
16
  import { Tooltip } from '../Tooltip/Tooltip.js';
17
17
  import '../Text/index.js';
18
+ import { isEllipsisActive } from './isEllipsisActive.js';
18
19
  import { Text } from '../Text/Text.js';
19
20
 
20
21
  const getInstanceId = setupGetInstanceId();
@@ -31,21 +32,17 @@ const SelectableTag = _ref => {
31
32
  ...other
32
33
  } = _ref;
33
34
  const prefix = usePrefix();
35
+ const tagRef = useRef();
34
36
  const tagId = id || `tag-${getInstanceId()}`;
35
37
  const [selectedTag, setSelectedTag] = useState(selected);
36
38
  const tagClasses = cx(`${prefix}--tag--selectable`, className, {
37
39
  [`${prefix}--tag--selectable-selected`]: selectedTag
38
40
  });
39
41
  const [isEllipsisApplied, setIsEllipsisApplied] = useState(false);
40
- const isEllipsisActive = element => {
41
- setIsEllipsisApplied(element.offsetWidth < element.scrollWidth);
42
- return element.offsetWidth < element.scrollWidth;
43
- };
44
42
  useLayoutEffect(() => {
45
- const elementTagId = document.querySelector(`#${tagId}`);
46
- const newElement = elementTagId?.getElementsByClassName(`${prefix}--tag__label`)[0];
47
- isEllipsisActive(newElement);
48
- }, [prefix, tagId]);
43
+ const newElement = tagRef.current?.getElementsByClassName(`${prefix}--tag__label`)[0];
44
+ setIsEllipsisApplied(isEllipsisActive(newElement));
45
+ }, [prefix, tagRef]);
49
46
  let normalizedSlug;
50
47
  if (slug && slug['type']?.displayName === 'Slug') {
51
48
  normalizedSlug = /*#__PURE__*/React__default.cloneElement(slug, {
@@ -67,8 +64,9 @@ const SelectableTag = _ref => {
67
64
  align: "bottom",
68
65
  className: tooltipClasses,
69
66
  leaveDelayMs: 0,
70
- onMouseEnter: false
67
+ onMouseEnter: () => false
71
68
  }, /*#__PURE__*/React__default.createElement(Tag, _extends({
69
+ ref: tagRef,
72
70
  slug: slug,
73
71
  size: size,
74
72
  renderIcon: renderIcon,
@@ -82,6 +80,7 @@ const SelectableTag = _ref => {
82
80
  }, text), normalizedSlug));
83
81
  }
84
82
  return /*#__PURE__*/React__default.createElement(Tag, _extends({
83
+ ref: tagRef,
85
84
  slug: slug,
86
85
  size: size,
87
86
  renderIcon: renderIcon,