react-tooltip 5.29.1-beta.1258.rc.1 → 5.30.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.
- package/dist/react-tooltip.cjs +50 -24
- package/dist/react-tooltip.cjs.map +1 -1
- package/dist/react-tooltip.min.cjs +2 -2
- package/dist/react-tooltip.min.cjs.map +1 -1
- package/dist/react-tooltip.min.mjs +2 -2
- package/dist/react-tooltip.min.mjs.map +1 -1
- package/dist/react-tooltip.mjs +50 -24
- package/dist/react-tooltip.mjs.map +1 -1
- package/dist/react-tooltip.umd.js +50 -24
- package/dist/react-tooltip.umd.js.map +1 -1
- package/dist/react-tooltip.umd.min.js +2 -2
- package/dist/react-tooltip.umd.min.js.map +1 -1
- package/package.json +1 -1
package/dist/react-tooltip.cjs
CHANGED
|
@@ -401,14 +401,13 @@ 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, arrowSize = 8, role = 'tooltip', }) => {
|
|
404
|
+
content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, previousActiveAnchor, 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);
|
|
408
408
|
const tooltipShowDelayTimerRef = React.useRef(null);
|
|
409
409
|
const tooltipHideDelayTimerRef = React.useRef(null);
|
|
410
410
|
const missedTransitionTimerRef = React.useRef(null);
|
|
411
|
-
const tooltipShowTimerRef = React.useRef(null);
|
|
412
411
|
const [computedPosition, setComputedPosition] = React.useState({
|
|
413
412
|
tooltipStyles: {},
|
|
414
413
|
tooltipArrowStyles: {},
|
|
@@ -520,8 +519,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
|
|
|
520
519
|
* wait for the component to render and calculate position
|
|
521
520
|
* before actually showing
|
|
522
521
|
*/
|
|
523
|
-
|
|
524
|
-
tooltipShowTimerRef.current = setTimeout(() => {
|
|
522
|
+
setTimeout(() => {
|
|
525
523
|
if (!mounted.current) {
|
|
526
524
|
return;
|
|
527
525
|
}
|
|
@@ -531,6 +529,41 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
|
|
|
531
529
|
}
|
|
532
530
|
}, 10);
|
|
533
531
|
};
|
|
532
|
+
/**
|
|
533
|
+
* Add aria-describedby to activeAnchor when tooltip is active
|
|
534
|
+
*/
|
|
535
|
+
React.useEffect(() => {
|
|
536
|
+
if (!id)
|
|
537
|
+
return;
|
|
538
|
+
function getAriaDescribedBy(element) {
|
|
539
|
+
var _a;
|
|
540
|
+
return ((_a = element === null || element === void 0 ? void 0 : element.getAttribute('aria-describedby')) === null || _a === void 0 ? void 0 : _a.split(' ')) || [];
|
|
541
|
+
}
|
|
542
|
+
function removeAriaDescribedBy(element) {
|
|
543
|
+
const newDescribedBy = getAriaDescribedBy(element).filter((s) => s !== id);
|
|
544
|
+
if (newDescribedBy.length) {
|
|
545
|
+
element === null || element === void 0 ? void 0 : element.setAttribute('aria-describedby', newDescribedBy.join(' '));
|
|
546
|
+
}
|
|
547
|
+
else {
|
|
548
|
+
element === null || element === void 0 ? void 0 : element.removeAttribute('aria-describedby');
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
if (show) {
|
|
552
|
+
removeAriaDescribedBy(previousActiveAnchor);
|
|
553
|
+
const currentDescribedBy = getAriaDescribedBy(activeAnchor);
|
|
554
|
+
const describedBy = [...new Set([...currentDescribedBy, id])].filter(Boolean).join(' ');
|
|
555
|
+
activeAnchor === null || activeAnchor === void 0 ? void 0 : activeAnchor.setAttribute('aria-describedby', describedBy);
|
|
556
|
+
}
|
|
557
|
+
else {
|
|
558
|
+
removeAriaDescribedBy(activeAnchor);
|
|
559
|
+
}
|
|
560
|
+
// eslint-disable-next-line consistent-return
|
|
561
|
+
return () => {
|
|
562
|
+
// cleanup aria-describedby when the tooltip is closed
|
|
563
|
+
removeAriaDescribedBy(activeAnchor);
|
|
564
|
+
removeAriaDescribedBy(previousActiveAnchor);
|
|
565
|
+
};
|
|
566
|
+
}, [activeAnchor, show, id, previousActiveAnchor]);
|
|
534
567
|
/**
|
|
535
568
|
* this replicates the effect from `handleShow()`
|
|
536
569
|
* when `isOpen` is changed from outside
|
|
@@ -666,9 +699,6 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
|
|
|
666
699
|
border,
|
|
667
700
|
arrowSize,
|
|
668
701
|
}).then((computedStylesData) => {
|
|
669
|
-
if (!mounted.current) {
|
|
670
|
-
return;
|
|
671
|
-
}
|
|
672
702
|
handleComputedPosition(computedStylesData);
|
|
673
703
|
});
|
|
674
704
|
};
|
|
@@ -1044,29 +1074,17 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
|
|
|
1044
1074
|
updateTooltipPosition();
|
|
1045
1075
|
}, [updateTooltipPosition]);
|
|
1046
1076
|
React.useEffect(() => {
|
|
1047
|
-
if (!
|
|
1077
|
+
if (!(contentWrapperRef === null || contentWrapperRef === void 0 ? void 0 : contentWrapperRef.current)) {
|
|
1048
1078
|
return () => null;
|
|
1049
1079
|
}
|
|
1050
|
-
const timeoutIds = new Set();
|
|
1051
1080
|
const contentObserver = new ResizeObserver(() => {
|
|
1052
|
-
|
|
1053
|
-
timeoutIds.delete(timeoutId);
|
|
1054
|
-
if (!mounted.current) {
|
|
1055
|
-
return;
|
|
1056
|
-
}
|
|
1057
|
-
updateTooltipPosition();
|
|
1058
|
-
});
|
|
1059
|
-
timeoutIds.add(timeoutId);
|
|
1081
|
+
setTimeout(() => updateTooltipPosition());
|
|
1060
1082
|
});
|
|
1061
1083
|
contentObserver.observe(contentWrapperRef.current);
|
|
1062
1084
|
return () => {
|
|
1063
1085
|
contentObserver.disconnect();
|
|
1064
|
-
timeoutIds.forEach((timeoutId) => {
|
|
1065
|
-
clearTimeout(timeoutId);
|
|
1066
|
-
});
|
|
1067
|
-
timeoutIds.clear();
|
|
1068
1086
|
};
|
|
1069
|
-
}, [
|
|
1087
|
+
}, [content, contentWrapperRef === null || contentWrapperRef === void 0 ? void 0 : contentWrapperRef.current]);
|
|
1070
1088
|
React.useEffect(() => {
|
|
1071
1089
|
var _a;
|
|
1072
1090
|
const anchorById = document.querySelector(`[id='${anchorId}']`);
|
|
@@ -1087,7 +1105,6 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
|
|
|
1087
1105
|
return () => {
|
|
1088
1106
|
clearTimeoutRef(tooltipShowDelayTimerRef);
|
|
1089
1107
|
clearTimeoutRef(tooltipHideDelayTimerRef);
|
|
1090
|
-
clearTimeoutRef(tooltipShowTimerRef);
|
|
1091
1108
|
};
|
|
1092
1109
|
}, []);
|
|
1093
1110
|
React.useEffect(() => {
|
|
@@ -1197,6 +1214,7 @@ const TooltipController = React__default["default"].forwardRef(({ id, anchorId,
|
|
|
1197
1214
|
const [tooltipPositionStrategy, setTooltipPositionStrategy] = React.useState(positionStrategy);
|
|
1198
1215
|
const [tooltipClassName, setTooltipClassName] = React.useState(null);
|
|
1199
1216
|
const [activeAnchor, setActiveAnchor] = React.useState(null);
|
|
1217
|
+
const previousActiveAnchorRef = React.useRef(null);
|
|
1200
1218
|
const styleInjectionRef = React.useRef(disableStyleInjection);
|
|
1201
1219
|
/**
|
|
1202
1220
|
* @todo Remove this in a future version (provider/wrapper method is deprecated)
|
|
@@ -1458,7 +1476,15 @@ const TooltipController = React__default["default"].forwardRef(({ id, anchorId,
|
|
|
1458
1476
|
afterHide,
|
|
1459
1477
|
disableTooltip,
|
|
1460
1478
|
activeAnchor,
|
|
1461
|
-
|
|
1479
|
+
previousActiveAnchor: previousActiveAnchorRef.current,
|
|
1480
|
+
setActiveAnchor: (anchor) => {
|
|
1481
|
+
setActiveAnchor((prev) => {
|
|
1482
|
+
if (!(anchor === null || anchor === void 0 ? void 0 : anchor.isSameNode(prev))) {
|
|
1483
|
+
previousActiveAnchorRef.current = prev;
|
|
1484
|
+
}
|
|
1485
|
+
return anchor;
|
|
1486
|
+
});
|
|
1487
|
+
},
|
|
1462
1488
|
role,
|
|
1463
1489
|
};
|
|
1464
1490
|
return React__default["default"].createElement(Tooltip, { ...props });
|