@carbon/react 1.58.0 → 1.58.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.
@@ -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,
@@ -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
  export declare const TYPES: {
@@ -40,7 +39,7 @@ export interface TagBaseProps {
40
39
  */
41
40
  disabled?: boolean;
42
41
  /**
43
- * @deprecated This property is deprecated and will be removed in the next major version. Use DismissibleTag instead.
42
+ * @deprecated The `filter` prop has been deprecated and will be removed in the next major version. Use DismissibleTag instead.
44
43
  */
45
44
  filter?: boolean;
46
45
  /**
@@ -48,7 +47,7 @@ export interface TagBaseProps {
48
47
  */
49
48
  id?: string;
50
49
  /**
51
- * @deprecated This property is deprecated and will be removed in the next major version. Use DismissibleTag instead.
50
+ * @deprecated The `onClose` prop has been deprecated and will be removed in the next major version. Use DismissibleTag instead.
52
51
  */
53
52
  onClose?: (event: React.MouseEvent<HTMLButtonElement>) => void;
54
53
  /**
@@ -66,7 +65,7 @@ export interface TagBaseProps {
66
65
  */
67
66
  slug?: ReactNode;
68
67
  /**
69
- * @deprecated This property is deprecated and will be removed in the next major version. Use DismissibleTag instead.
68
+ * @deprecated The `title` prop has been deprecated and will be removed in the next major version. Use DismissibleTag instead.
70
69
  */
71
70
  title?: string;
72
71
  /**
@@ -75,61 +74,6 @@ export interface TagBaseProps {
75
74
  type?: keyof typeof TYPES;
76
75
  }
77
76
  export type TagProps<T extends React.ElementType> = PolymorphicProps<T, TagBaseProps>;
78
- declare const Tag: {
79
- <T extends React.ElementType<any>>({ children, className, id, type, filter, renderIcon: CustomIconElement, title, disabled, onClose, size, as: BaseComponent, slug, ...other }: TagProps<T>): import("react/jsx-runtime").JSX.Element;
80
- propTypes: {
81
- /**
82
- * Provide an alternative tag or component to use instead of the default
83
- * wrapping element
84
- */
85
- as: PropTypes.Requireable<PropTypes.ReactComponentLike>;
86
- /**
87
- * Provide content to be rendered inside of a `Tag`
88
- */
89
- children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
90
- /**
91
- * Provide a custom className that is applied to the containing <span>
92
- */
93
- className: PropTypes.Requireable<string>;
94
- /**
95
- * Specify if the `Tag` is disabled
96
- */
97
- disabled: PropTypes.Requireable<boolean>;
98
- /**
99
- * Determine if `Tag` is a filter/chip
100
- */
101
- filter: (props: any, propName: any, componentName: any, ...rest: any[]) => any;
102
- /**
103
- * Specify the id for the tag.
104
- */
105
- id: PropTypes.Requireable<string>;
106
- /**
107
- * Click handler for filter tag close button.
108
- */
109
- onClose: (props: any, propName: any, componentName: any, ...rest: any[]) => any;
110
- /**
111
- * Optional prop to render a custom icon.
112
- * Can be a React component class
113
- */
114
- renderIcon: PropTypes.Requireable<object>;
115
- /**
116
- * Specify the size of the Tag. Currently supports either `sm`,
117
- * `md` (default) or `lg` sizes.
118
- */
119
- size: PropTypes.Requireable<string>;
120
- /**
121
- * **Experimental:** Provide a `Slug` component to be rendered inside the `Tag` component
122
- */
123
- slug: PropTypes.Requireable<PropTypes.ReactNodeLike>;
124
- /**
125
- * Text to show on clear filters
126
- */
127
- title: (props: any, propName: any, componentName: any, ...rest: any[]) => any;
128
- /**
129
- * Specify the type of the `Tag`
130
- */
131
- type: PropTypes.Requireable<string>;
132
- };
133
- };
77
+ declare const Tag: React.ForwardRefExoticComponent<Omit<TagProps<React.ElementType<any>>, "ref"> & React.RefAttributes<HTMLElement | undefined>>;
134
78
  export declare const types: string[];
135
79
  export default Tag;
@@ -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 { Close } from '@carbon/icons-react';
13
13
  import setupGetInstanceId from '../../tools/setupGetInstanceId.js';
@@ -16,6 +16,8 @@ import '../Text/index.js';
16
16
  import deprecate from '../../prop-types/deprecate.js';
17
17
  import { DefinitionTooltip } from '../Tooltip/DefinitionTooltip.js';
18
18
  import '../Tooltip/Tooltip.js';
19
+ import { isEllipsisActive } from './isEllipsisActive.js';
20
+ import { useMergeRefs } from '@floating-ui/react';
19
21
  import { Text } from '../Text/Text.js';
20
22
 
21
23
  var _Close;
@@ -39,7 +41,7 @@ const SIZES = {
39
41
  md: 'md',
40
42
  lg: 'lg'
41
43
  };
42
- const Tag = _ref => {
44
+ const Tag = /*#__PURE__*/React__default.forwardRef(function Tag(_ref, forwardRef) {
43
45
  let {
44
46
  children,
45
47
  className,
@@ -59,17 +61,14 @@ const Tag = _ref => {
59
61
  ...other
60
62
  } = _ref;
61
63
  const prefix = usePrefix();
64
+ const tagRef = useRef();
65
+ const ref = useMergeRefs([forwardRef, tagRef]);
62
66
  const tagId = id || `tag-${getInstanceId()}`;
63
67
  const [isEllipsisApplied, setIsEllipsisApplied] = useState(false);
64
- const isEllipsisActive = element => {
65
- setIsEllipsisApplied(element.offsetWidth < element.scrollWidth);
66
- return element.offsetWidth < element.scrollWidth;
67
- };
68
68
  useLayoutEffect(() => {
69
- const elementTagId = document.querySelector(`#${tagId}`);
70
- const newElement = elementTagId?.getElementsByClassName(`${prefix}--tag__label`)[0];
71
- isEllipsisActive(newElement);
72
- }, [prefix, tagId]);
69
+ const newElement = tagRef.current?.getElementsByClassName(`${prefix}--tag__label`)[0];
70
+ setIsEllipsisApplied(isEllipsisActive(newElement));
71
+ }, [prefix, tagRef]);
73
72
  const conditions = [`${prefix}--tag--selectable`, `${prefix}--tag--filter`, `${prefix}--tag--operational`];
74
73
  const isInteractiveTag = conditions.some(el => className?.includes(el));
75
74
  const tagClasses = cx(`${prefix}--tag`, className, {
@@ -122,6 +121,7 @@ const Tag = _ref => {
122
121
  [`${prefix}--tag--${type}`]: type && !isInteractiveTag
123
122
  });
124
123
  return /*#__PURE__*/React__default.createElement(ComponentTag, _extends({
124
+ ref: ref,
125
125
  disabled: disabled,
126
126
  className: tagClasses,
127
127
  id: tagId
@@ -138,7 +138,7 @@ const Tag = _ref => {
138
138
  title: children !== null && children !== undefined ? children : typeText,
139
139
  className: labelClasses
140
140
  }, children !== null && children !== undefined ? children : typeText), normalizedSlug);
141
- };
141
+ });
142
142
  Tag.propTypes = {
143
143
  /**
144
144
  * Provide an alternative tag or component to use instead of the default
@@ -160,7 +160,7 @@ Tag.propTypes = {
160
160
  /**
161
161
  * Determine if `Tag` is a filter/chip
162
162
  */
163
- filter: deprecate(PropTypes.bool, 'This property is deprecated and will be removed in the next major version. Use DismissibleTag instead.'),
163
+ filter: deprecate(PropTypes.bool, 'The `filter` prop has been deprecated and will be removed in the next major version. Use DismissibleTag instead.'),
164
164
  /**
165
165
  * Specify the id for the tag.
166
166
  */
@@ -168,7 +168,7 @@ Tag.propTypes = {
168
168
  /**
169
169
  * Click handler for filter tag close button.
170
170
  */
171
- onClose: deprecate(PropTypes.func, 'This property is deprecated and will be removed in the next major version. Use DismissibleTag instead.'),
171
+ onClose: deprecate(PropTypes.func, 'The `onClose` prop has been deprecated and will be removed in the next major version. Use DismissibleTag instead.'),
172
172
  /**
173
173
  * Optional prop to render a custom icon.
174
174
  * Can be a React component class
@@ -186,7 +186,7 @@ Tag.propTypes = {
186
186
  /**
187
187
  * Text to show on clear filters
188
188
  */
189
- title: deprecate(PropTypes.string, 'This property is deprecated and will be removed in the next major version. Use DismissibleTag instead.'),
189
+ title: deprecate(PropTypes.string, 'The `title` prop has been deprecated and will be removed in the next major version. Use DismissibleTag instead.'),
190
190
  /**
191
191
  * Specify the type of the `Tag`
192
192
  */
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Copyright IBM Corp. 2024
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
+ export declare const isEllipsisActive: (element: any) => boolean;
@@ -0,0 +1,15 @@
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
+ */
7
+
8
+ const isEllipsisActive = element => {
9
+ if (element) {
10
+ return element?.offsetWidth < element?.scrollWidth;
11
+ }
12
+ return false;
13
+ };
14
+
15
+ export { isEllipsisActive };
@@ -85,7 +85,7 @@ function Tooltip(_ref) {
85
85
  }
86
86
  function onMouseEnter() {
87
87
  // Interactive Tags should not support onMouseEnter
88
- if (!rest?.onMouseEnter?.()) {
88
+ if (!rest?.onMouseEnter) {
89
89
  setIsPointerIntersecting(true);
90
90
  setOpen(true, enterDelayMs);
91
91
  }
@@ -20,6 +20,7 @@ var iconsReact = require('@carbon/icons-react');
20
20
  require('../Tooltip/DefinitionTooltip.js');
21
21
  var Tooltip = require('../Tooltip/Tooltip.js');
22
22
  require('../Text/index.js');
23
+ var isEllipsisActive = require('./isEllipsisActive.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 }; }
@@ -45,18 +46,14 @@ const DismissibleTag = _ref => {
45
46
  ...other
46
47
  } = _ref;
47
48
  const prefix = usePrefix.usePrefix();
49
+ const tagLabelRef = React.useRef();
48
50
  const tagId = id || `tag-${getInstanceId()}`;
49
51
  const tagClasses = cx__default["default"](`${prefix}--tag--filter`, className);
50
52
  const [isEllipsisApplied, setIsEllipsisApplied] = React.useState(false);
51
- const isEllipsisActive = element => {
52
- setIsEllipsisApplied(element.offsetWidth < element.scrollWidth);
53
- return element.offsetWidth < element.scrollWidth;
54
- };
55
53
  React.useLayoutEffect(() => {
56
- const elementTagId = document.querySelector(`#${tagId}`);
57
- const newElement = elementTagId?.getElementsByClassName(`${prefix}--tag__label`)[0];
58
- isEllipsisActive(newElement);
59
- }, [prefix, tagId]);
54
+ const newElement = tagLabelRef.current?.getElementsByClassName(`${prefix}--tag__label`)[0];
55
+ setIsEllipsisApplied(isEllipsisActive.isEllipsisActive(newElement));
56
+ }, [prefix, tagLabelRef]);
60
57
  const handleClose = event => {
61
58
  if (onClose) {
62
59
  event.stopPropagation();
@@ -80,6 +77,7 @@ const DismissibleTag = _ref => {
80
77
  } = other;
81
78
  const dismissLabel = `Dismiss "${text}"`;
82
79
  return /*#__PURE__*/React__default["default"].createElement(Tag["default"], _rollupPluginBabelHelpers["extends"]({
80
+ ref: tagLabelRef,
83
81
  type: type,
84
82
  size: size,
85
83
  renderIcon: renderIcon,
@@ -19,6 +19,7 @@ var Tag = require('./Tag.js');
19
19
  require('../Tooltip/DefinitionTooltip.js');
20
20
  var Tooltip = require('../Tooltip/Tooltip.js');
21
21
  require('../Text/index.js');
22
+ var isEllipsisActive = require('./isEllipsisActive.js');
22
23
  var Text = require('../Text/Text.js');
23
24
 
24
25
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -53,18 +54,14 @@ const OperationalTag = _ref => {
53
54
  ...other
54
55
  } = _ref;
55
56
  const prefix = usePrefix.usePrefix();
57
+ const tagRef = React.useRef();
56
58
  const tagId = id || `tag-${getInstanceId()}`;
57
59
  const tagClasses = cx__default["default"](`${prefix}--tag--operational`, className);
58
60
  const [isEllipsisApplied, setIsEllipsisApplied] = React.useState(false);
59
- const isEllipsisActive = element => {
60
- setIsEllipsisApplied(element.offsetWidth < element.scrollWidth);
61
- return element.offsetWidth < element.scrollWidth;
62
- };
63
61
  React.useLayoutEffect(() => {
64
- const elementTagId = document.querySelector(`#${tagId}`);
65
- const newElement = elementTagId?.getElementsByClassName(`${prefix}--tag__label`)[0];
66
- isEllipsisActive(newElement);
67
- }, [prefix, tagId]);
62
+ const newElement = tagRef.current?.getElementsByClassName(`${prefix}--tag__label`)[0];
63
+ setIsEllipsisApplied(isEllipsisActive.isEllipsisActive(newElement));
64
+ }, [prefix, tagRef]);
68
65
  let normalizedSlug;
69
66
  if (slug && slug['type']?.displayName === 'Slug') {
70
67
  normalizedSlug = /*#__PURE__*/React__default["default"].cloneElement(slug, {
@@ -79,9 +76,10 @@ const OperationalTag = _ref => {
79
76
  align: "bottom",
80
77
  className: tooltipClasses,
81
78
  leaveDelayMs: 0,
82
- onMouseEnter: false,
79
+ onMouseEnter: () => false,
83
80
  closeOnActivation: true
84
81
  }, /*#__PURE__*/React__default["default"].createElement(Tag["default"], _rollupPluginBabelHelpers["extends"]({
82
+ ref: tagRef,
85
83
  type: type,
86
84
  size: size,
87
85
  renderIcon: renderIcon,
@@ -94,6 +92,7 @@ const OperationalTag = _ref => {
94
92
  }, text), normalizedSlug));
95
93
  }
96
94
  return /*#__PURE__*/React__default["default"].createElement(Tag["default"], _rollupPluginBabelHelpers["extends"]({
95
+ ref: tagRef,
97
96
  type: type,
98
97
  size: size,
99
98
  renderIcon: renderIcon,
@@ -19,6 +19,7 @@ var Tag = require('./Tag.js');
19
19
  require('../Tooltip/DefinitionTooltip.js');
20
20
  var Tooltip = require('../Tooltip/Tooltip.js');
21
21
  require('../Text/index.js');
22
+ var isEllipsisActive = require('./isEllipsisActive.js');
22
23
  var Text = require('../Text/Text.js');
23
24
 
24
25
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -41,21 +42,17 @@ const SelectableTag = _ref => {
41
42
  ...other
42
43
  } = _ref;
43
44
  const prefix = usePrefix.usePrefix();
45
+ const tagRef = React.useRef();
44
46
  const tagId = id || `tag-${getInstanceId()}`;
45
47
  const [selectedTag, setSelectedTag] = React.useState(selected);
46
48
  const tagClasses = cx__default["default"](`${prefix}--tag--selectable`, className, {
47
49
  [`${prefix}--tag--selectable-selected`]: selectedTag
48
50
  });
49
51
  const [isEllipsisApplied, setIsEllipsisApplied] = React.useState(false);
50
- const isEllipsisActive = element => {
51
- setIsEllipsisApplied(element.offsetWidth < element.scrollWidth);
52
- return element.offsetWidth < element.scrollWidth;
53
- };
54
52
  React.useLayoutEffect(() => {
55
- const elementTagId = document.querySelector(`#${tagId}`);
56
- const newElement = elementTagId?.getElementsByClassName(`${prefix}--tag__label`)[0];
57
- isEllipsisActive(newElement);
58
- }, [prefix, tagId]);
53
+ const newElement = tagRef.current?.getElementsByClassName(`${prefix}--tag__label`)[0];
54
+ setIsEllipsisApplied(isEllipsisActive.isEllipsisActive(newElement));
55
+ }, [prefix, tagRef]);
59
56
  let normalizedSlug;
60
57
  if (slug && slug['type']?.displayName === 'Slug') {
61
58
  normalizedSlug = /*#__PURE__*/React__default["default"].cloneElement(slug, {
@@ -77,8 +74,9 @@ const SelectableTag = _ref => {
77
74
  align: "bottom",
78
75
  className: tooltipClasses,
79
76
  leaveDelayMs: 0,
80
- onMouseEnter: false
77
+ onMouseEnter: () => false
81
78
  }, /*#__PURE__*/React__default["default"].createElement(Tag["default"], _rollupPluginBabelHelpers["extends"]({
79
+ ref: tagRef,
82
80
  slug: slug,
83
81
  size: size,
84
82
  renderIcon: renderIcon,
@@ -92,6 +90,7 @@ const SelectableTag = _ref => {
92
90
  }, text), normalizedSlug));
93
91
  }
94
92
  return /*#__PURE__*/React__default["default"].createElement(Tag["default"], _rollupPluginBabelHelpers["extends"]({
93
+ ref: tagRef,
95
94
  slug: slug,
96
95
  size: size,
97
96
  renderIcon: renderIcon,
@@ -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
  export declare const TYPES: {
@@ -40,7 +39,7 @@ export interface TagBaseProps {
40
39
  */
41
40
  disabled?: boolean;
42
41
  /**
43
- * @deprecated This property is deprecated and will be removed in the next major version. Use DismissibleTag instead.
42
+ * @deprecated The `filter` prop has been deprecated and will be removed in the next major version. Use DismissibleTag instead.
44
43
  */
45
44
  filter?: boolean;
46
45
  /**
@@ -48,7 +47,7 @@ export interface TagBaseProps {
48
47
  */
49
48
  id?: string;
50
49
  /**
51
- * @deprecated This property is deprecated and will be removed in the next major version. Use DismissibleTag instead.
50
+ * @deprecated The `onClose` prop has been deprecated and will be removed in the next major version. Use DismissibleTag instead.
52
51
  */
53
52
  onClose?: (event: React.MouseEvent<HTMLButtonElement>) => void;
54
53
  /**
@@ -66,7 +65,7 @@ export interface TagBaseProps {
66
65
  */
67
66
  slug?: ReactNode;
68
67
  /**
69
- * @deprecated This property is deprecated and will be removed in the next major version. Use DismissibleTag instead.
68
+ * @deprecated The `title` prop has been deprecated and will be removed in the next major version. Use DismissibleTag instead.
70
69
  */
71
70
  title?: string;
72
71
  /**
@@ -75,61 +74,6 @@ export interface TagBaseProps {
75
74
  type?: keyof typeof TYPES;
76
75
  }
77
76
  export type TagProps<T extends React.ElementType> = PolymorphicProps<T, TagBaseProps>;
78
- declare const Tag: {
79
- <T extends React.ElementType<any>>({ children, className, id, type, filter, renderIcon: CustomIconElement, title, disabled, onClose, size, as: BaseComponent, slug, ...other }: TagProps<T>): import("react/jsx-runtime").JSX.Element;
80
- propTypes: {
81
- /**
82
- * Provide an alternative tag or component to use instead of the default
83
- * wrapping element
84
- */
85
- as: PropTypes.Requireable<PropTypes.ReactComponentLike>;
86
- /**
87
- * Provide content to be rendered inside of a `Tag`
88
- */
89
- children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
90
- /**
91
- * Provide a custom className that is applied to the containing <span>
92
- */
93
- className: PropTypes.Requireable<string>;
94
- /**
95
- * Specify if the `Tag` is disabled
96
- */
97
- disabled: PropTypes.Requireable<boolean>;
98
- /**
99
- * Determine if `Tag` is a filter/chip
100
- */
101
- filter: (props: any, propName: any, componentName: any, ...rest: any[]) => any;
102
- /**
103
- * Specify the id for the tag.
104
- */
105
- id: PropTypes.Requireable<string>;
106
- /**
107
- * Click handler for filter tag close button.
108
- */
109
- onClose: (props: any, propName: any, componentName: any, ...rest: any[]) => any;
110
- /**
111
- * Optional prop to render a custom icon.
112
- * Can be a React component class
113
- */
114
- renderIcon: PropTypes.Requireable<object>;
115
- /**
116
- * Specify the size of the Tag. Currently supports either `sm`,
117
- * `md` (default) or `lg` sizes.
118
- */
119
- size: PropTypes.Requireable<string>;
120
- /**
121
- * **Experimental:** Provide a `Slug` component to be rendered inside the `Tag` component
122
- */
123
- slug: PropTypes.Requireable<PropTypes.ReactNodeLike>;
124
- /**
125
- * Text to show on clear filters
126
- */
127
- title: (props: any, propName: any, componentName: any, ...rest: any[]) => any;
128
- /**
129
- * Specify the type of the `Tag`
130
- */
131
- type: PropTypes.Requireable<string>;
132
- };
133
- };
77
+ declare const Tag: React.ForwardRefExoticComponent<Omit<TagProps<React.ElementType<any>>, "ref"> & React.RefAttributes<HTMLElement | undefined>>;
134
78
  export declare const types: string[];
135
79
  export default Tag;