@primer/react 0.0.0-20260424151836 → 0.0.0-20260424155814

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-20260424151836
3
+ ## 0.0.0-20260424155814
4
4
 
5
5
  ### Minor Changes
6
6
 
@@ -1 +1 @@
1
- {"version":3,"file":"AnchoredOverlay.d.ts","sourceRoot":"","sources":["../../src/AnchoredOverlay/AnchoredOverlay.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAA2C,KAAK,GAAG,EAAC,MAAM,OAAO,CAAA;AACxE,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,YAAY,CAAA;AAE5C,OAAO,KAAK,EAAC,qBAAqB,EAAC,MAAM,uBAAuB,CAAA;AAEhE,OAAO,KAAK,EAAC,qBAAqB,EAAC,MAAM,uBAAuB,CAAA;AAIhE,OAAO,KAAK,EAAC,cAAc,EAAE,gBAAgB,EAAC,MAAM,mBAAmB,CAAA;AACvE,OAAO,EAAC,KAAK,eAAe,EAAC,MAAM,6BAA6B,CAAA;AAChE,OAAO,EAAa,KAAK,eAAe,EAAC,MAAM,WAAW,CAAA;AAO1D,UAAU,8BAA8B;IACtC;;;OAGG;IACH,YAAY,EAAE,CAAC,CAAC,SAAS,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC,EAAE,YAAY,GAAG,iBAAiB,CAAC,EAChG,KAAK,EAAE,CAAC,KACL,GAAG,CAAC,OAAO,CAAA;IAEhB;;OAEG;IACH,SAAS,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAA;IAE/C;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,UAAU,iCAAiC;IACzC;;;OAGG;IACH,YAAY,EAAE,IA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U,EAAE,UAAU,GAAG,YAAY,CAAC,CAAA;IAChE;;OAEG;IACH,gBAAgB,CAAC,EAAE,CAAC,EAAC,QAAQ,EAAC,EAAE;QAAC,QAAQ,EAAE,cAAc,CAAA;KAAC,KAAK,IAAI,CAAA;IACnE;;OAEG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B;;OAEG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,CAAA;IAC3C;;;OAGG;IACH,QAAQ,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAA;CAChC;AAED,MAAM,MAAM,oBAAoB,GAAG,wBAAwB,GACzD,CAAC,8BAA8B,GAAG,iCAAiC,CAAC,GACpE,OAAO,CAAC,IAAI,CAAC,gBAAgB,EAAE,OAAO,GAAG,MAAM,GAAG,cAAc,GAAG,iBAAiB,GAAG,mBAAmB,CAAC,CAAC,CAAA;AAS9G;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,iBAAiB,CAAC,oBAAoB,CAAC,CAuPnF,CAAA"}
@@ -1,4 +1,4 @@
1
- import { useRef, useState, useCallback, useEffect } from 'react';
1
+ import { useState, useCallback, useEffect } from 'react';
2
2
  import { useFocusTrap } from '../hooks/useFocusTrap.js';
3
3
  import { useFocusZone } from '../hooks/useFocusZone.js';
4
4
  import { useId } from '../hooks/useId.js';
@@ -51,9 +51,10 @@ const AnchoredOverlay = ({
51
51
  renderAs = 'portal'
52
52
  }) => {
53
53
  const cssAnchorPositioningFlag = useFeatureFlag('primer_react_css_anchor_positioning');
54
- const supportsNativeCSSAnchorPositioning = useRef(false);
55
- // eslint-disable-next-line react-hooks/refs
56
- const cssAnchorPositioning = cssAnchorPositioningFlag && supportsNativeCSSAnchorPositioning.current;
54
+ // Lazy initial state so feature detection runs once per mount on the client.
55
+ // Guarded for SSR where `document` is undefined.
56
+ const [supportsNativeCSSAnchorPositioning] = useState(() => typeof document !== 'undefined' && 'anchorName' in document.documentElement.style);
57
+ const cssAnchorPositioning = cssAnchorPositioningFlag && supportsNativeCSSAnchorPositioning;
57
58
  // Only use Popover API when both CSS anchor positioning is enabled AND renderAs is true
58
59
  const shouldRenderAsPopover = cssAnchorPositioning && renderAs === 'popover';
59
60
  const anchorRef = useProvidedRefOrCreate(externalAnchorRef);
@@ -61,9 +62,13 @@ const AnchoredOverlay = ({
61
62
  // its identity (e.g. applying `anchor-name` for CSS anchor positioning) re-run
62
63
  // when a consumer remounts/replaces the anchor element while keeping the same
63
64
  // `anchorRef` object. Refs alone don't notify React when `.current` changes.
64
- const [anchorElement, setAnchorElement] = useState(anchorRef.current);
65
+ const [anchorElement, setAnchorElement] = useState(null);
65
66
  // Detect when `anchorRef.current` has been mutated by a consumer (e.g. via
66
67
  // their own `ref={anchorRef}`) without React's ref system notifying us.
68
+ // Reading the ref during render and conditionally calling setState is the
69
+ // documented React pattern for syncing external mutable state, but the
70
+ // react-hooks/refs lint rule is conservative and disallows it.
71
+ // eslint-disable-next-line react-hooks/refs
67
72
  if (anchorRef.current !== anchorElement) {
68
73
  setAnchorElement(anchorRef.current);
69
74
  }
@@ -80,14 +85,14 @@ const AnchoredOverlay = ({
80
85
  }
81
86
  }
82
87
  }, [open, onOpen]);
83
- const onAnchorClick = useCallback(event_0 => {
84
- if (event_0.defaultPrevented || event_0.button !== 0) {
88
+ const onAnchorClick = useCallback(event => {
89
+ if (event.defaultPrevented || event.button !== 0) {
85
90
  return;
86
91
  }
87
92
  // Prevent the browser's native popovertarget toggle so React
88
93
  // stays the single source of truth for popover visibility.
89
94
  if (cssAnchorPositioning) {
90
- event_0.preventDefault();
95
+ event.preventDefault();
91
96
  }
92
97
  if (!open) {
93
98
  onOpen === null || onOpen === void 0 ? void 0 : onOpen('anchor-click');
@@ -103,7 +108,7 @@ const AnchoredOverlay = ({
103
108
  }
104
109
  };
105
110
  const {
106
- position: position_0
111
+ position
107
112
  } = useAnchoredPosition({
108
113
  anchorElementRef: anchorRef,
109
114
  floatingElementRef: overlayRef,
@@ -114,12 +119,8 @@ const AnchoredOverlay = ({
114
119
  anchorOffset,
115
120
  displayInViewport,
116
121
  onPositionChange: positionChange
117
- },
118
- // eslint-disable-next-line react-hooks/refs
119
- [overlayRef.current]);
122
+ }, [overlayElement]);
120
123
  useEffect(() => {
121
- supportsNativeCSSAnchorPositioning.current = 'anchorName' in document.documentElement.style;
122
-
123
124
  // ensure overlay ref gets cleared when closed, so position can reset between closing/re-opening
124
125
  if (!open && overlayRef.current) {
125
126
  updateOverlayRef(null);
@@ -127,12 +128,12 @@ const AnchoredOverlay = ({
127
128
  }, [open, overlayRef, updateOverlayRef]);
128
129
  useFocusZone({
129
130
  containerRef: overlayRef,
130
- disabled: !open || !position_0,
131
+ disabled: !open || !position,
131
132
  ...focusZoneSettings
132
133
  });
133
134
  useFocusTrap({
134
135
  containerRef: overlayRef,
135
- disabled: !open || !position_0,
136
+ disabled: !open || !position,
136
137
  ...focusTrapSettings
137
138
  });
138
139
  const popoverId = useId();
@@ -167,11 +168,14 @@ const AnchoredOverlay = ({
167
168
  }
168
169
  return () => {
169
170
  anchorElement.style.removeProperty('anchor-name');
171
+ // The overlay may no longer be in the DOM at this point, so we need to check for its presence before trying to update it.
170
172
  if (currentOverlay) {
171
173
  currentOverlay.style.removeProperty('position-anchor');
172
174
  }
173
175
  };
174
- }, [cssAnchorPositioning, shouldRenderAsPopover, open, anchorElement, overlayElement, overlayRef, id, width]);
176
+ // overlayRef is a stable ref object; including it in deps is unnecessary.
177
+ // eslint-disable-next-line react-hooks/exhaustive-deps
178
+ }, [cssAnchorPositioning, shouldRenderAsPopover, open, anchorElement, overlayElement, id, width]);
175
179
  const showXIcon = onClose && variant.narrow === 'fullscreen' && displayCloseButton;
176
180
  const XButtonAriaLabelledBy = closeButtonProps['aria-labelledby'];
177
181
  const XButtonAriaLabel = closeButtonProps['aria-label'];
@@ -182,6 +186,8 @@ const AnchoredOverlay = ({
182
186
  } = overlayProps || {};
183
187
  return /*#__PURE__*/jsxs(Fragment, {
184
188
  children: [renderAnchor &&
189
+ // anchorRef is a ref object passed as a JSX `ref` prop on the rendered
190
+ // anchor; React writes to it at commit time, it is not read during render.
185
191
  // eslint-disable-next-line react-hooks/refs
186
192
  renderAnchor({
187
193
  ref: anchorRef,
@@ -200,13 +206,13 @@ const AnchoredOverlay = ({
200
206
  ignoreClickRefs: [anchorRef],
201
207
  onEscape: onEscape,
202
208
  role: "none",
203
- visibility: cssAnchorPositioning || position_0 ? 'visible' : 'hidden',
209
+ visibility: cssAnchorPositioning || position ? 'visible' : 'hidden',
204
210
  height: height,
205
211
  width: width,
206
- top: cssAnchorPositioning ? undefined : (position_0 === null || position_0 === void 0 ? void 0 : position_0.top) || 0,
207
- left: cssAnchorPositioning ? undefined : (position_0 === null || position_0 === void 0 ? void 0 : position_0.left) || 0,
212
+ top: cssAnchorPositioning ? undefined : (position === null || position === void 0 ? void 0 : position.top) || 0,
213
+ left: cssAnchorPositioning ? undefined : (position === null || position === void 0 ? void 0 : position.left) || 0,
208
214
  responsiveVariant: variant.narrow === 'fullscreen' ? 'fullscreen' : undefined,
209
- anchorSide: cssAnchorPositioning ? undefined : position_0 === null || position_0 === void 0 ? void 0 : position_0.anchorSide,
215
+ anchorSide: cssAnchorPositioning ? undefined : position === null || position === void 0 ? void 0 : position.anchorSide,
210
216
  className: clsx(className, overlayClassName, cssAnchorPositioning ? classes.AnchoredOverlay : undefined),
211
217
  preventOverflow: preventOverflow,
212
218
  "data-component": "AnchoredOverlay",
@@ -226,7 +232,7 @@ const AnchoredOverlay = ({
226
232
  setOverlayElement(node);
227
233
  },
228
234
  "data-anchor-position": cssAnchorPositioning,
229
- "data-side": cssAnchorPositioning ? side : position_0 === null || position_0 === void 0 ? void 0 : position_0.anchorSide,
235
+ "data-side": cssAnchorPositioning ? side : position === null || position === void 0 ? void 0 : position.anchorSide,
230
236
  children: [showXIcon ? /*#__PURE__*/jsx("div", {
231
237
  className: classes.ResponsiveCloseButtonContainer,
232
238
  children: /*#__PURE__*/jsx(IconButton, {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@primer/react",
3
3
  "type": "module",
4
- "version": "0.0.0-20260424151836",
4
+ "version": "0.0.0-20260424155814",
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",