diff --git a/dist/suggestions.js b/dist/suggestions.js index bda4718..0b70e23 100644 --- a/dist/suggestions.js +++ b/dist/suggestions.js @@ -1 +1 @@ -!function t(e,i,n){function s(o,h){if(!i[o]){if(!e[o]){var a="function"==typeof require&&require;if(!h&&a)return a(o,!0);if(r)return r(o,!0);var l=new Error("Cannot find module '"+o+"'");throw l.code="MODULE_NOT_FOUND",l}var u=i[o]={exports:{}};e[o][0].call(u.exports,function(t){var i=e[o][1][t];return s(i||t)},u,u.exports,t,e,i,n)}return i[o].exports}for(var r="function"==typeof require&&require,o=0;o-1},o.prototype.value=function(t){if(this.selected=t,this.el.value=this.getItemValue(t),document.createEvent){var e=document.createEvent("HTMLEvents");e.initEvent("change",!0,!1),this.el.dispatchEvent(e)}else this.el.fireEvent("onchange")},o.prototype.getCandidates=function(t){var e={pre:"",post:"",extract:function(t){return this.getItemValue(t)}.bind(this)};t(this.options.filter?s.filter(this.query,this.data,e):this.data.map(function(t){return{original:t,string:this.getItemValue(t).replace(new RegExp("("+this.query+")","ig"),function(t,e){return""+e+""})}}.bind(this)))},o.prototype.getItemValue=function(t){return t},e.exports=o},{"./list":4,fuzzy:2,xtend:3}]},{},[1]); +!function(){function t(e,i,n){function s(o,h){if(!i[o]){if(!e[o]){var a="function"==typeof require&&require;if(!h&&a)return a(o,!0);if(r)return r(o,!0);var l=new Error("Cannot find module '"+o+"'");throw l.code="MODULE_NOT_FOUND",l}var u=i[o]={exports:{}};e[o][0].call(u.exports,function(t){return s(e[o][1][t]||t)},u,u.exports,t,e,i,n)}return i[o].exports}for(var r="function"==typeof require&&require,o=0;o-1},o.prototype.value=function(t){if(this.selected=t,this.el.value=this.getItemValue(t),document.createEvent){var e=document.createEvent("HTMLEvents");e.initEvent("change",!0,!1),this.el.dispatchEvent(e)}else this.el.fireEvent("onchange")},o.prototype.getCandidates=function(t){var e={pre:"",post:"",extract:function(t){return this.getItemValue(t)}.bind(this)};t(this.options.filter?s.filter(this.query,this.data,e):this.data.map(function(t){for(var e=this.getItemValue(t),i=this.normalize(e),n=i.lastIndexOf(this.query);n>-1;){var s=n+this.query.length;e=e.slice(0,n)+""+e.slice(n,s)+""+e.slice(s),n=i.slice(0,n).lastIndexOf(this.query)}return{original:t,string:e}}.bind(this)))},o.prototype.getItemValue=function(t){return t},e.exports=o},{"./list":4,fuzzy:2,xtend:3}]},{},[1]); diff --git a/src/list.js b/src/list.js index 3262939..0fa702d 100644 --- a/src/list.js +++ b/src/list.js @@ -37,6 +37,10 @@ List.prototype.isEmpty = function() { return !this.items.length; }; +List.prototype.isVisible = function() { + return this.element.style.display === 'block'; +}; + List.prototype.draw = function() { this.element.innerHTML = ''; diff --git a/src/suggestions.js b/src/suggestions.js index a29bf3f..fee28be 100644 --- a/src/suggestions.js +++ b/src/suggestions.js @@ -64,9 +64,11 @@ Suggestions.prototype.handleKeyUp = function(keyCode) { Suggestions.prototype.handleKeyDown = function(e) { switch (e.keyCode) { case 13: // ENTER - case 9: // TAB - e.preventDefault(); + case 9: // TAB if (!this.list.isEmpty()) { + if (this.list.isVisible()) { + e.preventDefault(); + } this.value(this.list.items[this.list.active].original); this.list.hide(); }