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.
@@ -42,11 +42,7 @@ function injectStyle({ css, id = REACT_TOOLTIP_BASE_STYLES_ID, type = 'base', re
42
42
  }
43
43
  const { insertAt } = ref;
44
44
  if (document.getElementById(id)) {
45
- // this should never happen because of `injected[type]`
46
- {
47
- // eslint-disable-next-line no-console
48
- console.warn(`[react-tooltip] Element with id '${id}' already exists. Call \`removeStyle()\` first`);
49
- }
45
+ // this could happen in cases the tooltip is imported by multiple js modules
50
46
  return;
51
47
  }
52
48
  const head = document.head || document.getElementsByTagName('head')[0];
@@ -282,6 +278,14 @@ const getScrollParent = (node) => {
282
278
 
283
279
  const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
284
280
 
281
+ const clearTimeoutRef = (ref) => {
282
+ if (ref.current) {
283
+ clearTimeout(ref.current);
284
+ // eslint-disable-next-line no-param-reassign
285
+ ref.current = null;
286
+ }
287
+ };
288
+
285
289
  const DEFAULT_TOOLTIP_ID = 'DEFAULT_TOOLTIP_ID';
286
290
  const DEFAULT_CONTEXT_DATA = {
287
291
  anchorRefs: new Set(),
@@ -386,7 +390,7 @@ var styles = {"tooltip":"styles-module_tooltip__mnnfp","arrow":"styles-module_ar
386
390
 
387
391
  const Tooltip = ({
388
392
  // props
389
- 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,
393
+ 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,
390
394
  // props handled by controller
391
395
  content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnchor, setActiveAnchor, border, opacity, arrowColor, role = 'tooltip', }) => {
392
396
  var _a;
@@ -536,9 +540,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
536
540
  if (show === wasShowing.current) {
537
541
  return;
538
542
  }
539
- if (missedTransitionTimerRef.current) {
540
- clearTimeout(missedTransitionTimerRef.current);
541
- }
543
+ clearTimeoutRef(missedTransitionTimerRef);
542
544
  wasShowing.current = show;
543
545
  if (show) {
544
546
  afterShow === null || afterShow === void 0 ? void 0 : afterShow();
@@ -567,9 +569,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
567
569
  : newComputedPosition);
568
570
  };
569
571
  const handleShowTooltipDelayed = (delay = delayShow) => {
570
- if (tooltipShowDelayTimerRef.current) {
571
- clearTimeout(tooltipShowDelayTimerRef.current);
572
- }
572
+ clearTimeoutRef(tooltipShowDelayTimerRef);
573
573
  if (rendered) {
574
574
  // if the tooltip is already rendered, ignore delay
575
575
  handleShow(true);
@@ -580,9 +580,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
580
580
  }, delay);
581
581
  };
582
582
  const handleHideTooltipDelayed = (delay = delayHide) => {
583
- if (tooltipHideDelayTimerRef.current) {
584
- clearTimeout(tooltipHideDelayTimerRef.current);
585
- }
583
+ clearTimeoutRef(tooltipHideDelayTimerRef);
586
584
  tooltipHideDelayTimerRef.current = setTimeout(() => {
587
585
  if (hoveringTooltip.current) {
588
586
  return;
@@ -613,9 +611,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
613
611
  }
614
612
  setActiveAnchor(target);
615
613
  setProviderActiveAnchor({ current: target });
616
- if (tooltipHideDelayTimerRef.current) {
617
- clearTimeout(tooltipHideDelayTimerRef.current);
618
- }
614
+ clearTimeoutRef(tooltipHideDelayTimerRef);
619
615
  };
620
616
  const handleHideTooltip = () => {
621
617
  if (clickable) {
@@ -628,9 +624,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
628
624
  else {
629
625
  handleShow(false);
630
626
  }
631
- if (tooltipShowDelayTimerRef.current) {
632
- clearTimeout(tooltipShowDelayTimerRef.current);
633
- }
627
+ clearTimeoutRef(tooltipShowDelayTimerRef);
634
628
  };
635
629
  const handleTooltipPosition = ({ x, y }) => {
636
630
  var _a;
@@ -691,9 +685,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
691
685
  return;
692
686
  }
693
687
  handleShow(false);
694
- if (tooltipShowDelayTimerRef.current) {
695
- clearTimeout(tooltipShowDelayTimerRef.current);
696
- }
688
+ clearTimeoutRef(tooltipShowDelayTimerRef);
697
689
  };
698
690
  // debounce handler to prevent call twice when
699
691
  // mouse enter and focus events being triggered toggether
@@ -770,10 +762,13 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
770
762
  var _a, _b;
771
763
  const elementRefs = new Set(anchorRefs);
772
764
  anchorsBySelect.forEach((anchor) => {
765
+ if (disableTooltip === null || disableTooltip === void 0 ? void 0 : disableTooltip(anchor)) {
766
+ return;
767
+ }
773
768
  elementRefs.add({ current: anchor });
774
769
  });
775
770
  const anchorById = document.querySelector(`[id='${anchorId}']`);
776
- if (anchorById) {
771
+ if (anchorById && !(disableTooltip === null || disableTooltip === void 0 ? void 0 : disableTooltip(anchorById))) {
777
772
  elementRefs.add({ current: anchorById });
778
773
  }
779
774
  const handleScrollResize = () => {
@@ -811,7 +806,8 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
811
806
  }
812
807
  const enabledEvents = [];
813
808
  const handleClickOpenTooltipAnchor = (event) => {
814
- if (show && (event === null || event === void 0 ? void 0 : event.target) === activeAnchor) {
809
+ var _a;
810
+ if (show && ((_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.contains(activeAnchor))) {
815
811
  /**
816
812
  * ignore clicking the anchor that was used to open the tooltip.
817
813
  * this avoids conflict with the click close event.
@@ -821,7 +817,8 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
821
817
  handleShowTooltip(event);
822
818
  };
823
819
  const handleClickCloseTooltipAnchor = (event) => {
824
- if (!show || (event === null || event === void 0 ? void 0 : event.target) !== activeAnchor) {
820
+ var _a;
821
+ if (!show || !((_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.contains(activeAnchor))) {
825
822
  /**
826
823
  * ignore clicking the anchor that was NOT used to open the tooltip.
827
824
  * this avoids closing the tooltip when clicking on a
@@ -977,12 +974,8 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
977
974
  setRendered(false);
978
975
  handleShow(false);
979
976
  setActiveAnchor(null);
980
- if (tooltipShowDelayTimerRef.current) {
981
- clearTimeout(tooltipShowDelayTimerRef.current);
982
- }
983
- if (tooltipHideDelayTimerRef.current) {
984
- clearTimeout(tooltipHideDelayTimerRef.current);
985
- }
977
+ clearTimeoutRef(tooltipShowDelayTimerRef);
978
+ clearTimeoutRef(tooltipHideDelayTimerRef);
986
979
  return true;
987
980
  }
988
981
  return false;
@@ -1061,12 +1054,8 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
1061
1054
  handleShow(true);
1062
1055
  }
1063
1056
  return () => {
1064
- if (tooltipShowDelayTimerRef.current) {
1065
- clearTimeout(tooltipShowDelayTimerRef.current);
1066
- }
1067
- if (tooltipHideDelayTimerRef.current) {
1068
- clearTimeout(tooltipHideDelayTimerRef.current);
1069
- }
1057
+ clearTimeoutRef(tooltipShowDelayTimerRef);
1058
+ clearTimeoutRef(tooltipHideDelayTimerRef);
1070
1059
  };
1071
1060
  }, []);
1072
1061
  useEffect(() => {
@@ -1089,7 +1078,11 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
1089
1078
  }, [id, anchorSelect, imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.anchorSelect]);
1090
1079
  useEffect(() => {
1091
1080
  if (tooltipShowDelayTimerRef.current) {
1092
- clearTimeout(tooltipShowDelayTimerRef.current);
1081
+ /**
1082
+ * if the delay changes while the tooltip is waiting to show,
1083
+ * reset the timer with the new delay
1084
+ */
1085
+ clearTimeoutRef(tooltipShowDelayTimerRef);
1093
1086
  handleShowTooltipDelayed(delayShow);
1094
1087
  }
1095
1088
  }, [delayShow]);
@@ -1130,9 +1123,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
1130
1123
  isOpen: Boolean(rendered && !hidden && actualContent && canShow),
1131
1124
  }));
1132
1125
  return rendered && !hidden && actualContent ? (React.createElement(WrapperElement, { id: id, role: role, className: classNames('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) => {
1133
- if (missedTransitionTimerRef.current) {
1134
- clearTimeout(missedTransitionTimerRef.current);
1135
- }
1126
+ clearTimeoutRef(missedTransitionTimerRef);
1136
1127
  if (show || event.propertyName !== 'opacity') {
1137
1128
  return;
1138
1129
  }
@@ -1158,7 +1149,7 @@ const TooltipContent = ({ content }) => {
1158
1149
  return React.createElement("span", { dangerouslySetInnerHTML: { __html: content } });
1159
1150
  };
1160
1151
 
1161
- const TooltipController = React.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) => {
1152
+ const TooltipController = React.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) => {
1162
1153
  const [tooltipContent, setTooltipContent] = useState(content);
1163
1154
  const [tooltipHtml, setTooltipHtml] = useState(html);
1164
1155
  const [tooltipPlace, setTooltipPlace] = useState(place);
@@ -1431,6 +1422,7 @@ const TooltipController = React.forwardRef(({ id, anchorId, anchorSelect, conten
1431
1422
  setIsOpen,
1432
1423
  afterShow,
1433
1424
  afterHide,
1425
+ disableTooltip,
1434
1426
  activeAnchor,
1435
1427
  setActiveAnchor: (anchor) => setActiveAnchor(anchor),
1436
1428
  role,