Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to upstream @floating-ui/[email protected] #49

Merged
merged 2 commits into from
Nov 3, 2024

Conversation

github-actions[bot]
Copy link
Contributor

Release
@floating-ui/[email protected]

Diff for packages/dom

Diff
diff --git a/packages/dom/CHANGELOG.md b/packages/dom/CHANGELOG.md
index d1dc8e5b..9c97ff7d 100644
--- a/packages/dom/CHANGELOG.md
+++ b/packages/dom/CHANGELOG.md
@@ -1,5 +1,12 @@
 # @floating-ui/dom
 
+## 1.6.12
+
+### Patch Changes
+
+- fix: handle relative html offset clipping rect
+- fix(getClippingRect): allow passing `DOMRect` as a `boundary`
+
 ## 1.6.11
 
 ### Patch Changes
diff --git a/packages/dom/package.json b/packages/dom/package.json
index 8b9fe03c..45d8fa99 100644
--- a/packages/dom/package.json
+++ b/packages/dom/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@floating-ui/dom",
-  "version": "1.6.11",
+  "version": "1.6.12",
   "description": "Floating UI for the web",
   "publishConfig": {
     "access": "public"
diff --git a/packages/dom/src/platform/convertOffsetParentRelativeRectToViewportRelativeRect.ts b/packages/dom/src/platform/convertOffsetParentRelativeRectToViewportRelativeRect.ts
index 938268f2..01d1aa91 100644
--- a/packages/dom/src/platform/convertOffsetParentRelativeRectToViewportRelativeRect.ts
+++ b/packages/dom/src/platform/convertOffsetParentRelativeRectToViewportRelativeRect.ts
@@ -11,6 +11,7 @@ import {
 
 import {getBoundingClientRect} from '../utils/getBoundingClientRect';
 import {getScale} from './getScale';
+import {getHTMLOffset} from '../utils/getHTMLOffset';
 
 export function convertOffsetParentRelativeRectToViewportRelativeRect({
   elements,
@@ -52,10 +53,16 @@ export function convertOffsetParentRelativeRectToViewportRelativeRect({
     }
   }
 
+  const htmlOffset =
+    documentElement && !isOffsetParentAnElement && !isFixed
+      ? getHTMLOffset(documentElement, scroll, true)
+      : createCoords(0);
+
   return {
     width: rect.width * scale.x,
     height: rect.height * scale.y,
-    x: rect.x * scale.x - scroll.scrollLeft * scale.x + offsets.x,
-    y: rect.y * scale.y - scroll.scrollTop * scale.y + offsets.y,
+    x:
+      rect.x * scale.x - scroll.scrollLeft * scale.x + offsets.x + htmlOffset.x,
+    y: rect.y * scale.y - scroll.scrollTop * scale.y + offsets.y + htmlOffset.y,
   };
 }
diff --git a/packages/dom/src/platform/getClippingRect.ts b/packages/dom/src/platform/getClippingRect.ts
index 8627c4e5..7206264c 100644
--- a/packages/dom/src/platform/getClippingRect.ts
+++ b/packages/dom/src/platform/getClippingRect.ts
@@ -70,9 +70,10 @@ function getClientRectFromClippingAncestor(
   } else {
     const visualOffsets = getVisualOffsets(element);
     rect = {
-      ...clippingAncestor,
       x: clippingAncestor.x - visualOffsets.x,
       y: clippingAncestor.y - visualOffsets.y,
+      width: clippingAncestor.width,
+      height: clippingAncestor.height,
     };
   }
 
diff --git a/packages/dom/src/utils/getHTMLOffset.ts b/packages/dom/src/utils/getHTMLOffset.ts
new file mode 100644
index 00000000..bdc4bbea
--- /dev/null
+++ b/packages/dom/src/utils/getHTMLOffset.ts
@@ -0,0 +1,23 @@
+import type {NodeScroll} from '../types';
+import {getWindowScrollBarX} from './getWindowScrollBarX';
+
+export function getHTMLOffset(
+  documentElement: HTMLElement,
+  scroll: NodeScroll,
+  ignoreScrollbarX = false,
+) {
+  const htmlRect = documentElement.getBoundingClientRect();
+  const x =
+    htmlRect.left +
+    scroll.scrollLeft -
+    (ignoreScrollbarX
+      ? 0
+      : // RTL <body> scrollbar.
+        getWindowScrollBarX(documentElement, htmlRect));
+  const y = htmlRect.top + scroll.scrollTop;
+
+  return {
+    x,
+    y,
+  };
+}
diff --git a/packages/dom/src/utils/getRectRelativeToOffsetParent.ts b/packages/dom/src/utils/getRectRelativeToOffsetParent.ts
index 6bd9c657..1bee4fc6 100644
--- a/packages/dom/src/utils/getRectRelativeToOffsetParent.ts
+++ b/packages/dom/src/utils/getRectRelativeToOffsetParent.ts
@@ -11,6 +11,7 @@ import type {VirtualElement} from '../types';
 import {getDocumentElement} from '../platform/getDocumentElement';
 import {getBoundingClientRect} from './getBoundingClientRect';
 import {getWindowScrollBarX} from './getWindowScrollBarX';
+import {getHTMLOffset} from './getHTMLOffset';
 
 export function getRectRelativeToOffsetParent(
   element: Element | VirtualElement,
@@ -49,21 +50,13 @@ export function getRectRelativeToOffsetParent(
     }
   }
 
-  let htmlX = 0;
-  let htmlY = 0;
+  const htmlOffset =
+    documentElement && !isOffsetParentAnElement && !isFixed
+      ? getHTMLOffset(documentElement, scroll)
+      : createCoords(0);
 
-  if (documentElement && !isOffsetParentAnElement && !isFixed) {
-    const htmlRect = documentElement.getBoundingClientRect();
-    htmlY = htmlRect.top + scroll.scrollTop;
-    htmlX =
-      htmlRect.left +
-      scroll.scrollLeft -
-      // RTL <body> scrollbar.
-      getWindowScrollBarX(documentElement, htmlRect);
-  }
-
-  const x = rect.left + scroll.scrollLeft - offsets.x - htmlX;
-  const y = rect.top + scroll.scrollTop - offsets.y - htmlY;
+  const x = rect.left + scroll.scrollLeft - offsets.x - htmlOffset.x;
+  const y = rect.top + scroll.scrollTop - offsets.y - htmlOffset.y;
 
   return {
     x,

Full diff
1.6.11...1.6.12.

@DanielleHuisman DanielleHuisman marked this pull request as ready for review November 3, 2024 18:30
@DanielleHuisman DanielleHuisman merged commit aeb9443 into main Nov 3, 2024
4 checks passed
@DanielleHuisman DanielleHuisman deleted the upstream/dom-1.6.12 branch November 3, 2024 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant