@primer/react 0.0.0-20260701224029 → 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 -12
- 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",
|
|
@@ -79,18 +95,11 @@ const emptyKeybindingHints = [];
|
|
|
79
95
|
const Tooltip = /*#__PURE__*/ React.forwardRef(({ direction = "s", text, type = "description", children, id, className, keybindingHint = emptyKeybindingHints, delay = "short", _privateDisableTooltip = false, ...rest }, forwardedRef) => {
|
|
80
96
|
const tooltipId = useId$1(id);
|
|
81
97
|
const child = Children.only(children);
|
|
82
|
-
const childRef = child.props.ref;
|
|
83
98
|
const triggerRef = useRef(null);
|
|
84
|
-
const tooltipElRef =
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
};
|
|
89
|
-
const setTriggerRef = (node) => {
|
|
90
|
-
assignRef(triggerRef, node);
|
|
91
|
-
assignRef(childRef, node);
|
|
92
|
-
assignRef(forwardedRef, node);
|
|
93
|
-
};
|
|
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]);
|
|
94
103
|
const [calculatedDirection, setCalculatedDirection] = useState(direction);
|
|
95
104
|
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
|
|
96
105
|
const openTimeoutRef = React.useRef(null);
|
|
@@ -166,7 +175,7 @@ const Tooltip = /*#__PURE__*/ React.forwardRef(({ direction = "s", text, type =
|
|
|
166
175
|
return /*#__PURE__*/ jsx(TooltipContext.Provider, {
|
|
167
176
|
value,
|
|
168
177
|
children: /*#__PURE__*/ jsxs(Fragment, { children: [/*#__PURE__*/ React.isValidElement(child) && /*#__PURE__*/ React.cloneElement(child, {
|
|
169
|
-
ref:
|
|
178
|
+
ref: triggerMergedRef,
|
|
170
179
|
"aria-describedby": (() => {
|
|
171
180
|
if (type !== "description") return child.props["aria-describedby"];
|
|
172
181
|
const existingDescribedBy = child.props["aria-describedby"];
|
package/package.json
CHANGED