react-tooltip 5.27.0 → 5.28.0-beta.1224.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.
@@ -49,11 +49,7 @@
49
49
  }
50
50
  const { insertAt } = ref;
51
51
  if (document.getElementById(id)) {
52
- // this should never happen because of `injected[type]`
53
- {
54
- // eslint-disable-next-line no-console
55
- console.warn(`[react-tooltip] Element with id '${id}' already exists. Call \`removeStyle()\` first`);
56
- }
52
+ // this could happen in cases the tooltip is imported by multiple js modules
57
53
  return;
58
54
  }
59
55
  const head = document.head || document.getElementsByTagName('head')[0];
@@ -289,6 +285,14 @@
289
285
 
290
286
  const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
291
287
 
288
+ const clearTimeoutRef = (ref) => {
289
+ if (ref.current) {
290
+ clearTimeout(ref.current);
291
+ // eslint-disable-next-line no-param-reassign
292
+ ref.current = null;
293
+ }
294
+ };
295
+
292
296
  const DEFAULT_TOOLTIP_ID = 'DEFAULT_TOOLTIP_ID';
293
297
  const DEFAULT_CONTEXT_DATA = {
294
298
  anchorRefs: new Set(),
@@ -393,7 +397,7 @@
393
397
 
394
398
  const Tooltip = ({
395
399
  // props
396
- forwardRef, 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, openEvents, closeEvents, globalCloseEvents, imperativeModeOnly, style: externalStyles, position, afterShow, afterHide,
400
+ forwardRef, 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, openEvents, closeEvents, globalCloseEvents, imperativeModeOnly, style: externalStyles, position, afterShow, afterHide, disableTooltip,
397
401
  // props handled by controller
398
402
  content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnchor, setActiveAnchor, border, opacity, arrowColor, role = 'tooltip', }) => {
399
403
  var _a;
@@ -543,9 +547,7 @@
543
547
  if (show === wasShowing.current) {
544
548
  return;
545
549
  }
546
- if (missedTransitionTimerRef.current) {
547
- clearTimeout(missedTransitionTimerRef.current);
548
- }
550
+ clearTimeoutRef(missedTransitionTimerRef);
549
551
  wasShowing.current = show;
550
552
  if (show) {
551
553
  afterShow === null || afterShow === void 0 ? void 0 : afterShow();
@@ -574,9 +576,7 @@
574
576
  : newComputedPosition);
575
577
  };
576
578
  const handleShowTooltipDelayed = (delay = delayShow) => {
577
- if (tooltipShowDelayTimerRef.current) {
578
- clearTimeout(tooltipShowDelayTimerRef.current);
579
- }
579
+ clearTimeoutRef(tooltipShowDelayTimerRef);
580
580
  if (rendered) {
581
581
  // if the tooltip is already rendered, ignore delay
582
582
  handleShow(true);
@@ -587,9 +587,7 @@
587
587
  }, delay);
588
588
  };
