react-tooltip 5.28.0 → 5.29.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.
@@ -8,4 +8,5 @@
8
8
  --rt-opacity: 0.9;
9
9
  --rt-transition-show-delay: 0.15s;
10
10
  --rt-transition-closing-delay: 0.15s;
11
+ --rt-arrow-size: 8px;
11
12
  }
@@ -107,7 +107,7 @@ const computeTooltipPosition = async ({ elementReference = null, tooltipReferenc
107
107
  fallbackAxisSideDirection: 'start',
108
108
  }),
109
109
  dom.shift({ padding: 5 }),
110
- ], border, }) => {
110
+ ], border, arrowSize = 8, }) => {
111
111
  if (!elementReference) {
112
112
  // elementReference can be null or undefined and we will not compute the position
113
113
  // eslint-disable-next-line no-console
@@ -161,7 +161,7 @@ const computeTooltipPosition = async ({ elementReference = null, tooltipReferenc
161
161
  right: '',
162
162
  bottom: '',
163
163
  ...borderSide,
164
- [staticSide]: `-${4 + borderWidth}px`,
164
+ [staticSide]: `-${arrowSize / 2 + borderWidth}px`,
165
165
  };
166
166
  /* c8 ignore end */
167
167
  return { tooltipStyles: styles, tooltipArrowStyles: arrowStyle, place: placement };
@@ -401,7 +401,7 @@ const Tooltip = ({
401
401
  // props
402
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,
403
403
  // props handled by controller
404
- content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnchor, setActiveAnchor, border, opacity, arrowColor, role = 'tooltip', }) => {
404
+ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnchor, setActiveAnchor, border, opacity, arrowColor, arrowSize = 8, role = 'tooltip', }) => {
405
405
  var _a;
406
406
  const tooltipRef = React.useRef(null);
407
407
  const tooltipArrowRef = React.useRef(null);
@@ -475,15 +475,17 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
475
475
  };
476
476
  if (imperativeModeOnly) {
477
477
  Object.assign(actualOpenEvents, {
478
- mouseenter: false,
478
+ mouseover: false,
479
479
  focus: false,
480
+ mouseenter: false,
480
481
  click: false,
481
482
  dblclick: false,
482
483
  mousedown: false,
483
484
  });
484
485
  Object.assign(actualCloseEvents, {
485
- mouseleave: false,
486
+ mouseout: false,
486
487
  blur: false,
488
+ mouseleave: false,
487
489
  click: false,
488
490
  dblclick: false,
489
491
  mouseup: false,
@@ -660,6 +662,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
660
662
  strategy: positionStrategy,
661
663
  middlewares,
662
664
  border,
665
+ arrowSize,
663
666
  }).then((computedStylesData) => {
664
667
  handleComputedPosition(computedStylesData);
665
668
  });
@@ -747,6 +750,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
747
750
  strategy: positionStrategy,
748
751
  middlewares,
749
752
  border,
753
+ arrowSize,
750
754
  }).then((computedStylesData) => {
751
755
  if (!mounted.current) {
752
756
  // invalidate computed positions after remount
@@ -766,6 +770,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
766
770
  position,
767
771
  imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.position,
768
772
  float,
773
+ arrowSize,
769
774
  ]);
770
775
  React.useEffect(() => {
771
776
  var _a, _b;
@@ -814,8 +819,9 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
814
819
  window.addEventListener('click', handleClickOutsideAnchors);
815
820
  }
816
821
  const enabledEvents = [];
822
+ const activeAnchorContainsTarget = (event) => Boolean((event === null || event === void 0 ? void 0 : event.target) && (activeAnchor === null || activeAnchor === void 0 ? void 0 : activeAnchor.contains(event.target)));
817
823
  const handleClickOpenTooltipAnchor = (event) => {
818
- if (show && (event === null || event === void 0 ? void 0 : event.target) === activeAnchor) {
824
+ if (show && activeAnchorContainsTarget(event)) {
819
825
  /**
820
826
  * ignore clicking the anchor that was used to open the tooltip.
821
827
  * this avoids conflict with the click close event.
@@ -825,7 +831,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
825
831
  handleShowTooltip(event);
826
832
  };
827
833
  const handleClickCloseTooltipAnchor = (event) => {
828
- if (!show || (event === null || event === void 0 ? void 0 : event.target) !== activeAnchor) {
834
+ if (!show || !activeAnchorContainsTarget(event)) {
829
835
  /**
830
836
  * ignore clicking the anchor that was NOT used to open the tooltip.
831
837
  * this avoids closing the tooltip when clicking on a
@@ -867,18 +873,19 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
867
873
  listener: handlePointerMove,
868
874
  });
869
875
  }
870
- const handleMouseEnterTooltip = () => {
876
+ const handleMouseOverTooltip = () => {
871
877
  hoveringTooltip.current = true;
872
878
  };
873
- const handleMouseLeaveTooltip = () => {
879
+ const handleMouseOutTooltip = () => {
874
880
  hoveringTooltip.current = false;
875
881
  handleHideTooltip();
876
882
  };
877
- if (clickable && !hasClickEvent) {
878
- // used to keep the tooltip open when hovering content.
879
- // not needed if using click events.
880
- (_a = tooltipRef.current) === null || _a === void 0 ? void 0 : _a.addEventListener('mouseenter', handleMouseEnterTooltip);
881
- (_b = tooltipRef.current) === null || _b === void 0 ? void 0 : _b.addEventListener('mouseleave', handleMouseLeaveTooltip);
883
+ const addHoveringTooltipListeners = clickable && (actualCloseEvents.mouseout || actualCloseEvents.mouseleave);
884
+ if (addHoveringTooltipListeners) {
885
+ // used to keep the tooltip open when hovering from anchor to tooltip.
886
+ // only relevant if either `mouseout`/`mouseleave` is in use
887
+ (_a = tooltipRef.current) === null || _a === void 0 ? void 0 : _a.addEventListener('mouseover', handleMouseOverTooltip);
888
+ (_b = tooltipRef.current) === null || _b === void 0 ? void 0 : _b.addEventListener('mouseout', handleMouseOutTooltip);
882
889
  }
883
890
  enabledEvents.forEach(({ event, listener }) => {
884
891
  elementRefs.forEach((ref) => {
@@ -905,9 +912,9 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
905
912
  if (actualGlobalCloseEvents.escape) {
906
913
  window.removeEventListener('keydown', handleEsc);
907
914
  }
908
- if (clickable && !hasClickEvent) {
909
- (_a = tooltipRef.current) === null || _a === void 0 ? void 0 : _a.removeEventListener('mouseenter', handleMouseEnterTooltip);
910
- (_b = tooltipRef.current) === null || _b === void 0 ? void 0 : _b.removeEventListener('mouseleave', handleMouseLeaveTooltip);
915
+ if (addHoveringTooltipListeners) {
916
+ (_a = tooltipRef.current) === null || _a === void 0 ? void 0 : _a.removeEventListener('mouseover', handleMouseOverTooltip);
917
+ (_b = tooltipRef.current) === null || _b === void 0 ? void 0 : _b.removeEventListener('mouseout', handleMouseOutTooltip);
911
918
  }
912
919
  enabledEvents.forEach(({ event, listener }) => {
913
920
  elementRefs.forEach((ref) => {
@@ -1148,6 +1155,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
1148
1155
  background: arrowColor
1149
1156
  ? `linear-gradient(to right bottom, transparent 50%, ${arrowColor} 50%)`
1150
1157
  : undefined,
1158
+ '--rt-arrow-size': `${arrowSize}px`,
1151
1159
  }, ref: tooltipArrowRef }))) : null;
1152
1160
  };
1153
1161
 
@@ -1156,7 +1164,7 @@ const TooltipContent = ({ content }) => {
1156
1164
  return React__default["default"].createElement("span", { dangerouslySetInnerHTML: { __html: content } });
1157
1165
  };
1158
1166
 
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) => {
1167
+ 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, arrowSize, setIsOpen, afterShow, afterHide, disableTooltip, role = 'tooltip', }, ref) => {
1160
1168
  const [tooltipContent, setTooltipContent] = React.useState(content);
1161
1169
  const [tooltipHtml, setTooltipHtml] = React.useState(html);
1162
1170
  const [tooltipPlace, setTooltipPlace] = React.useState(place);
@@ -1426,6 +1434,7 @@ const TooltipController = React__default["default"].forwardRef(({ id, anchorId,
1426
1434
  border,
1427
1435
  opacity,
1428
1436
  arrowColor,
1437
+ arrowSize,
1429
1438
  setIsOpen,
1430
1439
  afterShow,
1431
1440
  afterHide,
@@ -1448,6 +1457,7 @@ const TooltipCoreStyles = `:root {
1448
1457
  --rt-opacity: 0.9;
1449
1458
  --rt-transition-show-delay: 0.15s;
1450
1459
  --rt-transition-closing-delay: 0.15s;
1460
+ --rt-arrow-size: 8px;
1451
1461
  }
1452
1462
 
1453
1463
  .core-styles-module_tooltip__3vRRp {
@@ -1466,6 +1476,7 @@ const TooltipCoreStyles = `:root {
1466
1476
  .core-styles-module_arrow__cvMwQ {
1467
1477
  position: absolute;
1468
1478
  background: inherit;
1479
+ z-index: -1;
1469
1480
  }
1470
1481
 
1471
1482
  .core-styles-module_noArrow__xock6 {
@@ -1497,8 +1508,8 @@ const TooltipStyles = `
1497
1508
  }
1498
1509
 
1499
1510
  .styles-module_arrow__K0L3T {
1500
- width: 8px;
1501
- height: 8px;
1511
+ width: var(--rt-arrow-size);
1512
+ height: var(--rt-arrow-size);
1502
1513
  }
1503
1514
 
1504
1515
  [class*='react-tooltip__place-top'] > .styles-module_arrow__K0L3T {