@primer/react 0.0.0-20260701183829 → 0.0.0-20260701220623
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
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,
|
|
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,UAgTD,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { Children, useState, useMemo, useEffect } from 'react';
|
|
1
|
+
import React, { Children, useRef, 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 =
|
|
95
|
+
const triggerRef = useRef(null);
|
|
96
96
|
const tooltipElRef = React.useRef(null);
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
97
|
+
|
|
98
|
+
// Tooltip clones its trigger, so compose refs manually to avoid overwriting the child's original ref
|
|
99
|
+
const assignRef = (ref, node) => {
|
|
100
|
+
if (typeof ref === 'function') {
|
|
101
|
+
ref(node);
|
|
102
|
+
} else if (ref) {
|
|
103
|
+
ref.current = node;
|
|
102
104
|
}
|
|
103
|
-
}
|
|
104
|
-
const setTriggerRef =
|
|
105
|
-
triggerRef
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const setTriggerFromEvent = event => {
|
|
109
|
-
triggerRef.current = event.currentTarget;
|
|
105
|
+
};
|
|
106
|
+
const setTriggerRef = node => {
|
|
107
|
+
assignRef(triggerRef, node);
|
|
108
|
+
assignRef(childRef, node);
|
|
109
|
+
assignRef(forwardedRef, node);
|
|
110
110
|
};
|
|
111
111
|
const [calculatedDirection, setCalculatedDirection] = useState(direction);
|
|
112
112
|
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
|
|
@@ -220,11 +220,8 @@ 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
|
-
|
|
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.
|
|
223
|
+
ref: setTriggerRef,
|
|
224
|
+
// If it is a type description, we use tooltip to describe the trigger
|
|
228
225
|
'aria-describedby': (() => {
|
|
229
226
|
// If tooltip is not a description type, keep the original aria-describedby
|
|
230
227
|
if (type !== 'description') {
|
|
@@ -244,13 +241,11 @@ const Tooltip = /*#__PURE__*/React.forwardRef(({
|
|
|
244
241
|
'aria-labelledby': type === 'label' ? tooltipId : child.props['aria-labelledby'],
|
|
245
242
|
onBlur: event => {
|
|
246
243
|
var _child$props$onBlur, _child$props;
|
|
247
|
-
setTriggerFromEvent(event);
|
|
248
244
|
closeTooltip();
|
|
249
245
|
(_child$props$onBlur = (_child$props = child.props).onBlur) === null || _child$props$onBlur === void 0 ? void 0 : _child$props$onBlur.call(_child$props, event);
|
|
250
246
|
},
|
|
251
247
|
onTouchEnd: event => {
|
|
252
248
|
var _child$props$onTouchE, _child$props2;
|
|
253
|
-
setTriggerFromEvent(event);
|
|
254
249
|
(_child$props$onTouchE = (_child$props2 = child.props).onTouchEnd) === null || _child$props$onTouchE === void 0 ? void 0 : _child$props$onTouchE.call(_child$props2, event);
|
|
255
250
|
|
|
256
251
|
// Hide tooltips on tap to essentially disable them on touch devices;
|
|
@@ -259,20 +254,14 @@ const Tooltip = /*#__PURE__*/React.forwardRef(({
|
|
|
259
254
|
},
|
|
260
255
|
onFocus: event => {
|
|
261
256
|
var _child$props$onFocus, _child$props3;
|
|
262
|
-
setTriggerFromEvent(event);
|
|
263
|
-
|
|
264
|
-
// only show tooltip on :focus-visible, not on :focus
|
|
265
257
|
try {
|
|
266
258
|
if (!event.target.matches(':focus-visible')) return;
|
|
267
|
-
} catch (_error) {
|
|
268
|
-
|
|
269
|
-
// https://github.com/jsdom/jsdom/issues/3426
|
|
270
|
-
}
|
|
259
|
+
} catch (_error) {}
|
|
260
|
+
if (event.currentTarget.hasAttribute('data-restoring-focus')) return;
|
|
271
261
|
openTooltip();
|
|
272
262
|
(_child$props$onFocus = (_child$props3 = child.props).onFocus) === null || _child$props$onFocus === void 0 ? void 0 : _child$props$onFocus.call(_child$props3, event);
|
|
273
263
|
},
|
|
274
264
|
onMouseOverCapture: event => {
|
|
275
|
-
setTriggerFromEvent(event);
|
|
276
265
|
const delayTime = delayTimeMap[delay] || 50;
|
|
277
266
|
// We use a `capture` event to ensure this is called first before
|
|
278
267
|
// events that might cancel the opening timeout (like `onTouchEnd`)
|
|
@@ -288,7 +277,6 @@ const Tooltip = /*#__PURE__*/React.forwardRef(({
|
|
|
288
277
|
},
|
|
289
278
|
onMouseLeave: event => {
|
|
290
279
|
var _child$props$onMouseL, _child$props5;
|
|
291
|
-
setTriggerFromEvent(event);
|
|
292
280
|
closeTooltip();
|
|
293
281
|
(_child$props$onMouseL = (_child$props5 = child.props).onMouseLeave) === null || _child$props$onMouseL === void 0 ? void 0 : _child$props$onMouseL.call(_child$props5, event);
|
|
294
282
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOpenAndCloseFocus.d.ts","sourceRoot":"","sources":["../../src/hooks/useOpenAndCloseFocus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAI9B,MAAM,MAAM,4BAA4B,GAAG;IACzC,eAAe,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAA;IACrD,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAA;IACjD,cAAc,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAA;IACnD,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAC7B,CAAA;AAED,wBAAgB,oBAAoB,CAAC,EACnC,eAAe,EACf,cAAc,EACd,YAAY,EACZ,kBAAkB,GACnB,EAAE,4BAA4B,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"useOpenAndCloseFocus.d.ts","sourceRoot":"","sources":["../../src/hooks/useOpenAndCloseFocus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAI9B,MAAM,MAAM,4BAA4B,GAAG;IACzC,eAAe,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAA;IACrD,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAA;IACjD,cAAc,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAA;IACnD,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAC7B,CAAA;AAED,wBAAgB,oBAAoB,CAAC,EACnC,eAAe,EACf,cAAc,EACd,YAAY,EACZ,kBAAkB,GACnB,EAAE,4BAA4B,GAAG,IAAI,CAyBrC"}
|
|
@@ -26,7 +26,13 @@ function useOpenAndCloseFocus(t0) {
|
|
|
26
26
|
}
|
|
27
27
|
const returnFocusRefCurrent = returnFocusRef.current;
|
|
28
28
|
return function () {
|
|
29
|
-
|
|
29
|
+
if (returnFocusRefCurrent instanceof HTMLElement) {
|
|
30
|
+
returnFocusRefCurrent.setAttribute("data-restoring-focus", "true");
|
|
31
|
+
returnFocusRefCurrent.focus();
|
|
32
|
+
queueMicrotask(() => {
|
|
33
|
+
returnFocusRefCurrent.removeAttribute("data-restoring-focus");
|
|
34
|
+
});
|
|
35
|
+
}
|
|
30
36
|
};
|
|
31
37
|
};
|
|
32
38
|
t2 = [initialFocusRef, returnFocusRef, containerRef, preventFocusOnOpen];
|
package/package.json
CHANGED