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

Arrow key down on un-clicked, empty input causes unrecoverable error #229

Open
aaronahearne opened this issue Mar 22, 2022 · 0 comments
Open

Comments

@aaronahearne
Copy link

aaronahearne commented Mar 22, 2022

  • vue-autosuggest version: 2.2.0
  • node version: 14.18.1
  • npm (or yarn) version: yarn 1.22.15

Relevant code or config

Standard implementation.

What you did:

Navigate to the autosuggest input using keyboard (Tab). Do not click the input.
Press the arrow down key.

What happened:

Receive the error: TypeError: Cannot read property '0' of undefined.

Problem description:

computed_section_default0 is not being populated unless the input receives a character or is clicked.

Suggested solution:

As a workaround to this issue, I provided an override to the handleKeyStroke method in the mounted hook of my component:

patchAutoSuggestKeystrokeBug() {
      const autoSuggest = this.$refs.autosuggest;
      const originalHandleKeyStrokeFunc = autoSuggest.handleKeyStroke;

      this.$refs.autosuggest.handleKeyStroke = function (e) {
        // Simulate a click on ArrowDown to open the list of suggestions
        if (e.keyCode === 40 && autoSuggest.$data.currentIndex === null) {
          autoSuggest.listeners.click();
          autoSuggest.$data.currentIndex = 0;
          return;
        }

        originalHandleKeyStrokeFunc(e);
      };
},

This allows the list of suggestions to open when the arrow key down is pressed in this scenario, rather than erroring.

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

No branches or pull requests

1 participant