diff --git a/packages/@headlessui-react/CHANGELOG.md b/packages/@headlessui-react/CHANGELOG.md index 76b634e17b..3bf62ea600 100644 --- a/packages/@headlessui-react/CHANGELOG.md +++ b/packages/@headlessui-react/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Ensure the main tree and parent `Dialog` components are marked as `inert` ([#2290](https://github.com/tailwindlabs/headlessui/pull/2290)) - Fix nested `Popover` components not opening ([#2293](https://github.com/tailwindlabs/headlessui/pull/2293)) - Make React types more compatible with other libraries ([#2282](https://github.com/tailwindlabs/headlessui/pull/2282)) +- Fix `Dialog` cleanup when the `Dialog` becomes hidden ([#2303](https://github.com/tailwindlabs/headlessui/pull/2303)) ## [1.7.11] - 2023-02-15 diff --git a/packages/@headlessui-react/src/components/dialog/dialog.test.tsx b/packages/@headlessui-react/src/components/dialog/dialog.test.tsx index 535bf66c89..a36bb4cb16 100644 --- a/packages/@headlessui-react/src/components/dialog/dialog.test.tsx +++ b/packages/@headlessui-react/src/components/dialog/dialog.test.tsx @@ -30,7 +30,7 @@ import { OpenClosedProvider, State } from '../../internal/open-closed' jest.mock('../../hooks/use-id') // @ts-expect-error -global.IntersectionObserver = class FakeIntersectionObserver { +global.ResizeObserver = class FakeResizeObserver { observe() {} disconnect() {} } diff --git a/packages/@headlessui-react/src/components/dialog/dialog.tsx b/packages/@headlessui-react/src/components/dialog/dialog.tsx index 7c810602ae..7f31f17724 100644 --- a/packages/@headlessui-react/src/components/dialog/dialog.tsx +++ b/packages/@headlessui-react/src/components/dialog/dialog.tsx @@ -309,14 +309,10 @@ function DialogFn( if (dialogState !== DialogStates.Open) return if (!internalDialogRef.current) return - let observer = new IntersectionObserver((entries) => { + let observer = new ResizeObserver((entries) => { for (let entry of entries) { - if ( - entry.boundingClientRect.x === 0 && - entry.boundingClientRect.y === 0 && - entry.boundingClientRect.width === 0 && - entry.boundingClientRect.height === 0 - ) { + let rect = entry.target.getBoundingClientRect() + if (rect.x === 0 && rect.y === 0 && rect.width === 0 && rect.height === 0) { close() } } diff --git a/packages/@headlessui-vue/CHANGELOG.md b/packages/@headlessui-vue/CHANGELOG.md index f7e641bafe..c5c618015b 100644 --- a/packages/@headlessui-vue/CHANGELOG.md +++ b/packages/@headlessui-vue/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Ensure the main tree and parent `Dialog` components are marked as `inert` ([#2290](https://github.com/tailwindlabs/headlessui/pull/2290)) - Fix nested `Popover` components not opening ([#2293](https://github.com/tailwindlabs/headlessui/pull/2293)) - Fix `change` event incorrectly getting called on `blur` ([#2296](https://github.com/tailwindlabs/headlessui/pull/2296)) +- Fix `Dialog` cleanup when the `Dialog` becomes hidden ([#2303](https://github.com/tailwindlabs/headlessui/pull/2303)) ## [1.7.10] - 2023-02-15 diff --git a/packages/@headlessui-vue/src/components/dialog/dialog.test.ts b/packages/@headlessui-vue/src/components/dialog/dialog.test.ts index 9f6307cf0b..0ffc735119 100644 --- a/packages/@headlessui-vue/src/components/dialog/dialog.test.ts +++ b/packages/@headlessui-vue/src/components/dialog/dialog.test.ts @@ -44,7 +44,7 @@ import { html } from '../../test-utils/html' import { useOpenClosedProvider, State } from '../../internal/open-closed' // @ts-expect-error -global.IntersectionObserver = class FakeIntersectionObserver { +global.ResizeObserver = class FakeResizeObserver { observe() {} disconnect() {} } diff --git a/packages/@headlessui-vue/src/components/dialog/dialog.ts b/packages/@headlessui-vue/src/components/dialog/dialog.ts index f3865966e2..2c5272d97f 100644 --- a/packages/@headlessui-vue/src/components/dialog/dialog.ts +++ b/packages/@headlessui-vue/src/components/dialog/dialog.ts @@ -280,14 +280,10 @@ export let Dialog = defineComponent({ let container = dom(internalDialogRef) if (!container) return - let observer = new IntersectionObserver((entries) => { + let observer = new ResizeObserver((entries) => { for (let entry of entries) { - if ( - entry.boundingClientRect.x === 0 && - entry.boundingClientRect.y === 0 && - entry.boundingClientRect.width === 0 && - entry.boundingClientRect.height === 0 - ) { + let rect = entry.target.getBoundingClientRect() + if (rect.x === 0 && rect.y === 0 && rect.width === 0 && rect.height === 0) { api.close() } }