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

fix(autocomplete-js): display warning when there are more than one instances of autocomplete #1108

Merged
merged 4 commits into from
Mar 16, 2023

Conversation

dhayab
Copy link
Member

@dhayab dhayab commented Mar 13, 2023

While autocomplate can technically render multiple instances in the same document, in practice it results in inconsistent behavior when a user interacts with them.

This is because we currently bind pointer events on Window to determine whether a panel should be closed after a user clicks outside of it. This only works for one of the autocomplete added to the document.

Until we find a way to handle that, and to make customers aware of this limitation, this PR displays a warning in dev when there are more than a single instance of Autocomplete on a document.

@dhayab dhayab requested review from a team, FabienMotte and aymeric-giraudet and removed request for a team March 13, 2023 15:21
@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 13, 2023

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 2c6e81f:

Sandbox Source
@algolia/autocomplete-example-github-repositories-custom-plugin Configuration
@algolia/autocomplete-example-instantsearch Configuration
@algolia/autocomplete-example-playground Configuration
@algolia/autocomplete-example-preview-panel-in-modal Configuration
@algolia/autocomplete-example-react-renderer Configuration
@algolia/autocomplete-example-starter-algolia Configuration
@algolia/autocomplete-example-starter Configuration
@algolia/autocomplete-example-reshape Configuration
@algolia/autocomplete-example-vue Configuration

Copy link
Member

@sarahdayan sarahdayan left a comment

Choose a reason for hiding this comment

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

I realized that we don't document destroy in the docs. Should we add an entry here so we can link it in the warning?

packages/autocomplete-js/src/autocomplete.ts Outdated Show resolved Hide resolved
dhayab and others added 2 commits March 13, 2023 16:44
@dhayab dhayab requested a review from sarahdayan March 13, 2023 15:53
@dhayab dhayab merged commit 2926feb into next Mar 16, 2023
@dhayab dhayab deleted the fix/warn-with-multiple-instances branch March 16, 2023 09:45
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.

3 participants