@primer/react 0.0.0-20260630235402 → 0.0.0-20260701173825
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.d.ts.map +1 -1
- package/dist/TooltipV2/Tooltip.js +25 -16
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tooltip.d.ts","sourceRoot":"","sources":["../../src/TooltipV2/Tooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAyC,KAAK,yBAAyB,EAAS,MAAM,OAAO,CAAA;AAS3G,OAAO,EAAoD,KAAK,mBAAmB,EAAC,MAAM,mBAAmB,CAAA;AAI7G,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,gBAAgB,CAAA;AAG9C,MAAM,MAAM,gBAAgB,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,CAAA;AAChF,MAAM,MAAM,YAAY,GAAG,KAAK,CAAC,iBAAiB,CAAC;IACjD,SAAS,CAAC,EAAE,gBAAgB,CAAA;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,OAAO,GAAG,aAAa,CAAA;IAC9B,cAAc,CAAC,EAAE,mBAAmB,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC,CAAA;IACjF;;;;;OAKG;IACH,KAAK,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAA;IACnC;;;;;;;;OAQG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAA;CACjC,CAAC,GACA,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC,CAAA;AAmEnC,eAAO,MAAM,OAAO,EAAE,yBAAyB,CAC7C,KAAK,CAAC,eAAe,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC,aAAa,CAAC,WAAW,CAAC,CACvE,GACC,
|
|
1
|
+
{"version":3,"file":"Tooltip.d.ts","sourceRoot":"","sources":["../../src/TooltipV2/Tooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAyC,KAAK,yBAAyB,EAAS,MAAM,OAAO,CAAA;AAS3G,OAAO,EAAoD,KAAK,mBAAmB,EAAC,MAAM,mBAAmB,CAAA;AAI7G,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,gBAAgB,CAAA;AAG9C,MAAM,MAAM,gBAAgB,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,GAAG,GAAG,CAAA;AAChF,MAAM,MAAM,YAAY,GAAG,KAAK,CAAC,iBAAiB,CAAC;IACjD,SAAS,CAAC,EAAE,gBAAgB,CAAA;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,OAAO,GAAG,aAAa,CAAA;IAC9B,cAAc,CAAC,EAAE,mBAAmB,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC,CAAA;IACjF;;;;;OAKG;IACH,KAAK,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAA;IACnC;;;;;;;;OAQG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAA;CACjC,CAAC,GACA,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC,CAAA;AAmEnC,eAAO,MAAM,OAAO,EAAE,yBAAyB,CAC7C,KAAK,CAAC,eAAe,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC,aAAa,CAAC,WAAW,CAAC,CACvE,GACC,UAiUD,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { Children,
|
|
1
|
+
import React, { Children, useState, useMemo, useEffect } from 'react';
|
|
2
2
|
import { invariant } from '../utils/invariant.js';
|
|
3
3
|
import { warning } from '../utils/warning.js';
|
|
4
4
|
import { getAnchoredPosition } from '@primer/behaviors';
|
|
@@ -92,21 +92,21 @@ const Tooltip = /*#__PURE__*/React.forwardRef(({
|
|
|
92
92
|
const tooltipId = useId(id);
|
|
93
93
|
const child = Children.only(children);
|
|
94
94
|
const childRef = child.ref;
|
|
95
|
-
const triggerRef = useRef(null);
|
|
95
|
+
const triggerRef = React.useRef(null);
|
|
96
96
|
const tooltipElRef = React.useRef(null);
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if (
|
|
101
|
-
|
|
102
|
-
} else if (ref) {
|
|
103
|
-
ref.current = node;
|
|
97
|
+
const setForwardedRef = React.useCallback(node => {
|
|
98
|
+
if (typeof forwardedRef === 'function') {
|
|
99
|
+
forwardedRef(node);
|
|
100
|
+
} else if (forwardedRef) {
|
|
101
|
+
forwardedRef.current = node;
|
|
104
102
|
}
|
|
105
|
-
};
|
|
106
|
-
const setTriggerRef = node => {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
103
|
+
}, [forwardedRef]);
|
|
104
|
+
const setTriggerRef = React.useCallback(node => {
|
|
105
|
+
triggerRef.current = node;
|
|
106
|
+
setForwardedRef(node);
|
|
107
|
+
}, [setForwardedRef]);
|
|
108
|
+
const setTriggerFromEvent = event => {
|
|
109
|
+
triggerRef.current = event.currentTarget;
|
|
110
110
|
};
|
|
111
111
|
const [calculatedDirection, setCalculatedDirection] = useState(direction);
|
|
112
112
|
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
|
|
@@ -220,8 +220,11 @@ const Tooltip = /*#__PURE__*/React.forwardRef(({
|
|
|
220
220
|
value: value,
|
|
221
221
|
children: /*#__PURE__*/jsxs(Fragment, {
|
|
222
222
|
children: [/*#__PURE__*/React.isValidElement(child) && /*#__PURE__*/React.cloneElement(child, {
|
|
223
|
-
|
|
224
|
-
|
|
223
|
+
...(childRef ? {} : {
|
|
224
|
+
ref: setTriggerRef
|
|
225
|
+
}),
|
|
226
|
+
// Preserve an existing child ref and track the trigger from events instead of
|
|
227
|
+
// overriding the child's ref, which can interfere with nested overlay behavior.
|
|
225
228
|
'aria-describedby': (() => {
|
|
226
229
|
// If tooltip is not a description type, keep the original aria-describedby
|
|
227
230
|
if (type !== 'description') {
|
|
@@ -241,11 +244,13 @@ const Tooltip = /*#__PURE__*/React.forwardRef(({
|
|
|
241
244
|
'aria-labelledby': type === 'label' ? tooltipId : child.props['aria-labelledby'],
|
|
242
245
|
onBlur: event => {
|
|
243
246
|
var _child$props$onBlur, _child$props;
|
|
247
|
+
setTriggerFromEvent(event);
|
|
244
248
|
closeTooltip();
|
|
245
249
|
(_child$props$onBlur = (_child$props = child.props).onBlur) === null || _child$props$onBlur === void 0 ? void 0 : _child$props$onBlur.call(_child$props, event);
|
|
246
250
|
},
|
|
247
251
|
onTouchEnd: event => {
|
|
248
252
|
var _child$props$onTouchE, _child$props2;
|
|
253
|
+
setTriggerFromEvent(event);
|
|
249
254
|
(_child$props$onTouchE = (_child$props2 = child.props).onTouchEnd) === null || _child$props$onTouchE === void 0 ? void 0 : _child$props$onTouchE.call(_child$props2, event);
|
|
250
255
|
|
|
251
256
|
// Hide tooltips on tap to essentially disable them on touch devices;
|
|
@@ -254,6 +259,8 @@ const Tooltip = /*#__PURE__*/React.forwardRef(({
|
|
|
254
259
|
},
|
|
255
260
|
onFocus: event => {
|
|
256
261
|
var _child$props$onFocus, _child$props3;
|
|
262
|
+
setTriggerFromEvent(event);
|
|
263
|
+
|
|
257
264
|
// only show tooltip on :focus-visible, not on :focus
|
|
258
265
|
try {
|
|
259
266
|
if (!event.target.matches(':focus-visible')) return;
|
|
@@ -265,6 +272,7 @@ const Tooltip = /*#__PURE__*/React.forwardRef(({
|
|
|
265
272
|
(_child$props$onFocus = (_child$props3 = child.props).onFocus) === null || _child$props$onFocus === void 0 ? void 0 : _child$props$onFocus.call(_child$props3, event);
|
|
266
273
|
},
|
|
267
274
|
onMouseOverCapture: event => {
|
|
275
|
+
setTriggerFromEvent(event);
|
|
268
276
|
const delayTime = delayTimeMap[delay] || 50;
|
|
269
277
|
// We use a `capture` event to ensure this is called first before
|
|
270
278
|
// events that might cancel the opening timeout (like `onTouchEnd`)
|
|
@@ -280,6 +288,7 @@ const Tooltip = /*#__PURE__*/React.forwardRef(({
|
|
|
280
288
|
},
|
|
281
289
|
onMouseLeave: event => {
|
|
282
290
|
var _child$props$onMouseL, _child$props5;
|
|
291
|
+
setTriggerFromEvent(event);
|
|
283
292
|
closeTooltip();
|
|
284
293
|
(_child$props$onMouseL = (_child$props5 = child.props).onMouseLeave) === null || _child$props$onMouseL === void 0 ? void 0 : _child$props$onMouseL.call(_child$props5, event);
|
|
285
294
|
}
|
package/package.json
CHANGED