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 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(