@primer/react 0.0.0-20260424153709 → 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 +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,
|
|
1
|
+
{"version":3,"file":"AnchoredOverlay.d.ts","sourceRoot":"","sources":["../../src/AnchoredOverlay/AnchoredOverlay.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAmC,KAAK,GAAG,EAAC,MAAM,OAAO,CAAA;AAChE,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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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 {
|
|
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,8 +51,10 @@ const AnchoredOverlay = ({
|
|
|
51
51
|
renderAs = 'portal'
|
|
52
52
|
}) => {
|
|
53
53
|
const cssAnchorPositioningFlag = useFeatureFlag('primer_react_css_anchor_positioning');
|
|
54
|
-
|
|
55
|
-
|
|
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;
|
|
56
58
|
// Only use Popover API when both CSS anchor positioning is enabled AND renderAs is true
|
|
57
59
|
const shouldRenderAsPopover = cssAnchorPositioning && renderAs === 'popover';
|
|
58
60
|
const anchorRef = useProvidedRefOrCreate(externalAnchorRef);
|
|
@@ -60,9 +62,13 @@ const AnchoredOverlay = ({
|
|
|
60
62
|
// its identity (e.g. applying `anchor-name` for CSS anchor positioning) re-run
|
|
61
63
|
// when a consumer remounts/replaces the anchor element while keeping the same
|
|
62
64
|
// `anchorRef` object. Refs alone don't notify React when `.current` changes.
|
|
63
|
-
const [anchorElement, setAnchorElement] = useState(
|
|
65
|
+
const [anchorElement, setAnchorElement] = useState(null);
|
|
64
66
|
// Detect when `anchorRef.current` has been mutated by a consumer (e.g. via
|
|
65
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
|
|
66
72
|
if (anchorRef.current !== anchorElement) {
|
|
67
73
|
setAnchorElement(anchorRef.current);
|
|
68
74
|
}
|
|
@@ -79,14 +85,14 @@ const AnchoredOverlay = ({
|
|
|
79
85
|
}
|
|
80
86
|
}
|
|
81
87
|
}, [open, onOpen]);
|
|
82
|
-
const onAnchorClick = useCallback(
|
|
83
|
-
if (
|
|
88
|
+
const onAnchorClick = useCallback(event => {
|
|
89
|
+
if (event.defaultPrevented || event.button !== 0) {
|
|
84
90
|
return;
|
|
85
91
|
}
|
|
86
92
|
// Prevent the browser's native popovertarget toggle so React
|
|
87
93
|
// stays the single source of truth for popover visibility.
|
|
88
94
|
if (cssAnchorPositioning) {
|
|
89
|
-
|
|
95
|
+
event.preventDefault();
|
|
90
96
|
}
|
|
91
97
|
if (!open) {
|
|
92
98
|
onOpen === null || onOpen === void 0 ? void 0 : onOpen('anchor-click');
|
|
@@ -102,7 +108,7 @@ const AnchoredOverlay = ({
|
|
|
102
108
|
}
|
|
103
109
|
};
|
|
104
110
|
const {
|
|
105
|
-
position
|
|
111
|
+
position
|
|
106
112
|
} = useAnchoredPosition({
|
|
107
113
|
anchorElementRef: anchorRef,
|
|
108
114
|
floatingElementRef: overlayRef,
|
|
@@ -113,10 +119,8 @@ const AnchoredOverlay = ({
|
|
|
113
119
|
anchorOffset,
|
|
114
120
|
displayInViewport,
|
|
115
121
|
onPositionChange: positionChange
|
|
116
|
-
}, [
|
|
122
|
+
}, [overlayElement]);
|
|
117
123
|
useEffect(() => {
|
|
118
|
-
supportsNativeCSSAnchorPositioning.current = 'anchorName' in document.documentElement.style;
|
|
119
|
-
|
|
120
124
|
// ensure overlay ref gets cleared when closed, so position can reset between closing/re-opening
|
|
121
125
|
if (!open && overlayRef.current) {
|
|
122
126
|
updateOverlayRef(null);
|
|
@@ -124,12 +128,12 @@ const AnchoredOverlay = ({
|
|
|
124
128
|
}, [open, overlayRef, updateOverlayRef]);
|
|
125
129
|
useFocusZone({
|
|
126
130
|
containerRef: overlayRef,
|
|
127
|
-
disabled: !open || !
|
|
131
|
+
disabled: !open || !position,
|
|
128
132
|
...focusZoneSettings
|
|
129
133
|
});
|
|
130
134
|
useFocusTrap({
|
|
131
135
|
containerRef: overlayRef,
|
|
132
|
-
disabled: !open || !
|
|
136
|
+
disabled: !open || !position,
|
|
133
137
|
...focusTrapSettings
|
|
134
138
|
});
|
|
135
139
|
const popoverId = useId();
|
|
@@ -169,7 +173,9 @@ const AnchoredOverlay = ({
|
|
|
169
173
|
currentOverlay.style.removeProperty('position-anchor');
|
|
170
174
|
}
|
|
171
175
|
};
|
|
172
|
-
|
|
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]);
|
|
173
179
|
const showXIcon = onClose && variant.narrow === 'fullscreen' && displayCloseButton;
|
|
174
180
|
const XButtonAriaLabelledBy = closeButtonProps['aria-labelledby'];
|
|
175
181
|
const XButtonAriaLabel = closeButtonProps['aria-label'];
|
|
@@ -179,7 +185,11 @@ const AnchoredOverlay = ({
|
|
|
179
185
|
...restOverlayProps
|
|
180
186
|
} = overlayProps || {};
|
|
181
187
|
return /*#__PURE__*/jsxs(Fragment, {
|
|
182
|
-
children: [renderAnchor &&
|
|
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.
|
|
191
|
+
// eslint-disable-next-line react-hooks/refs
|
|
192
|
+
renderAnchor({
|
|
183
193
|
ref: anchorRef,
|
|
184
194
|
id: anchorId,
|
|
185
195
|
'aria-haspopup': 'true',
|
|
@@ -196,13 +206,13 @@ const AnchoredOverlay = ({
|
|
|
196
206
|
ignoreClickRefs: [anchorRef],
|
|
197
207
|
onEscape: onEscape,
|
|
198
208
|
role: "none",
|
|
199
|
-
visibility: cssAnchorPositioning ||
|
|
209
|
+
visibility: cssAnchorPositioning || position ? 'visible' : 'hidden',
|
|
200
210
|
height: height,
|
|
201
211
|
width: width,
|
|
202
|
-
top: cssAnchorPositioning ? undefined : (
|
|
203
|
-
left: cssAnchorPositioning ? undefined : (
|
|
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,
|
|
204
214
|
responsiveVariant: variant.narrow === 'fullscreen' ? 'fullscreen' : undefined,
|
|
205
|
-
anchorSide: cssAnchorPositioning ? undefined :
|
|
215
|
+
anchorSide: cssAnchorPositioning ? undefined : position === null || position === void 0 ? void 0 : position.anchorSide,
|
|
206
216
|
className: clsx(className, overlayClassName, cssAnchorPositioning ? classes.AnchoredOverlay : undefined),
|
|
207
217
|
preventOverflow: preventOverflow,
|
|
208
218
|
"data-component": "AnchoredOverlay",
|
|
@@ -222,7 +232,7 @@ const AnchoredOverlay = ({
|
|
|
222
232
|
setOverlayElement(node);
|
|
223
233
|
},
|
|
224
234
|
"data-anchor-position": cssAnchorPositioning,
|
|
225
|
-
"data-side": cssAnchorPositioning ? side :
|
|
235
|
+
"data-side": cssAnchorPositioning ? side : position === null || position === void 0 ? void 0 : position.anchorSide,
|
|
226
236
|
children: [showXIcon ? /*#__PURE__*/jsx("div", {
|
|
227
237
|
className: classes.ResponsiveCloseButtonContainer,
|
|
228
238
|
children: /*#__PURE__*/jsx(IconButton, {
|
package/package.json
CHANGED