Skip to content

fix(autocomplete): hide header when there are no items to display#6883

Merged
FabienMotte merged 3 commits intomasterfrom
fix/autocomplete-header-empty-items
Jan 29, 2026
Merged

fix(autocomplete): hide header when there are no items to display#6883
FabienMotte merged 3 commits intomasterfrom
fix/autocomplete-header-empty-items

Conversation

@FabienMotte
Copy link
Contributor

Summary

This PR fixes the headerComponent being displayed even when there are no items, such as when using showRecent.headerComponent without any recent searches.

Result

Before

image

After

image

@FabienMotte FabienMotte requested a review from Haroenv January 29, 2026 11:39
@FabienMotte FabienMotte self-assigned this Jan 29, 2026
Copy link
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix looks good, can you add a test?

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jan 29, 2026

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 2db7a3f:

Sandbox Source
example-instantsearch-getting-started Configuration
example-react-instantsearch-getting-started Configuration
example-react-instantsearch-next-app-dir-example Configuration
example-react-instantsearch-next-routing-example Configuration
example-vue-instantsearch-getting-started Configuration

@FabienMotte FabienMotte requested a review from Haroenv January 29, 2026 11:48
Copy link
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so the issue is that unlike other sources, which only render if there are results, recent searches is rendered, and therefore renders the header. This feels like a correct fix, but alternatively we also could have made the whole recent searches source conditional based on the items, and not just the header, as we now are still rendering the parent div.

@FabienMotte
Copy link
Contributor Author

FabienMotte commented Jan 29, 2026

so the issue is that unlike other sources, which only render if there are results, recent searches is rendered, and therefore renders the header. This feels like a correct fix, but alternatively we also could have made the whole recent searches source conditional based on the items, and not just the header, as we now are still rendering the parent div.

Good point, should I also add a condition to only display the "Recent searches" source when there are items to show?
Or should we return null if there are no items to display in the AutocompleteIndex component?

@FabienMotte FabienMotte force-pushed the fix/autocomplete-header-empty-items branch from 681ca91 to 2db7a3f Compare January 29, 2026 12:01
@FabienMotte FabienMotte enabled auto-merge (squash) January 29, 2026 12:02
@FabienMotte FabienMotte merged commit 81e677a into master Jan 29, 2026
14 checks passed
@FabienMotte FabienMotte deleted the fix/autocomplete-header-empty-items branch January 29, 2026 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants