react-tooltip 5.22.0-beta.1091.0 → 5.22.0-beta.1106.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.
package/README.md CHANGED
@@ -58,17 +58,26 @@ yarn add react-tooltip
58
58
 
59
59
  ## Sponsors
60
60
 
61
+ ### Gold Sponsors 🌟
62
+
61
63
  <a href="https://frigade.com/?source=react-tooltip">
62
- <img alt="Frigade" style="height: 250px" src="docs/static/img/sponsors/frigade.png" />
64
+ <img alt="Frigade" style="height: 250px;" src="docs/static/img/sponsors/frigade.png" />
63
65
  </a>
64
66
 
65
67
  React Tooltip is proud to be sponsored by [Frigade](https://frigade.com/?source=react-tooltip), a developer tool for building better product onboarding: guided tours, getting started checklists, announcements, etc.
66
68
 
69
+ #### Silver Sponsors ✪
70
+
71
+ <a href="https://dopt.com/?source=react-tooltip">
72
+ <img alt="Dopt" style="height: 200px; width: 200px;" src="docs/static/img/sponsors/dopt.png" />
73
+ </a>
74
+
67
75
  ## Usage
68
76
 
69
77
  1 . Import the CSS file to set default styling.
70
78
 
71
- > :warning: If you are using a version before than `v5.13.0`, you must import the CSS file or the tooltip won't show!
79
+ > [!WARNING]\
80
+ > If you are using a version before than `v5.13.0`, you must import the CSS file or the tooltip won't show!
72
81
 
73
82
  ```js
74
83
  import 'react-tooltip/dist/react-tooltip.css'
@@ -100,6 +109,7 @@ import { Tooltip as ReactTooltip } from 'react-tooltip'
100
109
 
101
110
  4 . Include the `<Tooltip />` element.
102
111
 
112
+ > [!NOTE]\
103
113
  > Don't forget to set the id, it won't work without it!
104
114
 
105
115
  ```jsx
@@ -6,4 +6,6 @@
6
6
  --rt-color-warning: #f0ad4e;
7
7
  --rt-color-info: #337ab7;
8
8
  --rt-opacity: 0.9;
9
+ --rt-transition-show-delay: 0.15s;
10
+ --rt-transition-closing-delay: 0.15s;
9
11
  }
@@ -327,7 +327,7 @@ const computeTooltipPosition = async ({ elementReference = null, tooltipReferenc
327
327
  });
328
328
  };
329
329
 
330
- var coreStyles = {"tooltip":"core-styles-module_tooltip__3vRRp","fixed":"core-styles-module_fixed__pcSol","arrow":"core-styles-module_arrow__cvMwQ","noArrow":"core-styles-module_noArrow__xock6","clickable":"core-styles-module_clickable__ZuTTB","show":"core-styles-module_show__Nt9eE"};
330
+ var coreStyles = {"tooltip":"core-styles-module_tooltip__3vRRp","fixed":"core-styles-module_fixed__pcSol","arrow":"core-styles-module_arrow__cvMwQ","noArrow":"core-styles-module_noArrow__xock6","clickable":"core-styles-module_clickable__ZuTTB","show":"core-styles-module_show__Nt9eE","closing":"core-styles-module_closing__sGnxF"};
331
331
 
332
332
  var styles = {"tooltip":"styles-module_tooltip__mnnfp","arrow":"styles-module_arrow__K0L3T","dark":"styles-module_dark__xNqje","light":"styles-module_light__Z6W-X","success":"styles-module_success__A2AKt","warning":"styles-module_warning__SCK0X","error":"styles-module_error__JvumD","info":"styles-module_info__BWdHW"};
333
333
 
@@ -335,7 +335,7 @@ const Tooltip = ({
335
335
  // props
336
336
  id, className, classNameArrow, variant = 'dark', anchorId, anchorSelect, place = 'top', offset = 10, events = ['hover'], openOnClick = false, positionStrategy = 'absolute', middlewares, wrapper: WrapperElement, delayShow = 0, delayHide = 0, float = false, hidden = false, noArrow = false, clickable = false, closeOnEsc = false, closeOnScroll = false, closeOnResize = false, style: externalStyles, position, afterShow, afterHide,
337
337
  // props handled by controller
338
- content, contentWrapperRef, isOpen, holdPositionOnRender, setIsOpen, activeAnchor, setActiveAnchor, border, opacity, arrowColor, }) => {
338
+ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, border, opacity, arrowColor, }) => {
339
339
  const tooltipRef = React.useRef(null);
340
340
  const tooltipArrowRef = React.useRef(null);
341
341
  const tooltipShowDelayTimerRef = React.useRef(null);
@@ -366,23 +366,6 @@ content, contentWrapperRef, isOpen, holdPositionOnRender, setIsOpen, activeAncho
366
366
  mounted.current = false;
367
367
  };
