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

Enter key behaviour #31

Closed
paulheijman opened this issue Mar 19, 2018 · 6 comments
Closed

Enter key behaviour #31

paulheijman opened this issue Mar 19, 2018 · 6 comments
Assignees

Comments

@paulheijman
Copy link

First of all: thank you for a very useful component!

  • vue-autosuggest version: 1.3.1
  • node version: 9.4.0
  • npm (or yarn) version: 5.7.1
            <vue-autosuggest
                ref="autosuggest"
                @keyup.enter="doSearch"
                :suggestions="suggestions"
                :inputProps="inputProps"
                :renderSuggestion="renderSuggestion"
                :getSuggestionValue="getSuggestionValue"
                :onSelected="onSelected"
            />

Problem description:
I want to use the autosuggest as a searchbar and suggester works very nice, but when the user hits enter my search function isn't called despite the @keyup.enter

Suggested solution:
It seems the enter key event is overridden in the component for selecting a value from the dropdown list. If the list is closed the override should be ignored.

@darrenjennings
Copy link
Owner

thank you for the note. I will look into this later. It is not readily apparent how you can bind these kind of methods from the component instantiation without the library knowing about them to begin with so I will have to implement them manually like I did for onBlur and onFocus.

However, I have two solutions that might be able to work for you.

  1. keydown.enter is used in onSelected so you could use that to trigger your search. It should work even if there is nothing selected. I demonstrate an example here:
  1. Search inputs are usually embedded inside of HTML forms. If you use my component inside of a <form> , you can trigger a form submit inside the onSelected event.

@paulheijman
Copy link
Author

Hi Darren,
Thank you for your quick reply!
It does work the way you described in #1. But I think it would be nicer to have it implemented as with onBlur, etc.

darrenjennings added a commit that referenced this issue Mar 23, 2018
* added transparent wrappers and deprecated inputProps.onBlur and onFocus
* users can now user @keyup @Focus @blur etc on root vue-autosuggest component to bind native events to the input.

From #31
darrenjennings added a commit that referenced this issue Mar 26, 2018
* feat(listeners): added transparent wrappers and deprecated inputProps.onClick, onBlur, onFocus. users can now use native @keyup.tab @Focus @blur etc on root vue-autosuggest component to bind native events to the input.
* docs(1.4.0): version bump, readme update
* style(code): prettier semi and double quotes addedwq
* packages(vue): upgraded packages vue, vue-test-utils etc.

From #31 #34
@darrenjennings
Copy link
Owner

@paulheijman you can now do @keyup.enter and any other native event you'd like to attach to the <input> as of 1.4.1. Thanks for the suggestion and I think this is a great feature. Drafting release notes now.

@paulheijman
Copy link
Author

Hi Darren,

Thank you!

@cssndrx
Copy link

cssndrx commented Jan 23, 2021

Thanks so much for adding this, Darren!

Question for Darren or Paul.... how do you fish out the value of the VueAutosuggest from within the function linked to @keyup.enter?

@cssndrx
Copy link

cssndrx commented Jan 23, 2021

Ah doh! Figured it out. It's bound to v-model.

Amazing component, thank you Darren!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants