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] #40

Merged
merged 1 commit into from
Aug 10, 2024

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Aug 7, 2024

Release
@floating-ui/[email protected]

Diff for packages/utils

Diff
diff --git a/packages/utils/CHANGELOG.md b/packages/utils/CHANGELOG.md
index 2eccaed5..7f9072b1 100644
--- a/packages/utils/CHANGELOG.md
+++ b/packages/utils/CHANGELOG.md
@@ -1,5 +1,24 @@
 # @floating-ui/utils
 
+## 0.2.7
+
+### Patch Changes
+
+- fix(getFrameElement): ensure `win.parent` is an object
+
+## 0.2.6
+
+### Patch Changes
+
+- fix: test if `frameElement` is readable to avoid errors in Safari and MSEdge with cross-origin iframes
+
+## 0.2.5
+
+### Patch Changes
+
+- feat(getContainingBlock): allow `CSSStyleDeclaration` as an argument
+- fix(getContainingBlock): reorder `isTopLayer` check. Fixes regression when a top layer element like `<dialog>` is a containing block (e.g. it has a `transform` style) and a floating element is being positioned inside of it.
+
 ## 0.2.4
 
 ### Patch Changes
diff --git a/packages/utils/package.json b/packages/utils/package.json
index 72bf8c5e..ff969b80 100644
--- a/packages/utils/package.json
+++ b/packages/utils/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@floating-ui/utils",
-  "version": "0.2.4",
+  "version": "0.2.7",
   "description": "Utilities for Floating UI",
   "publishConfig": {
     "access": "public"
diff --git a/packages/utils/src/dom.ts b/packages/utils/src/dom.ts
index 208b5a2a..b90fea2b 100644
--- a/packages/utils/src/dom.ts
+++ b/packages/utils/src/dom.ts
@@ -68,9 +68,13 @@ export function isTopLayer(element: Element): boolean {
   });
 }
 
-export function isContainingBlock(element: Element): boolean {
+export function isContainingBlock(
+  elementOrCss: Element | CSSStyleDeclaration,
+): boolean {
   const webkit = isWebKit();
-  const css = getComputedStyle(element);
+  const css = isElement(elementOrCss)
+    ? getComputedStyle(elementOrCss)
+    : elementOrCss;
 
   // https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
   return (
@@ -92,12 +96,10 @@ export function getContainingBlock(element: Element): HTMLElement | null {
   let currentNode: Node | null = getParentNode(element);
 
   while (isHTMLElement(currentNode) && !isLastTraversableNode(currentNode)) {
-    if (isTopLayer(currentNode)) {
-      return null;
-    }
-
     if (isContainingBlock(currentNode)) {
       return currentNode;
+    } else if (isTopLayer(currentNode)) {
+      return null;
     }
 
     currentNode = getParentNode(currentNode);
@@ -180,13 +182,12 @@ export function getOverflowAncestors(
   const win = getWindow(scrollableAncestor);
 
   if (isBody) {
+    const frameElement = getFrameElement(win);
     return list.concat(
       win,
       win.visualViewport || [],
       isOverflowElement(scrollableAncestor) ? scrollableAncestor : [],
-      win.frameElement && traverseIframes
-        ? getOverflowAncestors(win.frameElement)
-        : [],
+      frameElement && traverseIframes ? getOverflowAncestors(frameElement) : [],
     );
   }
 
@@ -195,3 +196,9 @@ export function getOverflowAncestors(
     getOverflowAncestors(scrollableAncestor, [], traverseIframes),
   );
 }
+
+export function getFrameElement(win: Window): Element | null {
+  return win.parent && Object.getPrototypeOf(win.parent)
+    ? win.frameElement
+    : null;
+}

Full diff
0.2.4...0.2.7.

@DanielleHuisman DanielleHuisman marked this pull request as ready for review August 10, 2024 19:26
@DanielleHuisman DanielleHuisman enabled auto-merge (squash) August 10, 2024 19:27
@DanielleHuisman DanielleHuisman merged commit 8c5bee2 into main Aug 10, 2024
1 check passed
@DanielleHuisman DanielleHuisman deleted the upstream/utils-0.2.7 branch August 10, 2024 19:32
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