From a8dbefa460e5b3d36813c5df623a3eda76617ded Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Wed, 1 May 2024 09:52:57 -0400 Subject: [PATCH 1/2] Only render virtual options wrapper when there are items to show --- .../src/components/combobox/combobox.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/@headlessui-react/src/components/combobox/combobox.tsx b/packages/@headlessui-react/src/components/combobox/combobox.tsx index c1a09c4538..0286b41887 100644 --- a/packages/@headlessui-react/src/components/combobox/combobox.tsx +++ b/packages/@headlessui-react/src/components/combobox/combobox.tsx @@ -449,6 +449,12 @@ function VirtualProvider(props: { setBaseKey((v) => v + 1) }, [data.virtual?.options]) + let items = virtualizer.getVirtualItems() + + if (items.length === 0) { + return null + } + return (
- {virtualizer.getVirtualItems().map((item) => { + {items.map((item) => { return ( {React.cloneElement( From 87fdf6560a27400bf1b6de5950805d33d063b1e9 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Wed, 1 May 2024 09:54:10 -0400 Subject: [PATCH 2/2] Update changelog --- packages/@headlessui-react/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/@headlessui-react/CHANGELOG.md b/packages/@headlessui-react/CHANGELOG.md index 287cb0f03f..f8b612ca43 100644 --- a/packages/@headlessui-react/CHANGELOG.md +++ b/packages/@headlessui-react/CHANGELOG.md @@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Only check for elements in `useInertOthers` ([#3154](https://github.com/tailwindlabs/headlessui/pull/3154)) - Fix anchored elements not flipping when there is padding ([#3157](https://github.com/tailwindlabs/headlessui/pull/3157)) - Render virtual items during an exiting transition ([#3160](https://github.com/tailwindlabs/headlessui/pull/3160)) +- Only render virtual options wrapper when there are items to show ([#3161](https://github.com/tailwindlabs/headlessui/pull/3161)) ### Changed