Skip to content

Commit db702a7

Browse files
Only render virtual options wrapper when there are items to show (#3161)
* Only render virtual options wrapper when there are items to show * Update changelog
1 parent 5952268 commit db702a7

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

packages/@headlessui-react/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3232
- Only check for elements in `useInertOthers` ([#3154](https://github.com/tailwindlabs/headlessui/pull/3154))
3333
- Fix anchored elements not flipping when there is padding ([#3157](https://github.com/tailwindlabs/headlessui/pull/3157))
3434
- Render virtual items during an exiting transition ([#3160](https://github.com/tailwindlabs/headlessui/pull/3160))
35+
- Only render virtual options wrapper when there are items to show ([#3161](https://github.com/tailwindlabs/headlessui/pull/3161))
3536

3637
### Changed
3738

packages/@headlessui-react/src/components/combobox/combobox.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,12 @@ function VirtualProvider(props: {
449449
setBaseKey((v) => v + 1)
450450
}, [data.virtual?.options])
451451

452+
let items = virtualizer.getVirtualItems()
453+
454+
if (items.length === 0) {
455+
return null
456+
}
457+
452458
return (
453459
<VirtualContext.Provider value={virtualizer}>
454460
<div
@@ -483,7 +489,7 @@ function VirtualProvider(props: {
483489
}
484490
}}
485491
>
486-
{virtualizer.getVirtualItems().map((item) => {
492+
{items.map((item) => {
487493
return (
488494
<Fragment key={item.key}>
489495
{React.cloneElement(

0 commit comments

Comments
 (0)