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