@primer/react 38.19.0-rc.88f2cf699 → 38.19.0-rc.9a5df56a0

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
@@ -4,12 +4,12 @@
4
4
 
5
5
  ### Minor Changes
6
6
 
7
- - [#7686](https://github.com/primer/react/pull/7686) [`6cd13c0`](https://github.com/primer/react/commit/6cd13c03a0293732af6d9499f1f925bf7d95d82b) Thanks [@JelloBagel](https://github.com/JelloBagel)! - StateLabel: Add new type: `archived`
8
-
9
7
  - [#7677](https://github.com/primer/react/pull/7677) [`c1a81b1`](https://github.com/primer/react/commit/c1a81b178742ba547b85a3df3ed3c27bcff6b7c5) Thanks [@TylerJDev](https://github.com/TylerJDev)! - AnchoredOverlay: Add Popover API to AnchoredOverlay (behind `primer_react_css_anchor_positioning` feature flag)
10
8
 
11
9
  ### Patch Changes
12
10
 
11
+ - [#7652](https://github.com/primer/react/pull/7652) [`5d19e2b`](https://github.com/primer/react/commit/5d19e2bb5bbd444f2e82d98eef300c221863941c) Thanks [@owenniblock](https://github.com/owenniblock)! - useAnchoredPosition: recalculate overlay position when any scrollable ancestor (or the window) is scrolled.
12
+
13
13
  - [#7638](https://github.com/primer/react/pull/7638) [`f04e85d`](https://github.com/primer/react/commit/f04e85df536cd6e8047f70b070bd3cf7c0961f92) Thanks [@iansan5653](https://github.com/iansan5653)! - Update internal implementations of combined refs to improve performance and add support for React 19 callback refs
14
14
 
15
15
  - [#7695](https://github.com/primer/react/pull/7695) [`780fc3d`](https://github.com/primer/react/commit/780fc3d7b52fd0f9b63f313af6355398180a0118) Thanks [@mattcosta7](https://github.com/mattcosta7)! - perf(ThemeProvider): Reduce unnecessary renders and effect cascades
@@ -1 +1 @@
1
- {"version":3,"file":"useAnchoredPosition.d.ts","sourceRoot":"","sources":["../../src/hooks/useAnchoredPosition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAE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,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"}
@@ -4,6 +4,26 @@ import { useProvidedRefOrCreate } from './useProvidedRefOrCreate.js';
4
4
  import { useResizeObserver } from './useResizeObserver.js';
5
5
  import useIsomorphicLayoutEffect from '../utils/useIsomorphicLayoutEffect.js';
6
6
 
7
+ /**
8
+ * Returns all scrollable ancestor elements of the given element, plus the window.
9
+ * An element is scrollable if its computed overflow/overflow-x/overflow-y is
10
+ * 'auto', 'scroll', or 'overlay'.
11
+ */
12
+ function getScrollableAncestors(element) {
13
+ const scrollables = [];
14
+ let current = element.parentElement;
15
+ while (current) {
16
+ const style = getComputedStyle(current);
17
+ const overflowY = style.overflowY;
18
+ const overflowX = style.overflowX;
19
+ if (/auto|scroll|overlay/.test(overflowY) || /auto|scroll|overlay/.test(overflowX)) {
20
+ scrollables.push(current);
21
+ }
22
+ current = current.parentElement;
23
+ }
24
+ scrollables.push(window);
25
+ return scrollables;
26
+ }
7
27
  /**
8
28
  * Calculates the top and left values for an absolutely-positioned floating element
9
29
  * to be anchored to some anchor element. Returns refs for the floating element
@@ -76,6 +96,33 @@ function useAnchoredPosition(settings, dependencies = []) {
76
96
  useResizeObserver(updatePosition); // watches for changes in window size
77
97
  useResizeObserver(updatePosition, floatingElementRef); // watches for changes in floating element size
78
98
 
99
+ // Recalculate position when any scrollable ancestor of the anchor scrolls.
100
+ // Uses requestAnimationFrame to avoid layout thrashing during scroll.
101
+ React.useEffect(() => {
102
+ const anchorEl = anchorElementRef.current;
103
+ if (!anchorEl) return;
104
+ let rafId = null;
105
+ const handleScroll = () => {
106
+ if (rafId !== null) return;
107
+ rafId = requestAnimationFrame(() => {
108
+ rafId = null;
109
+ updatePosition();
110
+ });
111
+ };
112
+ const scrollables = getScrollableAncestors(anchorEl);
113
+ for (const scrollable of scrollables) {
114
+ // eslint-disable-next-line github/prefer-observers -- IntersectionObserver cannot detect continuous scroll position changes needed for repositioning
115
+ scrollable.addEventListener('scroll', handleScroll);
116
+ }
117
+ return () => {
118
+ for (const scrollable of scrollables) {
119
+ scrollable.removeEventListener('scroll', handleScroll);
120
+ }
121
+ if (rafId !== null) {
122
+ cancelAnimationFrame(rafId);
123
+ }
124
+ };
125
+ }, [anchorElementRef, updatePosition]);
79
126
  return {
80
127
  floatingElementRef,
81
128
  anchorElementRef,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@primer/react",
3
3
  "type": "module",
4
- "version": "38.19.0-rc.88f2cf699",
4
+ "version": "38.19.0-rc.9a5df56a0",
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",