@primer/react 0.0.0-20260424155814 → 0.0.0-20260427154406
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-
|
|
3
|
+
## 0.0.0-20260427154406
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
|
|
24
24
|
This enables consumers to query and test components using stable selectors like `[data-component="Table.Row"]`.
|
|
25
25
|
|
|
26
|
-
- [#7766](https://github.com/primer/react/pull/7766) [`
|
|
26
|
+
- [#7766](https://github.com/primer/react/pull/7766) [`b3f06f1`](https://github.com/primer/react/commit/b3f06f1e2c91125c7b6b035bd019f534219d358f) Thanks [@TylerJDev](https://github.com/TylerJDev)! - AnchoredOverlay: (Behind feature flag) Make popover API usage opt-in
|
|
27
27
|
|
|
28
28
|
- [#7763](https://github.com/primer/react/pull/7763) [`b288d6e`](https://github.com/primer/react/commit/b288d6e2dc9d1eef345ef4d16f6b0fba4f165955) Thanks [@liuliu-dev](https://github.com/liuliu-dev)! - Add borderRadius prop to Card component.
|
|
29
29
|
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
|
|
38
38
|
- [#7757](https://github.com/primer/react/pull/7757) [`ed82a1e`](https://github.com/primer/react/commit/ed82a1e0399b98428d4b794239bb37649806b5cc) Thanks [@liuliu-dev](https://github.com/liuliu-dev)! - SelectPanel: Lock body scroll when modal variant is on.
|
|
39
39
|
|
|
40
|
-
- [#
|
|
40
|
+
- [#7780](https://github.com/primer/react/pull/7780) [`b401fb6`](https://github.com/primer/react/commit/b401fb6c20fdd6ca951b32662fd2c45d427d2fcf) Thanks [@francinelucca](https://github.com/francinelucca)! - chore: fixes bug in Checkbox indeterminate state where indeterminate state was being lost on checkbox click if the state didn't change
|
|
41
41
|
|
|
42
42
|
- [#7734](https://github.com/primer/react/pull/7734) [`421ebf0`](https://github.com/primer/react/commit/421ebf0a54558a29f1efbe1850036f80b1bbe126) Thanks [@llastflowers](https://github.com/llastflowers)! - add data-component attributes for Avatar, AvatarStack, Banner, & BaseStyles
|
|
43
43
|
|
|
@@ -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,EAAiC,KAAK,GAAG,EAAC,MAAM,OAAO,CAAA;AAE9D,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;;O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E;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,CA8OnF,CAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useRef, useCallback, useEffect } from 'react';
|
|
2
|
+
import useIsomorphicLayoutEffect from '../utils/useIsomorphicLayoutEffect.js';
|
|
2
3
|
import { useFocusTrap } from '../hooks/useFocusTrap.js';
|
|
3
4
|
import { useFocusZone } from '../hooks/useFocusZone.js';
|
|
4
5
|
import { useId } from '../hooks/useId.js';
|
|
@@ -51,29 +52,13 @@ const AnchoredOverlay = ({
|
|
|
51
52
|
renderAs = 'portal'
|
|
52
53
|
}) => {
|
|
53
54
|
const cssAnchorPositioningFlag = useFeatureFlag('primer_react_css_anchor_positioning');
|
|
54
|
-
|
|
55
|
-
//
|
|
56
|
-
const
|
|
57
|
-
const cssAnchorPositioning = cssAnchorPositioningFlag && supportsNativeCSSAnchorPositioning;
|
|
55
|
+
const supportsNativeCSSAnchorPositioning = useRef(false);
|
|
56
|
+
// eslint-disable-next-line react-hooks/refs
|
|
57
|
+
const cssAnchorPositioning = cssAnchorPositioningFlag && supportsNativeCSSAnchorPositioning.current;
|
|
58
58
|
// Only use Popover API when both CSS anchor positioning is enabled AND renderAs is true
|
|
59
59
|
const shouldRenderAsPopover = cssAnchorPositioning && renderAs === 'popover';
|
|
60
60
|
const anchorRef = useProvidedRefOrCreate(externalAnchorRef);
|
|
61
|
-
// Track the current anchor DOM element in state so that effects depending on
|
|
62
|
-
// its identity (e.g. applying `anchor-name` for CSS anchor positioning) re-run
|
|
63
|
-
// when a consumer remounts/replaces the anchor element while keeping the same
|
|
64
|
-
// `anchorRef` object. Refs alone don't notify React when `.current` changes.
|
|
65
|
-
const [anchorElement, setAnchorElement] = useState(null);
|
|
66
|
-
// Detect when `anchorRef.current` has been mutated by a consumer (e.g. via
|
|
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
|
|
72
|
-
if (anchorRef.current !== anchorElement) {
|
|
73
|
-
setAnchorElement(anchorRef.current);
|
|
74
|
-
}
|
|
75
61
|
const [overlayRef, updateOverlayRef] = useRenderForcingRef();
|
|
76
|
-
const [overlayElement, setOverlayElement] = useState(null);
|
|
77
62
|
const anchorId = useId(externalAnchorId);
|
|
78
63
|
const onClickOutside = useCallback(() => onClose === null || onClose === void 0 ? void 0 : onClose('click-outside'), [onClose]);
|
|
79
64
|
const onEscape = useCallback(() => onClose === null || onClose === void 0 ? void 0 : onClose('escape'), [onClose]);
|
|
@@ -85,14 +70,14 @@ const AnchoredOverlay = ({
|
|
|
85
70
|
}
|
|
86
71
|
}
|
|
87
72
|
}, [open, onOpen]);
|
|
88
|
-
const onAnchorClick = useCallback(
|
|
89
|
-
if (
|
|
73
|
+
const onAnchorClick = useCallback(event_0 => {
|
|
74
|
+
if (event_0.defaultPrevented || event_0.button !== 0) {
|
|
90
75
|
return;
|
|
91
76
|
}
|
|
92
77
|
// Prevent the browser's native popovertarget toggle so React
|
|
93
78
|
// stays the single source of truth for popover visibility.
|
|
94
79
|
if (cssAnchorPositioning) {
|
|
95
|
-
|
|
80
|
+
event_0.preventDefault();
|
|
96
81
|
}
|
|
97
82
|
if (!open) {
|
|
98
83
|
onOpen === null || onOpen === void 0 ? void 0 : onOpen('anchor-click');
|
|
@@ -108,7 +93,7 @@ const AnchoredOverlay = ({
|
|
|
108
93
|
}
|
|
109
94
|
};
|
|
110
95
|
const {
|
|
111
|
-
position
|
|
96
|
+
position: position_0
|
|
112
97
|
} = useAnchoredPosition({
|
|
113
98
|
anchorElementRef: anchorRef,
|
|
114
99
|
floatingElementRef: overlayRef,
|
|
@@ -119,8 +104,12 @@ const AnchoredOverlay = ({
|
|
|
119
104
|
anchorOffset,
|
|
120
105
|
displayInViewport,
|
|
121
106
|
onPositionChange: positionChange
|
|
122
|
-
},
|
|
107
|
+
},
|
|
108
|
+
// eslint-disable-next-line react-hooks/refs
|
|
109
|
+
[overlayRef.current]);
|
|
123
110
|
useEffect(() => {
|
|
111
|
+
supportsNativeCSSAnchorPositioning.current = 'anchorName' in document.documentElement.style;
|
|
112
|
+
|
|
124
113
|
// ensure overlay ref gets cleared when closed, so position can reset between closing/re-opening
|
|
125
114
|
if (!open && overlayRef.current) {
|
|
126
115
|
updateOverlayRef(null);
|
|
@@ -128,25 +117,43 @@ const AnchoredOverlay = ({
|
|
|
128
117
|
}, [open, overlayRef, updateOverlayRef]);
|
|
129
118
|
useFocusZone({
|
|
130
119
|
containerRef: overlayRef,
|
|
131
|
-
disabled: !open || !
|
|
120
|
+
disabled: !open || !position_0,
|
|
132
121
|
...focusZoneSettings
|
|
133
122
|
});
|
|
134
123
|
useFocusTrap({
|
|
135
124
|
containerRef: overlayRef,
|
|
136
|
-
disabled: !open || !
|
|
125
|
+
disabled: !open || !position_0,
|
|
137
126
|
...focusTrapSettings
|
|
138
127
|
});
|
|
139
128
|
const popoverId = useId();
|
|
140
129
|
const id = popoverId.replaceAll(':', '_'); // popoverId can contain colons which are invalid in CSS custom property names, so we replace them with underscores
|
|
141
130
|
|
|
142
131
|
useEffect(() => {
|
|
143
|
-
if (!cssAnchorPositioning || !
|
|
144
|
-
const
|
|
132
|
+
if (!cssAnchorPositioning || !anchorRef.current) return;
|
|
133
|
+
const anchor = anchorRef.current;
|
|
134
|
+
const overlay = overlayRef.current;
|
|
135
|
+
anchor.style.setProperty('anchor-name', `--anchored-overlay-anchor-${id}`);
|
|
136
|
+
return () => {
|
|
137
|
+
anchor.style.removeProperty('anchor-name');
|
|
138
|
+
if (overlay) {
|
|
139
|
+
overlay.style.removeProperty('position-anchor');
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
// eslint-disable-next-line react-hooks/refs
|
|
143
|
+
}, [cssAnchorPositioning, anchorRef, overlayRef, id, open]);
|
|
145
144
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
145
|
+
// Track the overlay element so we can re-run the effect when it changes.
|
|
146
|
+
// The overlay unmounts when closed, so each open creates a new DOM node -
|
|
147
|
+
// that needs showPopover() called.
|
|
148
|
+
// eslint-disable-next-line react-hooks/refs
|
|
149
|
+
const overlayElement = overlayRef.current;
|
|
150
|
+
useIsomorphicLayoutEffect(() => {
|
|
151
|
+
// Read ref inside effect to get the value after child refs are attached
|
|
152
|
+
const currentOverlay = overlayRef.current;
|
|
153
|
+
if (!cssAnchorPositioning || !open || !currentOverlay) return;
|
|
154
|
+
currentOverlay.style.setProperty('position-anchor', `--anchored-overlay-anchor-${id}`);
|
|
155
|
+
const anchorElement = anchorRef.current;
|
|
156
|
+
if (anchorElement) {
|
|
150
157
|
const overlayWidth = width ? parseInt(widthMap[width]) : null;
|
|
151
158
|
const result = getDefaultPosition(anchorElement, overlayWidth);
|
|
152
159
|
currentOverlay.setAttribute('data-align', result.horizontal);
|
|
@@ -154,28 +161,20 @@ const AnchoredOverlay = ({
|
|
|
154
161
|
// Apply offset only when viewport is too narrow
|
|
155
162
|
const offset = result.horizontal === 'left' ? result.leftOffset : result.rightOffset;
|
|
156
163
|
currentOverlay.style.setProperty(`--anchored-overlay-anchor-offset-${result.horizontal}`, `${offset || 0}px`);
|
|
164
|
+
}
|
|
157
165
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
} catch {
|
|
165
|
-
// Ignore if popover is already showing or not supported
|
|
166
|
+
// Only call showPopover when renderAs is enabled
|
|
167
|
+
if (shouldRenderAsPopover) {
|
|
168
|
+
try {
|
|
169
|
+
if (!currentOverlay.matches(':popover-open')) {
|
|
170
|
+
currentOverlay.showPopover();
|
|
166
171
|
}
|
|
172
|
+
} catch {
|
|
173
|
+
// Ignore if popover is already showing or not supported
|
|
167
174
|
}
|
|
168
175
|
}
|
|
169
|
-
|
|
170
|
-
|
|
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.
|
|
172
|
-
if (currentOverlay) {
|
|
173
|
-
currentOverlay.style.removeProperty('position-anchor');
|
|
174
|
-
}
|
|
175
|
-
};
|
|
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]);
|
|
176
|
+
// eslint-disable-next-line react-hooks/refs
|
|
177
|
+
}, [cssAnchorPositioning, shouldRenderAsPopover, open, overlayElement, id, overlayRef, anchorRef, width]);
|
|
179
178
|
const showXIcon = onClose && variant.narrow === 'fullscreen' && displayCloseButton;
|
|
180
179
|
const XButtonAriaLabelledBy = closeButtonProps['aria-labelledby'];
|
|
181
180
|
const XButtonAriaLabel = closeButtonProps['aria-label'];
|
|
@@ -186,8 +185,6 @@ const AnchoredOverlay = ({
|
|
|
186
185
|
} = overlayProps || {};
|
|
187
186
|
return /*#__PURE__*/jsxs(Fragment, {
|
|
188
187
|
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
188
|
// eslint-disable-next-line react-hooks/refs
|
|
192
189
|
renderAnchor({
|
|
193
190
|
ref: anchorRef,
|
|
@@ -206,13 +203,13 @@ const AnchoredOverlay = ({
|
|
|
206
203
|
ignoreClickRefs: [anchorRef],
|
|
207
204
|
onEscape: onEscape,
|
|
208
205
|
role: "none",
|
|
209
|
-
visibility: cssAnchorPositioning ||
|
|
206
|
+
visibility: cssAnchorPositioning || position_0 ? 'visible' : 'hidden',
|
|
210
207
|
height: height,
|
|
211
208
|
width: width,
|
|
212
|
-
top: cssAnchorPositioning ? undefined : (
|
|
213
|
-
left: cssAnchorPositioning ? undefined : (
|
|
209
|
+
top: cssAnchorPositioning ? undefined : (position_0 === null || position_0 === void 0 ? void 0 : position_0.top) || 0,
|
|
210
|
+
left: cssAnchorPositioning ? undefined : (position_0 === null || position_0 === void 0 ? void 0 : position_0.left) || 0,
|
|
214
211
|
responsiveVariant: variant.narrow === 'fullscreen' ? 'fullscreen' : undefined,
|
|
215
|
-
anchorSide: cssAnchorPositioning ? undefined :
|
|
212
|
+
anchorSide: cssAnchorPositioning ? undefined : position_0 === null || position_0 === void 0 ? void 0 : position_0.anchorSide,
|
|
216
213
|
className: clsx(className, overlayClassName, cssAnchorPositioning ? classes.AnchoredOverlay : undefined),
|
|
217
214
|
preventOverflow: preventOverflow,
|
|
218
215
|
"data-component": "AnchoredOverlay",
|
|
@@ -229,10 +226,9 @@ const AnchoredOverlay = ({
|
|
|
229
226
|
assignRef(overlayProps.ref, node);
|
|
230
227
|
}
|
|
231
228
|
updateOverlayRef(node);
|
|
232
|
-
setOverlayElement(node);
|
|
233
229
|
},
|
|
234
230
|
"data-anchor-position": cssAnchorPositioning,
|
|
235
|
-
"data-side": cssAnchorPositioning ? side :
|
|
231
|
+
"data-side": cssAnchorPositioning ? side : position_0 === null || position_0 === void 0 ? void 0 : position_0.anchorSide,
|
|
236
232
|
children: [showXIcon ? /*#__PURE__*/jsx("div", {
|
|
237
233
|
className: classes.ResponsiveCloseButtonContainer,
|
|
238
234
|
children: /*#__PURE__*/jsx(IconButton, {
|
package/package.json
CHANGED