@primer/react 0.0.0-20260330123531 → 0.0.0-20260330144944

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-20260330123531
3
+ ## 0.0.0-20260330144944
4
4
 
5
5
  ### Minor Changes
6
6
 
@@ -12,6 +12,8 @@
12
12
 
13
13
  ### Patch Changes
14
14
 
15
+ - [#7652](https://github.com/primer/react/pull/7652) [`fbacefb`](https://github.com/primer/react/commit/fbacefb3aef577adb01500e30c1c6957a61491f1) Thanks [@owenniblock](https://github.com/owenniblock)! - useAnchoredPosition: recalculate overlay position when any scrollable ancestor (or the window) is scrolled.
16
+
15
17
  - [#7690](https://github.com/primer/react/pull/7690) [`b492cc8`](https://github.com/primer/react/commit/b492cc82efdb68189a070dfa7fcd88f18cc9d7b4) Thanks [@copilot-swe-agent](https://github.com/apps/copilot-swe-agent)! - fix(Button): Apply inline-flex display to loading wrapper for link variant buttons
16
18
 
17
19
  - [#7696](https://github.com/primer/react/pull/7696) [`1acb7d3`](https://github.com/primer/react/commit/1acb7d3dc416094e481ac9b45d3fa45ebd527c86) Thanks [@francinelucca](https://github.com/francinelucca)! - Fix item dividers not visible in SelectPanel and FilteredActionList when `showItemDividers` is enabled, caused by `content-visibility: auto` clipping the absolutely-positioned divider pseudo-elements.
@@ -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;AAKvE,MAAM,WAAW,4BAA6B,SAAQ,OAAO,CAAC,gBAAgB,CAAC;IAC7E,kBAAkB,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,OAAO,GAAG,IAAI,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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": "0.0.0-20260330123531",
4
+ "version": "0.0.0-20260330144944",
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",