diff --git a/packages/@headlessui-react/CHANGELOG.md b/packages/@headlessui-react/CHANGELOG.md
index b4a58bfff3..07b1f16776 100644
--- a/packages/@headlessui-react/CHANGELOG.md
+++ b/packages/@headlessui-react/CHANGELOG.md
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix prematurely added anchoring styles on `ListboxOptions` ([#3337](https://github.com/tailwindlabs/headlessui/pull/3337))
- Ensure `unmount` on `Dialog` works in combination with the `transition` prop on `DialogBackdrop` and `DialogPanel` components ([#3352](https://github.com/tailwindlabs/headlessui/pull/3352))
- Fix crash in `Combobox` component when in `virtual` mode when options are empty ([#3356](https://github.com/tailwindlabs/headlessui/pull/3356))
+- Fix hanging tests when using `anchor` prop ([#3357](https://github.com/tailwindlabs/headlessui/pull/3357))
## [2.1.1] - 2024-06-26
diff --git a/packages/@headlessui-react/src/components/popover/popover.test.tsx b/packages/@headlessui-react/src/components/popover/popover.test.tsx
index 1ca6e7d747..85d00d0f71 100644
--- a/packages/@headlessui-react/src/components/popover/popover.test.tsx
+++ b/packages/@headlessui-react/src/components/popover/popover.test.tsx
@@ -804,6 +804,26 @@ describe('Rendering', () => {
assertActiveElement(getByText('restorable'))
})
)
+
+ it(
+ 'should be possible to use the `anchor` prop on the `PopoverPanel`',
+ suppressConsoleLogs(async () => {
+ render(
+
+ Trigger
+ Panel open
+
+ )
+
+ assertPopoverButton({ state: PopoverState.InvisibleUnmounted })
+ assertPopoverPanel({ state: PopoverState.InvisibleUnmounted })
+
+ await click(getPopoverButton())
+
+ assertPopoverButton({ state: PopoverState.Visible })
+ assertPopoverPanel({ state: PopoverState.Visible })
+ })
+ )
})
describe('Multiple `Popover.Button` warnings', () => {
diff --git a/packages/@headlessui-react/src/internal/floating.tsx b/packages/@headlessui-react/src/internal/floating.tsx
index 6baaa432df..216e1f9f87 100644
--- a/packages/@headlessui-react/src/internal/floating.tsx
+++ b/packages/@headlessui-react/src/internal/floating.tsx
@@ -375,9 +375,16 @@ function useFixScrollingPixel(element: HTMLElement | null) {
if (!element) return
let observer = new MutationObserver(() => {
- let maxHeight = element.style.maxHeight
- if (parseFloat(maxHeight) !== parseInt(maxHeight)) {
- element.style.maxHeight = `${Math.ceil(parseFloat(maxHeight))}px`
+ let maxHeight = window.getComputedStyle(element).maxHeight
+
+ let maxHeightFloat = parseFloat(maxHeight)
+ if (isNaN(maxHeightFloat)) return
+
+ let maxHeightInt = parseInt(maxHeight)
+ if (isNaN(maxHeightInt)) return
+
+ if (maxHeightFloat !== maxHeightInt) {
+ element.style.maxHeight = `${Math.ceil(maxHeightFloat)}px`
}
})
diff --git a/playgrounds/react/pages/listbox/listbox-with-pure-tailwind.tsx b/playgrounds/react/pages/listbox/listbox-with-pure-tailwind.tsx
index 0d845b098a..de62f6945f 100644
--- a/playgrounds/react/pages/listbox/listbox-with-pure-tailwind.tsx
+++ b/playgrounds/react/pages/listbox/listbox-with-pure-tailwind.tsx
@@ -1,4 +1,4 @@
-import { Listbox, Transition } from '@headlessui/react'
+import { Label, Listbox, ListboxButton, ListboxOption, ListboxOptions } from '@headlessui/react'
import { useEffect, useState } from 'react'
let people = [
@@ -26,20 +26,12 @@ export default function Home() {
-
{
- console.log('value:', value)
- setActivePerson(value)
- }}
- >
-
- Assigned to
-
+
+
-
+
{active}
-
+
-
-
-
- {people.map((name) => (
-
-
- {name}
-
-
-
-
-
- ))}
-
-
-
+ {people.map((name) => (
+
+
+ {name}
+
+
+
+
+
+ ))}
+