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.mjs
CHANGED
|
@@ -392,14 +392,13 @@ const Tooltip = ({
|
|
|
392
392
|
// props
|
|
393
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,
|
|
394
394
|
// props handled by controller
|
|
395
|
-
content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnchor, setActiveAnchor, border, opacity, arrowColor, arrowSize = 8, role = 'tooltip', }) => {
|
|
395
|
+
content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, previousActiveAnchor, activeAnchor, setActiveAnchor, border, opacity, arrowColor, arrowSize = 8, role = 'tooltip', }) => {
|
|
396
396
|
var _a;
|
|
397
397
|
const tooltipRef = useRef(null);
|
|
398
398
|
const tooltipArrowRef = useRef(null);
|
|
399
399
|
const tooltipShowDelayTimerRef = useRef(null);
|
|
400
400
|
const tooltipHideDelayTimerRef = useRef(null);
|
|
401
401
|
const missedTransitionTimerRef = useRef(null);
|
|
402
|
-
const tooltipShowTimerRef = useRef(null);
|
|
403
402
|
const [computedPosition, setComputedPosition] = useState({
|
|
404
403
|
tooltipStyles: {},
|
|
405
404
|
tooltipArrowStyles: {},
|
|
@@ -511,8 +510,7 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
|
|
|
511
510
|
* wait for the component to render and calculate position
|
|
512
511
|
* before actually showing
|
|
513
512
|
*/
|
|
514
|
-
|
|
515
|
-
tooltipShowTimerRef.current = setTimeout(() => {
|
|
513
|
+
setTimeout(() => {
|
|
516
514
|
if (!mounted.current) {
|
|
517
515
|
return;
|
|
518
516
|
}
|
|
@@ -522,6 +520,41 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
|
|
|
522
520
|
}
|
|
523
521
|
}, 10);
|
|
524
522
|
};
|
|
523
|
+
/**
|
|
524
|
+
* Add aria-describedby to activeAnchor when tooltip is active
|
|
525
|
+
*/
|
|
526
|
+
useEffect(() => {
|
|
527
|
+
if (!id)
|
|
528
|
+
return;
|
|
529
|
+
function getAriaDescribedBy(element) {
|
|
530
|
+
var _a;
|
|
531
|
+
return ((_a = element === null || element === void 0 ? void 0 : element.getAttribute('aria-describedby')) === null || _a === void 0 ? void 0 : _a.split(' ')) || [];
|
|
532
|
+
}
|
|
533
|
+
function removeAriaDescribedBy(element) {
|
|
534
|
+
const newDescribedBy = getAriaDescribedBy(element).filter((s) => s !== id);
|
|
535
|
+
if (newDescribedBy.length) {
|
|
536
|
+
element === null || element === void 0 ? void 0 : element.setAttribute('aria-describedby', newDescribedBy.join(' '));
|
|
537
|
+
}
|
|
538
|
+
else {
|
|
539
|
+
element === null || element === void 0 ? void 0 : element.removeAttribute('aria-describedby');
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
if (show) {
|
|
543
|
+
removeAriaDescribedBy(previousActiveAnchor);
|
|
544
|
+
const currentDescribedBy = getAriaDescribedBy(activeAnchor);
|
|
545
|
+
const describedBy = [...new Set([...currentDescribedBy, id])].filter(Boolean).join(' ');
|
|
546
|
+
activeAnchor === null || activeAnchor === void 0 ? void 0 : activeAnchor.setAttribute('aria-describedby', describedBy);
|
|
547
|
+
}
|
|
548
|
+
else {
|
|
549
|
+
removeAriaDescribedBy(activeAnchor);
|
|
550
|
+
}
|
|
551
|
+
// eslint-disable-next-line consistent-return
|
|
552
|
+
return () => {
|
|
553
|
+
// cleanup aria-describedby when the tooltip is closed
|
|
554
|
+
removeAriaDescribedBy(activeAnchor);
|
|
555
|
+
removeAriaDescribedBy(previousActiveAnchor);
|
|
556
|
+
};
|
|
557
|
+
}, [activeAnchor, show, id, previousActiveAnchor]);
|
|
525
558
|
/**
|
|
526
559
|
* this replicates the effect from `handleShow()`
|
|
527
560
|
* when `isOpen` is changed from outside
|
|
@@ -657,9 +690,6 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
|
|
|
657
690
|
border,
|
|
658
691
|
arrowSize,
|
|
659
692
|
}).then((computedStylesData) => {
|
|
660
|
-
if (!mounted.current) {
|
|
661
|
-
return;
|
|
662
|
-
}
|
|
663
693
|
handleComputedPosition(computedStylesData);
|
|
664
694
|
});
|
|
665
695
|
};
|
|
@@ -1035,29 +1065,17 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
|
|
|
1035
1065
|
updateTooltipPosition();
|
|
1036
1066
|
}, [updateTooltipPosition]);
|
|
1037
1067
|
useEffect(() => {
|
|
1038
|
-
if (!
|
|
1068
|
+
if (!(contentWrapperRef === null || contentWrapperRef === void 0 ? void 0 : contentWrapperRef.current)) {
|
|
1039
1069
|
return () => null;
|
|
1040
1070
|
}
|
|
1041
|
-
const timeoutIds = new Set();
|
|
1042
1071
|
const contentObserver = new ResizeObserver(() => {
|
|
1043
|
-
|
|
1044
|
-
timeoutIds.delete(timeoutId);
|
|
1045
|
-
if (!mounted.current) {
|
|
1046
|
-
return;
|
|
1047
|
-
}
|
|
1048
|
-
updateTooltipPosition();
|
|
1049
|
-
});
|
|
1050
|
-
timeoutIds.add(timeoutId);
|
|
1072
|
+
setTimeout(() => updateTooltipPosition());
|
|
1051
1073
|
});
|
|
1052
1074
|
contentObserver.observe(contentWrapperRef.current);
|
|
1053
1075
|
return () => {
|
|
1054
1076
|
contentObserver.disconnect();
|
|
1055
|
-
timeoutIds.forEach((timeoutId) => {
|
|
1056
|
-
clearTimeout(timeoutId);
|
|
1057
|
-
});
|
|
1058
|
-
timeoutIds.clear();
|
|
1059
1077
|
};
|
|
1060
|
-
}, [
|
|
1078
|
+
}, [content, contentWrapperRef === null || contentWrapperRef === void 0 ? void 0 : contentWrapperRef.current]);
|
|
1061
1079
|
useEffect(() => {
|
|
1062
1080
|
var _a;
|
|
1063
1081
|
const anchorById = document.querySelector(`[id='${anchorId}']`);
|
|
@@ -1078,7 +1096,6 @@ content, contentWrapperRef, isOpen, defaultIsOpen = false, setIsOpen, activeAnch
|
|
|
1078
1096
|
return () => {
|
|
1079
1097
|
clearTimeoutRef(tooltipShowDelayTimerRef);
|
|
1080
1098
|
clearTimeoutRef(tooltipHideDelayTimerRef);
|
|
1081
|
-
clearTimeoutRef(tooltipShowTimerRef);
|
|
1082
1099
|
};
|
|
1083
1100
|
}, []);
|
|
1084
1101
|
useEffect(() => {
|
|
@@ -1188,6 +1205,7 @@ const TooltipController = React.forwardRef(({ id, anchorId, anchorSelect, conten
|
|
|
1188
1205
|
const [tooltipPositionStrategy, setTooltipPositionStrategy] = useState(positionStrategy);
|
|
1189
1206
|
const [tooltipClassName, setTooltipClassName] = useState(null);
|
|
1190
1207
|
const [activeAnchor, setActiveAnchor] = useState(null);
|
|
1208
|
+
const previousActiveAnchorRef = useRef(null);
|
|
1191
1209
|
const styleInjectionRef = useRef(disableStyleInjection);
|
|
1192
1210
|
/**
|
|
1193
1211
|
* @todo Remove this in a future version (provider/wrapper method is deprecated)
|
|
@@ -1449,7 +1467,15 @@ const TooltipController = React.forwardRef(({ id, anchorId, anchorSelect, conten
|
|
|
1449
1467
|
afterHide,
|
|
1450
1468
|
disableTooltip,
|
|
1451
1469
|
activeAnchor,
|
|
1452
|
-
|
|
1470
|
+
previousActiveAnchor: previousActiveAnchorRef.current,
|
|
1471
|
+
setActiveAnchor: (anchor) => {
|
|
1472
|
+
setActiveAnchor((prev) => {
|
|
1473
|
+
if (!(anchor === null || anchor === void 0 ? void 0 : anchor.isSameNode(prev))) {
|
|
1474
|
+
previousActiveAnchorRef.current = prev;
|
|
1475
|
+
}
|
|
1476
|
+
return anchor;
|
|
1477
|
+
});
|
|
1478
|
+
},
|
|
1453
1479
|
role,
|
|
1454
1480
|
};
|
|
1455
1481
|
return React.createElement(Tooltip, { ...props });
|