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.
@@ -51,11 +51,7 @@ function injectStyle({ css, id = REACT_TOOLTIP_BASE_STYLES_ID, type = 'base', re
51
51
  }
52
52
  const { insertAt } = ref;
53
53
  if (document.getElementById(id)) {
54
- // this should never happen because of `injected[type]`
55
- {
56
- // eslint-disable-next-line no-console
57
- console.warn(`[react-tooltip] Element with id '${id}' already exists. Call \`removeStyle()\` first`);
58
- }
54
+ // this could happen in cases the tooltip is imported by multiple js modules
59
55
  return;
60
56
  }
61
57
  const head = document.head || document.getElementsByTagName('head')[0];
@@ -291,6 +287,14 @@ const getScrollParent = (node) => {
291
287
 
292
288
  const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
293
289
 
290
+ const clearTimeoutRef = (ref) => {
291
+ if (ref.current) {
292
+ clearTimeout(ref.current);
293
+ // eslint-disable-next-line no-param-reassign
294
+ ref.current = null;
295
+ }
296
+ };
297
+
294
298
  const DEFAULT_TOOLTIP_ID = 'DEFAULT_TOOLTIP_ID';
295
299
  const DEFAULT_CONTEXT_DATA = {
296
300
  anchorRefs: new Set(),
@@ -395,7 +399,7 @@ var styles = {"tooltip":"styles-module_tooltip__mnnfp","arrow":"styles-module_ar
395
399
 
396
400
  const Tooltip = ({
397
401
  // props
398
- 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,
402
+ 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,
399
403
  // props handled by controller
400
404
  content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnchor, setActiveAnchor, border, opacity, arrowColor, role = 'tooltip', }) => {
401
405
  var _a;
@@ -545,9 +549,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
545
549
  if (show === wasShowing.current) {
546
550
  return;
547
551
  }
548
- if (missedTransitionTimerRef.current) {
549
- clearTimeout(missedTransitionTimerRef.current);
550
- }
552
+ clearTimeoutRef(missedTransitionTimerRef);
551
553
  wasShowing.current = show;
552
554
  if (show) {
553
555
  afterShow === null || afterShow === void 0 ? void 0 : afterShow();
@@ -576,9 +578,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
576
578
  : newComputedPosition);
577
579
  };
578
580
  const handleShowTooltipDelayed = (delay = delayShow) => {
579
- if (tooltipShowDelayTimerRef.current) {
580
- clearTimeout(tooltipShowDelayTimerRef.current);
581
- }
581
+ clearTimeoutRef(tooltipShowDelayTimerRef);
582
582
  if (rendered) {
583
583
  // if the tooltip is already rendered, ignore delay
584
584
  handleShow(true);
@@ -589,9 +589,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
589
589
  }, delay);
590
590
  };
591
591
  const handleHideTooltipDelayed = (delay = delayHide) => {
592
- if (tooltipHideDelayTimerRef.current) {
593
- clearTimeout(tooltipHideDelayTimerRef.current);
594
- }
592
+ clearTimeoutRef(tooltipHideDelayTimerRef);
595
593
  tooltipHideDelayTimerRef.current = setTimeout(() => {
596
594
  if (hoveringTooltip.current) {
597
595
  return;
@@ -622,9 +620,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
622
620
  }
623
621
  setActiveAnchor(target);
624
622
  setProviderActiveAnchor({ current: target });
625
- if (tooltipHideDelayTimerRef.current) {
626
- clearTimeout(tooltipHideDelayTimerRef.current);
627
- }
623
+ clearTimeoutRef(tooltipHideDelayTimerRef);
628
624
  };
629
625
  const handleHideTooltip = () => {
630
626
  if (clickable) {
@@ -637,9 +633,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
637
633
  else {
638
634
  handleShow(false);
639
635
  }
640
- if (tooltipShowDelayTimerRef.current) {
641
- clearTimeout(tooltipShowDelayTimerRef.current);
642
- }
636
+ clearTimeoutRef(tooltipShowDelayTimerRef);
643
637
  };
644
638
  const handleTooltipPosition = ({ x, y }) => {
645
639
  var _a;
@@ -700,9 +694,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
700
694
  return;
701
695
  }
702
696
  handleShow(false);
703
- if (tooltipShowDelayTimerRef.current) {
704
- clearTimeout(tooltipShowDelayTimerRef.current);
705
- }
697
+ clearTimeoutRef(tooltipShowDelayTimerRef);
706
698
  };
707
699
  // debounce handler to prevent call twice when
708
700
  // mouse enter and focus events being triggered toggether
@@ -779,10 +771,13 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
779
771
  var _a, _b;
780
772
  const elementRefs = new Set(anchorRefs);
781
773
  anchorsBySelect.forEach((anchor) => {
774
+ if (disableTooltip === null || disableTooltip === void 0 ? void 0 : disableTooltip(anchor)) {
775
+ return;
776
+ }
782
777
  elementRefs.add({ current: anchor });
783
778
  });
784
779
  const anchorById = document.querySelector(`[id='${anchorId}']`);
785
- if (anchorById) {
780
+ if (anchorById && !(disableTooltip === null || disableTooltip === void 0 ? void 0 : disableTooltip(anchorById))) {
786
781
  elementRefs.add({ current: anchorById });
787
782
  }
788
783
  const handleScrollResize = () => {
@@ -820,7 +815,8 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
820
815
  }
821
816
  const enabledEvents = [];
822
817
  const handleClickOpenTooltipAnchor = (event) => {
823
- if (show && (event === null || event === void 0 ? void 0 : event.target) === activeAnchor) {
818
+ var _a;
819
+ if (show && ((_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.contains(activeAnchor))) {
824
820
  /**
825
821
  * ignore clicking the anchor that was used to open the tooltip.
826
822
  * this avoids conflict with the click close event.
@@ -830,7 +826,8 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
830
826
  handleShowTooltip(event);
831
827
  };
832
828
  const handleClickCloseTooltipAnchor = (event) => {
833
- if (!show || (event === null || event === void 0 ? void 0 : event.target) !== activeAnchor) {
829
+ var _a;
830
+ if (!show || !((_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.contains(activeAnchor))) {
834
831
  /**
835
832
  * ignore clicking the anchor that was NOT used to open the tooltip.
836
833
  * this avoids closing the tooltip when clicking on a
@@ -986,12 +983,8 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
986
983
  setRendered(false);
987
984
  handleShow(false);
988
985
  setActiveAnchor(null);
989
- if (tooltipShowDelayTimerRef.current) {
990
- clearTimeout(tooltipShowDelayTimerRef.current);
991
- }
992
- if (tooltipHideDelayTimerRef.current) {
993
- clearTimeout(tooltipHideDelayTimerRef.current);
994
- }
986
+ clearTimeoutRef(tooltipShowDelayTimerRef);
987
+ clearTimeoutRef(tooltipHideDelayTimerRef);
995
988
  return true;
996
989
  }
997
990
  return false;
@@ -1070,12 +1063,8 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
1070
1063
  handleShow(true);
1071
1064
  }
1072
1065
  return () => {
1073
- if (tooltipShowDelayTimerRef.current) {
1074
- clearTimeout(tooltipShowDelayTimerRef.current);
1075
- }
1076
- if (tooltipHideDelayTimerRef.current) {
1077
- clearTimeout(tooltipHideDelayTimerRef.current);
1078
- }
1066
+ clearTimeoutRef(tooltipShowDelayTimerRef);
1067
+ clearTimeoutRef(tooltipHideDelayTimerRef);
1079
1068
  };
1080
1069
  }, []);
1081
1070
  React.useEffect(() => {
@@ -1098,7 +1087,11 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
1098
1087
  }, [id, anchorSelect, imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.anchorSelect]);
1099
1088
  React.useEffect(() => {
1100
1089
  if (tooltipShowDelayTimerRef.current) {
1101
- clearTimeout(tooltipShowDelayTimerRef.current);
1090
+ /**
1091
+ * if the delay changes while the tooltip is waiting to show,
1092
+ * reset the timer with the new delay
1093
+ */
1094
+ clearTimeoutRef(tooltipShowDelayTimerRef);
1102
1095
  handleShowTooltipDelayed(delayShow);
1103
1096
  }
1104
1097
  }, [delayShow]);
@@ -1139,9 +1132,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
1139
1132
  isOpen: Boolean(rendered && !hidden && actualContent && canShow),
1140
1133
  }));
1141
1134
  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) => {
1142
- if (missedTransitionTimerRef.current) {
1143
- clearTimeout(missedTransitionTimerRef.current);
1144
- }
1135
+ clearTimeoutRef(missedTransitionTimerRef);
1145
1136
  if (show || event.propertyName !== 'opacity') {
1146
1137
  return;
1147
1138
  }
@@ -1167,7 +1158,7 @@ const TooltipContent = ({ content }) => {
1167
1158
  return React__default["default"].createElement("span", { dangerouslySetInnerHTML: { __html: content } });
1168
1159
  };
1169
1160
 
1170
- 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) => {
1161
+ 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) => {
1171
1162
  const [tooltipContent, setTooltipContent] = React.useState(content);
1172
1163
  const [tooltipHtml, setTooltipHtml] = React.useState(html);
1173
1164
  const [tooltipPlace, setTooltipPlace] = React.useState(place);
@@ -1440,6 +1431,7 @@ const TooltipController = React__default["default"].forwardRef(({ id, anchorId,
1440
1431
  setIsOpen,
1441
1432
  afterShow,
1442
1433
  afterHide,
1434
+ disableTooltip,
1443
1435
  activeAnchor,
1444
1436
  setActiveAnchor: (anchor) => setActiveAnchor(anchor),
1445
1437
  role,