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: cursor stays where it's supposed to be #343

Merged
merged 1 commit into from
Oct 12, 2020
Merged

Conversation

eunjae-lee
Copy link
Contributor

@eunjae-lee eunjae-lee commented Oct 12, 2020

Summary

When the query is abcdef, and move the cursor in the middle of input element and type Z, then it will become abcZdef. Here the cursor is supposed to be right after Z, but it was wrongly moved to the end of the query.

The problem comes from the order of

  setHighlightedIndex(props.defaultHighlightedIndex);
  setQuery(query);

When setHighlightedIndex() is called, the input.value is already abcZdef, but store.getState().query is still abcdef because the query hasn't been updated to the store yet.

So input.value becomes abcdef. Shortly after because of setQuery, input.value becomes abcZdef again.

In this PR, the order is been reversed, which now correctly sets the query first, and then proceed with the rest. It doesn't move cursor anymore.

@codesandbox-ci
Copy link

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 d6de51b:

Sandbox Source
algolia/autocomplete.js: js Configuration

@eunjae-lee eunjae-lee requested review from a team, yannickcr and francoischalifour and removed request for a team October 12, 2020 15:27
Copy link
Member

@francoischalifour francoischalifour left a comment

Choose a reason for hiding this comment

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

Nice catch!

@eunjae-lee eunjae-lee merged commit bae4d62 into next Oct 12, 2020
@eunjae-lee eunjae-lee deleted the fix/cursor-jumping branch October 12, 2020 16:02
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.

None yet

2 participants