@primer/react 0.0.0-20260701194821 → 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,6 +1,6 @@
1
1
  # @primer/react
2
2
 
3
- ## 0.0.0-20260701194821
3
+ ## 0.0.0-20260701220623
4
4
 
5
5
  ### Patch Changes
6
6
 
@@ -1 +1 @@
1
- {"version":3,"file":"Tooltip.d.ts","sourceRoot":"","sources":["../../src/TooltipV2/Tooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAyC,KAAK,yBAAyB,EAAC,MAAM,OAAO,CAAA;AASnG,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,UAkUD,CAAA"}
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 childProps = child.props;
95
- const childRef = childProps.ref;
96
- const triggerRef = React.useRef(null);
94
+ const childRef = child.ref;
95
+ const triggerRef = useRef(null);
97
96
  const tooltipElRef = React.useRef(null);
98
- const setForwardedRef = React.useCallback(node => {
99
- if (typeof forwardedRef === 'function') {
100
- forwardedRef(node);
101
- } else if (forwardedRef) {
102
- forwardedRef.current = node;
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
- }, [forwardedRef]);
105
- const setTriggerRef = React.useCallback(node => {
106
- triggerRef.current = node;
107
- setForwardedRef(node);
108
- }, [setForwardedRef]);
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
- ...(childRef ? {} : {
225
- ref: setTriggerRef
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,14 @@ 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 (_error) {
269
- // jsdom (jest) does not support `:focus-visible` yet and would throw an error
270
- // https://github.com/jsdom/jsdom/issues/3426
271
- }
259
+ } catch (_error) {}
260
+ if (event.currentTarget.hasAttribute('data-restoring-focus')) return;
272
261
  openTooltip();
273
262
  (_child$props$onFocus = (_child$props3 = child.props).onFocus) === null || _child$props$onFocus === void 0 ? void 0 : _child$props$onFocus.call(_child$props3, event);
274
263
  },
275
264
  onMouseOverCapture: event => {
276
- setTriggerFromEvent(event);
277
265
  const delayTime = delayTimeMap[delay] || 50;
278
266
  // We use a `capture` event to ensure this is called first before
279
267
  // events that might cancel the opening timeout (like `onTouchEnd`)
@@ -289,7 +277,6 @@ const Tooltip = /*#__PURE__*/React.forwardRef(({
289
277
  },
290
278
  onMouseLeave: event => {
291
279
  var _child$props$onMouseL, _child$props5;
292
- setTriggerFromEvent(event);
293
280
  closeTooltip();
294
281
  (_child$props$onMouseL = (_child$props5 = child.props).onMouseLeave) === null || _child$props$onMouseL === void 0 ? void 0 : _child$props$onMouseL.call(_child$props5, event);
295
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,CAmBrC"}
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
- returnFocusRefCurrent === null || returnFocusRefCurrent === void 0 ? void 0 : returnFocusRefCurrent.focus();
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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@primer/react",
3
3
  "type": "module",
4
- "version": "0.0.0-20260701194821",
4
+ "version": "0.0.0-20260701220623",
5
5
  "description": "An implementation of GitHub's Primer Design System using React",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",