ng2-ui / auto-complete

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

Is It possible to close dropdown on esc? #279

Closed Pinank closed 6 years ago

Pinank commented 6 years ago

On Esc i'm getting the textfield reference and using the blur event i'm able to lose the focus of textfield but the dropdown shows. So is there any way or method available to handle this?

allenhwkim commented 6 years ago

yes it's possible. Currently not implemented.

Pinank commented 6 years ago

Can you please update it. We are already having the code there. You just need to add the hide dropdown part

`inputElKeyHandler = (evt: any) => {
let totalNumItem = this.filteredList.length;

switch (evt.keyCode) {
  case 27: // ESC, hide auto complete
    break;

  case 38: // UP, select the previous li el
    this.itemIndex = (totalNumItem + this.itemIndex - 1) % totalNumItem;
    this.scrollToView(this.itemIndex);
    break;

  case 40: // DOWN, select the next li el or the first one
    this.dropdownVisible = true;
    let sum = this.itemIndex;
    if (this.itemIndex === null) {
      sum = 0;
    } else {
      sum = sum + 1;
    }
    this.itemIndex = (totalNumItem + sum) % totalNumItem;
    this.scrollToView(this.itemIndex);
    break;

  case 13: // ENTER, choose it!!
    this.selectOne(this.filteredList[this.itemIndex]);
    evt.preventDefault();
    break;

  case 9: // TAB, choose if tab-to-select is enabled
    if (this.tabToSelect) {
      this.selectOne(this.filteredList[this.itemIndex]);
    }
    break;
}
  };`