@primer/react 0.0.0-20260423154134 → 0.0.0-20260423210448
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-20260423210448
|
|
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) [`6770095`](https://github.com/primer/react/commit/67700952bec8373c01843b88e39ccb6dfe5b108c) 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
|
|
|
@@ -31,8 +31,6 @@
|
|
|
31
31
|
|
|
32
32
|
- [#7714](https://github.com/primer/react/pull/7714) [`e974d9f`](https://github.com/primer/react/commit/e974d9f6d156805dbda9639a3fe6091a02a1a754) Thanks [@hectahertz](https://github.com/hectahertz)! - perf(ActionList): replace :has() selector with JS-computed attribute
|
|
33
33
|
|
|
34
|
-
- [#7770](https://github.com/primer/react/pull/7770) [`5436499`](https://github.com/primer/react/commit/54364991c437a2d4092b8847f5544634cb79b7aa) Thanks [@LisaKr](https://github.com/LisaKr)! - Defer `useAnchoredPosition` initial mount setState from useLayoutEffect to useEffect when overlay is closed, eliminating unnecessary cascading re-renders that block paint.
|
|
35
|
-
|
|
36
34
|
- [#7754](https://github.com/primer/react/pull/7754) [`9e3fe4b`](https://github.com/primer/react/commit/9e3fe4b501ce5affb558bf92697e5c79341903ca) Thanks [@liuliu-dev](https://github.com/liuliu-dev)! - Breadcrumbs: On narrow viewports, only show the current page breadcrumb and the overflow menu when `overflow="menu"` is set.
|
|
37
35
|
|
|
38
36
|
- Fake entry to force publishing
|
|
@@ -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,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,CA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B,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,CAgPnF,CAAA"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { useRef, useCallback, useEffect } from 'react';
|
|
2
|
-
import useIsomorphicLayoutEffect from '../utils/useIsomorphicLayoutEffect.js';
|
|
1
|
+
import { useRef, useState, useCallback, useEffect } from 'react';
|
|
3
2
|
import { useFocusTrap } from '../hooks/useFocusTrap.js';
|
|
4
3
|
import { useFocusZone } from '../hooks/useFocusZone.js';
|
|
5
4
|
import { useId } from '../hooks/useId.js';
|
|
@@ -58,6 +57,16 @@ const AnchoredOverlay = ({
|
|
|
58
57
|
// Only use Popover API when both CSS anchor positioning is enabled AND renderAs is true
|
|
59
58
|
const shouldRenderAsPopover = cssAnchorPositioning && renderAs === 'popover';
|
|
60
59
|
const anchorRef = useProvidedRefOrCreate(externalAnchorRef);
|
|
60
|
+
// Track the current anchor DOM element in state so that effects depending on
|
|
61
|
+
// its identity (e.g. applying `anchor-name` for CSS anchor positioning) re-run
|
|
62
|
+
// when a consumer remounts/replaces the anchor element while keeping the same
|
|
63
|
+
// `anchorRef` object. Refs alone don't notify React when `.current` changes.
|
|
64
|
+
const [anchorElement, setAnchorElement] = useState(anchorRef.current);
|
|
65
|
+
// Detect when `anchorRef.current` has been mutated by a consumer (e.g. via
|
|
66
|
+
// their own `ref={anchorRef}`) without React's ref system notifying us.
|
|
67
|
+
if (anchorRef.current !== anchorElement) {
|
|
68
|
+
setAnchorElement(anchorRef.current);
|
|
69
|
+
}
|
|
61
70
|
const [overlayRef, updateOverlayRef] = useRenderForcingRef();
|
|
62
71
|
const anchorId = useId(externalAnchorId);
|
|
63
72
|
const onClickOutside = useCallback(() => onClose === null || onClose === void 0 ? void 0 : onClose('click-outside'), [onClose]);
|
|
@@ -128,32 +137,19 @@ const AnchoredOverlay = ({
|
|
|
128
137
|
const popoverId = useId();
|
|
129
138
|
const id = popoverId.replaceAll(':', '_'); // popoverId can contain colons which are invalid in CSS custom property names, so we replace them with underscores
|
|
130
139
|
|
|
131
|
-
useEffect(() => {
|
|
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]);
|
|
144
|
-
|
|
145
140
|
// Track the overlay element so we can re-run the effect when it changes.
|
|
146
141
|
// The overlay unmounts when closed, so each open creates a new DOM node -
|
|
147
142
|
// that needs showPopover() called.
|
|
148
143
|
// eslint-disable-next-line react-hooks/refs
|
|
149
144
|
const overlayElement = overlayRef.current;
|
|
150
|
-
|
|
151
|
-
|
|
145
|
+
useEffect(() => {
|
|
146
|
+
if (!cssAnchorPositioning || !anchorElement) return;
|
|
152
147
|
const currentOverlay = overlayRef.current;
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
if (
|
|
148
|
+
|
|
149
|
+
// Link the anchor and the overlay (when present) via CSS anchor positioning.
|
|
150
|
+
anchorElement.style.setProperty('anchor-name', `--anchored-overlay-anchor-${id}`);
|
|
151
|
+
if (open && currentOverlay) {
|
|
152
|
+
currentOverlay.style.setProperty('position-anchor', `--anchored-overlay-anchor-${id}`);
|
|
157
153
|
const overlayWidth = width ? parseInt(widthMap[width]) : null;
|
|
158
154
|
const result = getDefaultPosition(anchorElement, overlayWidth);
|
|
159
155
|
currentOverlay.setAttribute('data-align', result.horizontal);
|
|
@@ -161,20 +157,25 @@ const AnchoredOverlay = ({
|
|
|
161
157
|
// Apply offset only when viewport is too narrow
|
|
162
158
|
const offset = result.horizontal === 'left' ? result.leftOffset : result.rightOffset;
|
|
163
159
|
currentOverlay.style.setProperty(`--anchored-overlay-anchor-offset-${result.horizontal}`, `${offset || 0}px`);
|
|
164
|
-
}
|
|
165
160
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
161
|
+
// Only call showPopover when shouldRenderAsPopover is enabled
|
|
162
|
+
if (shouldRenderAsPopover) {
|
|
163
|
+
try {
|
|
164
|
+
if (!currentOverlay.matches(':popover-open')) {
|
|
165
|
+
currentOverlay.showPopover();
|
|
166
|
+
}
|
|
167
|
+
} catch {
|
|
168
|
+
// Ignore if popover is already showing or not supported
|
|
171
169
|
}
|
|
172
|
-
} catch {
|
|
173
|
-
// Ignore if popover is already showing or not supported
|
|
174
170
|
}
|
|
175
171
|
}
|
|
176
|
-
|
|
177
|
-
|
|
172
|
+
return () => {
|
|
173
|
+
anchorElement.style.removeProperty('anchor-name');
|
|
174
|
+
if (currentOverlay) {
|
|
175
|
+
currentOverlay.style.removeProperty('position-anchor');
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
}, [cssAnchorPositioning, shouldRenderAsPopover, open, anchorElement, overlayElement, overlayRef, id, width]);
|
|
178
179
|
const showXIcon = onClose && variant.narrow === 'fullscreen' && displayCloseButton;
|
|
179
180
|
const XButtonAriaLabelledBy = closeButtonProps['aria-labelledby'];
|
|
180
181
|
const XButtonAriaLabel = closeButtonProps['aria-label'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAnchoredPosition.d.ts","sourceRoot":"","sources":["../../src/hooks/useAnchoredPosition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAC,cAAc,EAAE,gBAAgB,EAAC,MAAM,mBAAmB,CAAA;AA0BvE,MAAM,WAAW,4BAA6B,SAAQ,OAAO,CAAC,gBAAgB,CAAC;IAC7E,kBAAkB,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC,CAAA;IACpD,gBAAgB,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC,CAAA;IAClD,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,cAAc,GAAG,SAAS,KAAK,IAAI,CAAA;CAClE;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,CAAC,EAAE,4BAA4B,EACvC,YAAY,GAAE,KAAK,CAAC,cAAmB,GACtC;IACD,kBAAkB,EAAE,KAAK,CAAC,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC,CAAA;IACnD,gBAAgB,EAAE,KAAK,CAAC,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC,CAAA;IACjD,QAAQ,EAAE,cAAc,GAAG,SAAS,CAAA;CACrC,
|
|
1
|
+
{"version":3,"file":"useAnchoredPosition.d.ts","sourceRoot":"","sources":["../../src/hooks/useAnchoredPosition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAC,cAAc,EAAE,gBAAgB,EAAC,MAAM,mBAAmB,CAAA;AA0BvE,MAAM,WAAW,4BAA6B,SAAQ,OAAO,CAAC,gBAAgB,CAAC;IAC7E,kBAAkB,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC,CAAA;IACpD,gBAAgB,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC,CAAA;IAClD,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,cAAc,GAAG,SAAS,KAAK,IAAI,CAAA;CAClE;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,CAAC,EAAE,4BAA4B,EACvC,YAAY,GAAE,KAAK,CAAC,cAAmB,GACtC;IACD,kBAAkB,EAAE,KAAK,CAAC,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC,CAAA;IACnD,gBAAgB,EAAE,KAAK,CAAC,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC,CAAA;IACjD,QAAQ,EAAE,cAAc,GAAG,SAAS,CAAA;CACrC,CA4GA"}
|
|
@@ -92,25 +92,7 @@ function useAnchoredPosition(settings, dependencies = []) {
|
|
|
92
92
|
useIsomorphicLayoutEffect(() => {
|
|
93
93
|
savedOnPositionChange.current = settings === null || settings === void 0 ? void 0 : settings.onPositionChange;
|
|
94
94
|
}, [settings === null || settings === void 0 ? void 0 : settings.onPositionChange]);
|
|
95
|
-
|
|
96
|
-
// Defer the first updatePosition to useEffect when the overlay is closed on
|
|
97
|
-
// mount, avoiding paint-blocking cascading setState. If the overlay is already
|
|
98
|
-
// open on mount, run synchronously in useLayoutEffect to prevent a flash.
|
|
99
|
-
// After mount (including Suspense reappear), only call updatePosition when
|
|
100
|
-
// both refs are attached — skipping closed overlays avoids unnecessary setState.
|
|
101
|
-
const hasMountedRef = React.useRef(false);
|
|
102
|
-
useIsomorphicLayoutEffect(() => {
|
|
103
|
-
if (floatingElementRef.current instanceof Element && anchorElementRef.current instanceof Element) {
|
|
104
|
-
hasMountedRef.current = true;
|
|
105
|
-
updatePosition();
|
|
106
|
-
}
|
|
107
|
-
}, [updatePosition, floatingElementRef, anchorElementRef]);
|
|
108
|
-
React.useEffect(() => {
|
|
109
|
-
if (!hasMountedRef.current) {
|
|
110
|
-
hasMountedRef.current = true;
|
|
111
|
-
updatePosition();
|
|
112
|
-
}
|
|
113
|
-
}, [updatePosition]);
|
|
95
|
+
useIsomorphicLayoutEffect(updatePosition, [updatePosition]);
|
|
114
96
|
useResizeObserver(updatePosition); // watches for changes in window size
|
|
115
97
|
useResizeObserver(updatePosition, floatingElementRef); // watches for changes in floating element size
|
|
116
98
|
|
package/package.json
CHANGED