589
589
  const handleHideTooltipDelayed = (delay = delayHide) => {
590
- if (tooltipHideDelayTimerRef.current) {
591
- clearTimeout(tooltipHideDelayTimerRef.current);
592
- }
590
+ clearTimeoutRef(tooltipHideDelayTimerRef);
593
591
  tooltipHideDelayTimerRef.current = setTimeout(() => {
594
592
  if (hoveringTooltip.current) {
595
593
  return;
@@ -620,9 +618,7 @@
620
618
  }
621
619
  setActiveAnchor(target);
622
620
  setProviderActiveAnchor({ current: target });
623
- if (tooltipHideDelayTimerRef.current) {
624
- clearTimeout(tooltipHideDelayTimerRef.current);
625
- }
621
+ clearTimeoutRef(tooltipHideDelayTimerRef);
626
622
  };
627
623
  const handleHideTooltip = () => {
628
624
  if (clickable) {
@@ -635,9 +631,7 @@
635
631
  else {
636
632
  handleShow(false);
637
633
  }
638
- if (tooltipShowDelayTimerRef.current) {
639
- clearTimeout(tooltipShowDelayTimerRef.current);
640
- }
634
+ clearTimeoutRef(tooltipShowDelayTimerRef);
641
635
  };
642
636
  const handleTooltipPosition = ({ x, y }) => {
643
637
  var _a;
@@ -698,9 +692,7 @@
698
692
  return;
699
693
  }
700
694
  handleShow(false);
701
- if (tooltipShowDelayTimerRef.current) {
702
- clearTimeout(tooltipShowDelayTimerRef.current);
703
- }
695
+ clearTimeoutRef(tooltipShowDelayTimerRef);
704
696
  };
705
697
  // debounce handler to prevent call twice when
706
698
  // mouse enter and focus events being triggered toggether
@@ -777,10 +769,13 @@
777
769
  var _a, _b;
778
770
  const elementRefs = new Set(anchorRefs);
779
771
  anchorsBySelect.forEach((anchor) => {
772
+ if (disableTooltip === null || disableTooltip === void 0 ? void 0 : disableTooltip(anchor)) {
773
+ return;
774
+ }
780
775
  elementRefs.add({ current: anchor });
781
776
  });
782
777
  const anchorById = document.querySelector(`[id='${anchorId}']`);
783
- if (anchorById) {
778
+ if (anchorById && !(disableTooltip === null || disableTooltip === void 0 ? void 0 : disableTooltip(anchorById))) {
784
779
  elementRefs.add({ current: anchorById });
785
780
  }
786
781
  const handleScrollResize = () => {
@@ -818,7 +813,8 @@
818
813
  }
819
814
  const enabledEvents = [];
820
815
  const handleClickOpenTooltipAnchor = (event) => {
821
- if (show && (event === null || event === void 0 ? void 0 : event.target) === activeAnchor) {
816
+ var _a;
817
+ if (show && ((_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.contains(activeAnchor))) {
822
818
  /**
823
819
  * ignore clicking the anchor that was used to open the tooltip.
824
820
  * this avoids conflict with the click close event.
@@ -828,7 +824,8 @@
828
824
  handleShowTooltip(event);
829
825
  };
830
826
  const handleClickCloseTooltipAnchor = (event) => {
831
- if (!show || (event === null || event === void 0 ? void 0 : event.target) !== activeAnchor) {
827
+ var _a;
828
+ if (!show || !((_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.contains(activeAnchor))) {
832
829
  /**
833
830
  * ignore clicking the anchor that was NOT used to open the tooltip.
834
831
  * this avoids closing the tooltip when clicking on a
@@ -984,12 +981,8 @@
984
981
  setRendered(false);
985
982
  handleShow(false);
986
983
  setActiveAnchor(null);
987
- if (tooltipShowDelayTimerRef.current) {
988
- clearTimeout(tooltipShowDelayTimerRef.current);
989
- }
990
- if (tooltipHideDelayTimerRef.current) {
991
- clearTimeout(tooltipHideDelayTimerRef.current);
992
- }
984
+ clearTimeoutRef(tooltipShowDelayTimerRef);
985
+ clearTimeoutRef(tooltipHideDelayTimerRef);
993
986
  return true;
994
987
  }
995
988
  return false;
@@ -1068,12 +1061,8 @@
1068
1061
  handleShow(true);
1069
1062
  }
1070
1063
  return () => {
1071
- if (tooltipShowDelayTimerRef.current) {
1072
- clearTimeout(tooltipShowDelayTimerRef.current);
1073
- }
1074
- if (tooltipHideDelayTimerRef.current) {
1075
- clearTimeout(tooltipHideDelayTimerRef.current);
1076
- }
1064
+ clearTimeoutRef(tooltipShowDelayTimerRef);
1065
+ clearTimeoutRef(tooltipHideDelayTimerRef);
1077
1066
  };
1078
1067
  }, []);
1079
1068
  React.useEffect(() => {
@@ -1096,7 +1085,11 @@
1096
1085
  }, [id, anchorSelect, imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.anchorSelect]);
1097
1086
  React.useEffect(() => {
1098
1087
  if (tooltipShowDelayTimerRef.current) {
1099
- clearTimeout(tooltipShowDelayTimerRef.current);
1088
+ /**
1089
+ * if the delay changes while the tooltip is waiting to show,
1090
+ * reset the timer with the new delay
1091
+ */
1092
+ clearTimeoutRef(tooltipShowDelayTimerRef);
1100
1093
  handleShowTooltipDelayed(delayShow);
1101
1094
  }
1102
1095
  }, [delayShow]);
@@ -1137,9 +1130,7 @@
1137
1130
  isOpen: Boolean(rendered && !hidden && actualContent && canShow),
1138
1131
  }));
1139
1132
  return rendered && !hidden && actualContent ? (React__default["default"].createElement(WrapperElement, { id: id, role: role, className: classNames__default["default"]('react-tooltip', coreStyles['tooltip'], styles['tooltip'], styles[variant], className, `react-tooltip__place-${computedPosition.place}`, coreStyles[canShow ? 'show' : 'closing'], canShow ? 'react-tooltip__show' : 'react-tooltip__closing', positionStrategy === 'fixed' && coreStyles['fixed'], clickable && coreStyles['clickable']), onTransitionEnd: (event) => {
1140
- if (missedTransitionTimerRef.current) {
1141
- clearTimeout(missedTransitionTimerRef.current);
1142
- }
1133
+ clearTimeoutRef(missedTransitionTimerRef);
1143
1134
  if (show || event.propertyName !== 'opacity') {
1144
1135
  return;
1145
1136
  }
@@ -1165,7 +1156,7 @@
1165
1156
  return React__default["default"].createElement("span", { dangerouslySetInnerHTML: { __html: content } });
1166
1157
  };
1167
1158
 
1168
- const TooltipController = React__default["default"].forwardRef(({ 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, openEvents, closeEvents, globalCloseEvents, imperativeModeOnly = false, style, position, isOpen, defaultIsOpen = false, disableStyleInjection = false, border, opacity, arrowColor, setIsOpen, afterShow, afterHide, role = 'tooltip', }, ref) => {
1159
+ const TooltipController = React__default["default"].forwardRef(({ 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, openEvents, closeEvents, globalCloseEvents, imperativeModeOnly = false, style, position, isOpen, defaultIsOpen = false, disableStyleInjection = false, border, opacity, arrowColor, setIsOpen, afterShow, afterHide, disableTooltip, role = 'tooltip', }, ref) => {
1169
1160
  const [tooltipContent, setTooltipContent] = React.useState(content);
1170
1161
  const [tooltipHtml, setTooltipHtml] = React.useState(html);
1171
1162
  const [tooltipPlace, setTooltipPlace] = React.useState(place);
@@ -1438,6 +1429,7 @@
1438
1429
  setIsOpen,
1439
1430
  afterShow,
1440
1431
  afterHide,
1432
+ disableTooltip,
1441
1433
  activeAnchor,
1442
1434
  setActiveAnchor: (anchor) => setActiveAnchor(anchor),
1443
1435
  role,