@primer/react 0.0.0-20260701194821 → 0.0.0-20260701221856
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';
|
|
@@ -91,23 +91,22 @@ const Tooltip = /*#__PURE__*/React.forwardRef(({
|
|
|
91
91
|
}, forwardedRef) => {
|
|
92
92
|
const tooltipId = useId(id);
|
|
93
93
|
const child = Children.only(children);
|
|
94
|
-
const
|
|
95
|
-
const
|
|
96
|
-
const triggerRef = React.useRef(null);
|
|
94
|
+
const childRef = child.ref;
|
|
95
|
+
const triggerRef = useRef(null);
|
|
97
96
|
const tooltipElRef = React.useRef(null);
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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;
|
|
103
104
|
}
|
|
104
|
-
}
|
|
105
|
-
const setTriggerRef =
|
|
106
|
-
triggerRef
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const setTriggerFromEvent = event => {
|
|
110
|
-
triggerRef.current = event.currentTarget;
|
|
105
|
+
};
|
|
106
|
+
const setTriggerRef = node => {
|
|
107
|
+
assignRef(triggerRef, node);
|
|
108
|
+
assignRef(childRef, node);
|
|
109
|
+
assignRef(forwardedRef, node);
|
|
111
110
|
};
|
|
112
111
|
const [calculatedDirection, setCalculatedDirection] = useState(direction);
|
|
113
112
|
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
|
|
@@ -221,11 +220,8 @@ const Tooltip = /*#__PURE__*/React.forwardRef(({
|
|
|
221
220
|
value: value,
|
|
222
221
|
children: /*#__PURE__*/jsxs(Fragment, {
|
|
223
222
|
children: [/*#__PURE__*/React.isValidElement(child) && /*#__PURE__*/React.cloneElement(child, {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
}),
|
|
227
|
-
// Preserve an existing child ref and track the trigger from events instead of
|
|
228
|
-
// 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
|
|
229
225
|
'aria-describedby': (() => {
|
|
230
226
|
// If tooltip is not a description type, keep the original aria-describedby
|
|
231
227
|
if (type !== 'description') {
|
|
@@ -245,13 +241,11 @@ const Tooltip = /*#__PURE__*/React.forwardRef(({
|
|
|
245
241
|
'aria-labelledby': type === 'label' ? tooltipId : child.props['aria-labelledby'],
|
|
246
242
|
onBlur: event => {
|
|
247
243
|
var _child$props$onBlur, _child$props;
|
|
248
|
-
setTriggerFromEvent(event);
|
|
249
244
|
closeTooltip();
|
|
250
245
|
(_child$props$onBlur = (_child$props = child.props).onBlur) === null || _child$props$onBlur === void 0 ? void 0 : _child$props$onBlur.call(_child$props, event);
|
|
251
246
|
},
|
|
252
247
|
onTouchEnd: event => {
|
|
253
248
|
var _child$props$onTouchE, _child$props2;
|
|
254
|
-
setTriggerFromEvent(event);
|
|
255
249
|
(_child$props$onTouchE = (_child$props2 = child.props).onTouchEnd) === null || _child$props$onTouchE === void 0 ? void 0 : _child$props$onTouchE.call(_child$props2, event);
|
|
256
250
|
|
|
257
251
|
// Hide tooltips on tap to essentially disable them on touch devices;
|
|
@@ -260,20 +254,16 @@ const Tooltip = /*#__PURE__*/React.forwardRef(({
|
|
|
260
254
|
},
|
|
261
255
|
onFocus: event => {
|
|
262
256
|
var _child$props$onFocus, _child$props3;
|
|
263
|
-
setTriggerFromEvent(event);
|
|
264
|
-
|
|
265
|
-
// only show tooltip on :focus-visible, not on :focus
|
|
266
257
|
try {
|
|
267
258
|
if (!event.target.matches(':focus-visible')) return;
|
|
268
|
-
} catch
|
|
269
|
-
//
|
|
270
|
-
// https://github.com/jsdom/jsdom/issues/3426
|
|
259
|
+
} catch {
|
|
260
|
+
// Some test environments do not support `:focus-visible`.
|
|
271
261
|
}
|
|
262
|
+
if (event.currentTarget.hasAttribute('data-restoring-focus')) return;
|
|
272
263
|
openTooltip();
|
|
273
264
|
(_child$props$onFocus = (_child$props3 = child.props).onFocus) === null || _child$props$onFocus === void 0 ? void 0 : _child$props$onFocus.call(_child$props3, event);
|
|
274
265
|
},
|
|
275
266
|
onMouseOverCapture: event => {
|
|
276
|
-
setTriggerFromEvent(event);
|
|
277
267
|
const delayTime = delayTimeMap[delay] || 50;
|
|
278
268
|
// We use a `capture` event to ensure this is called first before
|
|
279
269
|
// events that might cancel the opening timeout (like `onTouchEnd`)
|
|
@@ -289,7 +279,6 @@ const Tooltip = /*#__PURE__*/React.forwardRef(({
|
|
|
289
279
|
},
|
|
290
280
|
onMouseLeave: event => {
|
|
291
281
|
var _child$props$onMouseL, _child$props5;
|
|
292
|
-
setTriggerFromEvent(event);
|
|
293
282
|
closeTooltip();
|
|
294
283
|
(_child$props$onMouseL = (_child$props5 = child.props).onMouseLeave) === null || _child$props$onMouseL === void 0 ? void 0 : _child$props$onMouseL.call(_child$props5, event);
|
|
295
284
|
}
|
|
@@ -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