@primer/react 0.0.0-20260701230315 → 0.0.0-20260701234532
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/CHANGELOG.md +1 -1
- package/dist/TooltipV2/Tooltip.js +21 -15
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useMergedRefs } from "../hooks/useMergedRefs.js";
|
|
1
2
|
import { useOnEscapePress } from "../hooks/useOnEscapePress.js";
|
|
2
3
|
import { useId as useId$1 } from "../hooks/useId.js";
|
|
3
4
|
import { warning } from "../utils/warning.js";
|
|
@@ -15,6 +16,21 @@ import React, { Children, useEffect, useMemo, useRef, useState } from "react";
|
|
|
15
16
|
import { getAnchoredPosition } from "@primer/behaviors";
|
|
16
17
|
import { apply, isSupported } from "@oddbird/popover-polyfill/fn";
|
|
17
18
|
//#region src/TooltipV2/Tooltip.tsx
|
|
19
|
+
function mergeRefs(...refs) {
|
|
20
|
+
return (value) => {
|
|
21
|
+
const cleanups = [];
|
|
22
|
+
for (const ref of refs) {
|
|
23
|
+
if (!ref) continue;
|
|
24
|
+
if (typeof ref === "function") {
|
|
25
|
+
const cleanup = ref(value);
|
|
26
|
+
if (typeof cleanup === "function") cleanups.push(cleanup);
|
|
27
|
+
} else ref.current = value;
|
|
28
|
+
}
|
|
29
|
+
if (cleanups.length > 0) return () => {
|
|
30
|
+
for (const cleanup of cleanups) cleanup();
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
}
|
|
18
34
|
const directionToPosition = {
|
|
19
35
|
nw: {
|
|
20
36
|
side: "outside-top",
|
|
@@ -75,25 +91,15 @@ const delayTimeMap = {
|
|
|
75
91
|
const isInteractive = (element) => {
|
|
76
92
|
return interactiveElements.some((selector) => element.matches(selector)) || element.hasAttribute("role") && element.getAttribute("role") === "button";
|
|
77
93
|
};
|
|
78
|
-
function getChildRef(element) {
|
|
79
|
-
return "ref" in element ? element.ref : void 0;
|
|
80
|
-
}
|
|
81
94
|
const emptyKeybindingHints = [];
|
|
82
95
|
const Tooltip = /*#__PURE__*/ React.forwardRef(({ direction = "s", text, type = "description", children, id, className, keybindingHint = emptyKeybindingHints, delay = "short", _privateDisableTooltip = false, ...rest }, forwardedRef) => {
|
|
83
96
|
const tooltipId = useId$1(id);
|
|
84
97
|
const child = Children.only(children);
|
|
85
|
-
const childRef = /*#__PURE__*/ React.isValidElement(child) ? getChildRef(child) : void 0;
|
|
86
98
|
const triggerRef = useRef(null);
|
|
87
|
-
const tooltipElRef =
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
};
|
|
92
|
-
const setTriggerRef = (node) => {
|
|
93
|
-
assignRef(triggerRef, node);
|
|
94
|
-
assignRef(childRef, node);
|
|
95
|
-
assignRef(forwardedRef, node);
|
|
96
|
-
};
|
|
99
|
+
const tooltipElRef = useRef(null);
|
|
100
|
+
const mergedTooltipRef = useMergedRefs(forwardedRef, triggerRef);
|
|
101
|
+
const childPropRef = /*#__PURE__*/ React.isValidElement(child) && "props" in child ? child.props.ref : void 0;
|
|
102
|
+
const triggerMergedRef = useMemo(() => mergeRefs(mergedTooltipRef, childPropRef), [mergedTooltipRef, childPropRef]);
|
|
97
103
|
const [calculatedDirection, setCalculatedDirection] = useState(direction);
|
|
98
104
|
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
|
|
99
105
|
const openTimeoutRef = React.useRef(null);
|
|
@@ -169,7 +175,7 @@ const Tooltip = /*#__PURE__*/ React.forwardRef(({ direction = "s", text, type =
|
|
|
169
175
|
return /*#__PURE__*/ jsx(TooltipContext.Provider, {
|
|
170
176
|
value,
|
|
171
177
|
children: /*#__PURE__*/ jsxs(Fragment, { children: [/*#__PURE__*/ React.isValidElement(child) && /*#__PURE__*/ React.cloneElement(child, {
|
|
172
|
-
ref:
|
|
178
|
+
ref: triggerMergedRef,
|
|
173
179
|
"aria-describedby": (() => {
|
|
174
180
|
if (type !== "description") return child.props["aria-describedby"];
|
|
175
181
|
const existingDescribedBy = child.props["aria-describedby"];
|
package/package.json
CHANGED