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

Merged
merged 3 commits into from
Aug 9, 2024

Conversation

github-actions[bot]
Copy link
Contributor

Release
@floating-ui/[email protected]

Diff for packages/utils

Diff
diff --git a/packages/utils/CHANGELOG.md b/packages/utils/CHANGELOG.md
index 2eccaed5..92a1b608 100644
--- a/packages/utils/CHANGELOG.md
+++ b/packages/utils/CHANGELOG.md
@@ -1,5 +1,12 @@
 # @floating-ui/utils
 
+## 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..5c133d7b 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.5",
   "description": "Utilities for Floating UI",
   "publishConfig": {
     "access": "public"
diff --git a/packages/utils/src/dom.ts b/packages/utils/src/dom.ts
index 208b5a2a..34743483 100644
--- a/packages/utils/src/dom.ts
+++ b/packages/utils/src/dom.ts
@@ -68,9 +68,9 @@ 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 +92,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);

Full diff
0.2.4...0.2.5.

@DanielleHuisman DanielleHuisman marked this pull request as ready for review August 9, 2024 11:55
@DanielleHuisman DanielleHuisman merged commit eea0228 into main Aug 9, 2024
1 check passed
@DanielleHuisman DanielleHuisman deleted the upstream/utils-0.2.5 branch August 9, 2024 12:07
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