ng2-ui / auto-complete

Angular Auto Complete component and directive
https://ng2-ui.github.io/dist/#/auto-complete
MIT License
279 stars 122 forks source link

keep track of on <enter> on charKey change to prevent hiding the resu… #342

Closed koktaildotcom closed 6 years ago

koktaildotcom commented 6 years ago

resolves https://github.com/ng2-ui/auto-complete/issues/340

koktaildotcom commented 6 years ago

@almothafar can you look at the pr please?

almothafar commented 6 years ago

Thanks for PR, I'm just worried about breaking the correct behavior of this component, I mean when the list opened, and I select the item with arrows, and click enter to select, does your BR breaking this and force me to click instead? if yes, then I'm not going to merge this, because it will simply create a new issue.

koktaildotcom commented 6 years ago

Thanks for your reaction @almothafar. The PR is not breaking the correct behavior of the select list. The code keeps track of current state of the input with the selectOnEnter variable.

In your scenario: selectOnEnter = false on default. On arrow up (or arrow down) the event will be triggered and set selectOnEnter to true if the enter is triggered now, the item is selected.

On hideDropdownList the selectOnEnter will be set to false so the enter event (without the autocomplete list open) will not return the item.

I've already have this code running on a production environment.

almothafar commented 6 years ago

Sounds good. I'll merge it but it will be released next version.