368
368
  }, []);
369
- React.useEffect(() => {
370
- if (!show) {
371
- /**
372
- * this fixes weird behavior when switching between two anchor elements very quickly
373
- * remove the timeout and switch quickly between two adjancent anchor elements to see it
374
- *
375
- * in practice, this means the tooltip is not immediately removed from the DOM on hide
376
- */
377
- const timeout = setTimeout(() => {
378
- setRendered(false);
379
- }, 150);
380
- return () => {
381
- clearTimeout(timeout);
382
- };
383
- }
384
- return () => null;
385
- }, [show]);
386
369
  const handleShow = (value) => {
387
370
  if (!mounted.current) {
388
371
  return;
@@ -646,7 +629,7 @@ content, contentWrapperRef, isOpen, holdPositionOnRender, setIsOpen, activeAncho
646
629
  if (closeOnResize) {
647
630
  window.addEventListener('resize', handleScrollResize);
648
631
  }
649
- else if (activeAnchor && tooltipRef.current && !holdPositionOnRender) {
632
+ else if (activeAnchor && tooltipRef.current) {
650
633
  updateTooltipCleanup = dom.autoUpdate(activeAnchor, tooltipRef.current, updateTooltipPosition, {
651
634
  ancestorResize: true,
652
635
  elementResize: true,
@@ -757,12 +740,20 @@ content, contentWrapperRef, isOpen, holdPositionOnRender, setIsOpen, activeAncho
757
740
  if (activeAnchor) {
758
741
  const elements = [...mutation.removedNodes].filter((node) => node.nodeType === 1);
759
742
  if (selector) {
760
- removedAnchors.push(
761
- // the element itself is an anchor
762
- ...elements.filter((element) => element.matches(selector)));
763
- removedAnchors.push(
764
- // the element has children which are anchors
765
- ...elements.flatMap((element) => [...element.querySelectorAll(selector)]));
743
+ try {
744
+ removedAnchors.push(
745
+ // the element itself is an anchor
746
+ ...elements.filter((element) => element.matches(selector)));
747
+ removedAnchors.push(
748
+ // the element has children which are anchors
749
+ ...elements.flatMap((element) => [...element.querySelectorAll(selector)]));
750
+ }
751
+ catch (_a) {
752
+ /**
753
+ * invalid CSS selector.
754
+ * already warned on tooltip controller
755
+ */
756
+ }
766
757
  }
767
758
  elements.some((node) => {
768
759
  var _a;
@@ -793,14 +784,14 @@ content, contentWrapperRef, isOpen, holdPositionOnRender, setIsOpen, activeAncho
793
784
  // the element has children which are anchors
794
785
  ...elements.flatMap((element) => [...element.querySelectorAll(selector)]));
795
786
  }
796
- catch (_a) {
787
+ catch (_b) {
797
788
  /**
798
789
  * invalid CSS selector.
799
790
  * already warned on tooltip controller
800
791
  */
801
792
  }
802
793
  });
803
- if (newAnchors.length) {
794
+ if (newAnchors.length || removedAnchors.length) {
804
795
  setAnchorsBySelect((anchors) => [
805
796
  ...anchors.filter((anchor) => removedAnchors.includes(anchor)),
806
797
  ...newAnchors,
@@ -875,24 +866,22 @@ content, contentWrapperRef, isOpen, holdPositionOnRender, setIsOpen, activeAncho
875
866
  }
876
867
  }, [id, anchorSelect]);
877
868
  const canShow = !hidden && content && show && Object.keys(inlineStyles).length > 0;
878
- return rendered || (wasShowing.current && holdPositionOnRender) ? (React__default["default"].createElement(WrapperElement, { id: id, role: "tooltip", className: classNames__default["default"]('react-tooltip', coreStyles['tooltip'], styles['tooltip'], styles[variant], className, `react-tooltip__place-${actualPlacement}`, {
879
- 'react-tooltip__show': canShow,
880
- [coreStyles['show']]: canShow,
881
- [coreStyles['fixed']]: positionStrategy === 'fixed',
882
- [coreStyles['clickable']]: clickable,
883
- }), style: {
869
+ return rendered ? (React__default["default"].createElement(WrapperElement, { id: id, role: "tooltip", className: classNames__default["default"]('react-tooltip', coreStyles['tooltip'], styles['tooltip'], styles[variant], className, `react-tooltip__place-${actualPlacement}`, coreStyles[canShow ? 'show' : 'closing'], canShow ? 'react-tooltip__show' : 'react-tooltip__closing', positionStrategy === 'fixed' && coreStyles['fixed'], clickable && coreStyles['clickable']), onTransitionEnd: (event) => {
870
+ /**
871
+ * @warning if `--rt-transition-closing-delay` is set to 0,
872
+ * the tooltip will be stuck (but not visible) on the DOM
873
+ */
874
+ if (show || event.propertyName !== 'opacity') {
875
+ return;
876
+ }
877
+ setRendered(false);
878
+ }, style: {
884
879
  ...externalStyles,
885
880
  ...inlineStyles,
886
881
  opacity: opacity !== undefined && canShow ? opacity : undefined,
887
882
  }, ref: tooltipRef },
888
883
  content,
889
- React__default["default"].createElement(WrapperElement, { className: classNames__default["default"]('react-tooltip-arrow', coreStyles['arrow'], styles['arrow'], classNameArrow, {
890
- /**
891
- * changed from dash `no-arrow` to camelcase because of:
892
- * https://github.com/indooorsman/esbuild-css-modules-plugin/issues/42
893
- */
894
- [coreStyles['noArrow']]: noArrow,
895
- }), style: {
884
+ React__default["default"].createElement(WrapperElement, { className: classNames__default["default"]('react-tooltip-arrow', coreStyles['arrow'], styles['arrow'], classNameArrow, noArrow && coreStyles['noArrow']), style: {
896
885
  ...inlineArrowStyles,
897
886
  background: arrowColor
898
887
  ? `linear-gradient(to right bottom, transparent 50%, ${arrowColor} 50%)`
@@ -905,7 +894,7 @@ const TooltipContent = ({ content }) => {
905
894
  return React__default["default"].createElement("span", { dangerouslySetInnerHTML: { __html: content } });
906
895
  };
907
896
 
908
- const TooltipController = ({ id, anchorId, anchorSelect, content, html, render, className, classNameArrow, variant = 'dark', place = 'top', offset = 10, wrapper = 'div', children = null, events = ['hover'], openOnClick = false, positionStrategy = 'absolute', middlewares, delayShow = 0, delayHide = 0, float = false, hidden = false, noArrow = false, clickable = false, closeOnEsc = false, closeOnScroll = false, closeOnResize = false, style, position, isOpen, disableStyleInjection = false, holdPositionOnRender, border, opacity, arrowColor, setIsOpen, afterShow, afterHide, }) => {
897
+ const TooltipController = ({ id, anchorId, anchorSelect, content, html, render, className, classNameArrow, variant = 'dark', place = 'top', offset = 10, wrapper = 'div', children = null, events = ['hover'], openOnClick = false, positionStrategy = 'absolute', middlewares, delayShow = 0, delayHide = 0, float = false, hidden = false, noArrow = false, clickable = false, closeOnEsc = false, closeOnScroll = false, closeOnResize = false, style, position, isOpen, disableStyleInjection = false, border, opacity, arrowColor, setIsOpen, afterShow, afterHide, }) => {
909
898
  const [tooltipContent, setTooltipContent] = React.useState(content);
910
899
  const [tooltipHtml, setTooltipHtml] = React.useState(html);
911
900
  const [tooltipPlace, setTooltipPlace] = React.useState(place);
@@ -1156,7 +1145,6 @@ const TooltipController = ({ id, anchorId, anchorSelect, content, html, render,
1156
1145
  style,
1157
1146
  position,
1158
1147
  isOpen,
1159
- holdPositionOnRender,
1160
1148
  border,
1161
1149
  opacity,
1162
1150
  arrowColor,
@@ -1178,17 +1166,17 @@ const TooltipCoreStyles = `:root {
1178
1166
  --rt-color-warning: #f0ad4e;
1179
1167
  --rt-color-info: #337ab7;
1180
1168
  --rt-opacity: 0.9;
1169
+ --rt-transition-show-delay: 0.15s;
1170
+ --rt-transition-closing-delay: 0.15s;
1181
1171
  }
1182
1172
 
1183
1173
  .core-styles-module_tooltip__3vRRp {
1184
- visibility: hidden;
1185
1174
  position: absolute;
1186
1175
  top: 0;
1187
1176
  left: 0;
1188
1177
  pointer-events: none;
1189
1178
  opacity: 0;
1190
- transition: opacity 0.3s ease-out;
1191
- will-change: opacity, visibility;
1179
+ will-change: opacity;
1192
1180
  }
1193
1181
 
1194
1182
  .core-styles-module_fixed__pcSol {
@@ -1209,8 +1197,13 @@ const TooltipCoreStyles = `:root {
1209
1197
  }
1210
1198
 
1211
1199
  .core-styles-module_show__Nt9eE {
1212
- visibility: visible;
1213
1200
  opacity: var(--rt-opacity);
1201
+ transition: opacity var(--rt-transition-show-delay) ease-out;
1202
+ }
1203
+
1204
+ .core-styles-module_closing__sGnxF {
1205
+ opacity: 0;
1206
+ transition: opacity var(--rt-transition-closing-delay) ease-in;
1214
1207
  }
1215
1208
 
1216
1209
  `;