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