Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only render virtual options wrapper when there are items to show #3161

Merged
merged 2 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/@headlessui-react/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<VirtualContext.Provider value={virtualizer}>
<div
Expand Down Expand Up @@ -483,7 +489,7 @@ function VirtualProvider(props: {
}
}}
>
{virtualizer.getVirtualItems().map((item) => {
{items.map((item) => {
return (
<Fragment key={item.key}>
{React.cloneElement(
Expand Down
Loading