Skip to content
This repository has been archived by the owner on Dec 7, 2021. It is now read-only.

Commit

Permalink
Cycle through search matches
Browse files Browse the repository at this point in the history
  • Loading branch information
Mobius1 committed Sep 18, 2016
1 parent bd93cc7 commit 652d580
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 10 additions & 8 deletions selectr.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@

event.preventDefault();

var currentIdx = _this.activeIdx, dir;
var list = this.searching ? this.searchList : this.list, dir;

switch (keyCode) {
case 13: // select option
Expand All @@ -385,13 +385,13 @@
break;
case 40: // scroll down options
dir = 'down';
if ( _this.activeIdx < _this.list.length - 1 ) {
if ( _this.activeIdx < list.length - 1 ) {
_this.activeIdx++;
};
break;
}

var nextElem = _this.list[_this.activeIdx];
var nextElem = list[_this.activeIdx];
var nextRect = nextElem.getBoundingClientRect();

if ( dir === 'up' ) {
Expand Down Expand Up @@ -419,7 +419,7 @@


// Set the class for highlighting
forEach(_this.list, function(i, opt) {
forEach(list, function(i, opt) {
if ( i === _this.activeIdx ) {
_addClass(opt, 'active');
} else {
Expand All @@ -433,8 +433,9 @@
var _this = this;
var value = _this.input.value;
var len = value.length;
var navigating = event.keyCode === 38 || event.keyCode === 40;

if ( len < this.options.minChars && len >= this.lastLen ) return;
if ( ( len < this.options.minChars && len >= this.lastLen ) || navigating ) return;

if ( this.ajaxOpts ) {
this.ajaxSearch();
Expand Down Expand Up @@ -469,7 +470,7 @@
}
_removeClass(opt, 'excluded');

console.log(_this.searchList);
console.log(_this.searchList)
}
});

Expand Down Expand Up @@ -516,9 +517,10 @@

var _this = this;
var selected = event.target;
var list = this.searching ? this.searchList : this.list;

if ( event.type === 'keydown' ) {
selected = _this.list[_this.activeIdx];
selected = list[_this.activeIdx];
}

if ( selected.nodeName !== 'LI' ) return;
Expand Down Expand Up @@ -751,7 +753,6 @@
if ( this.options.enableSearch ) {
this.input.value = null;
this.searching = false;
this.searchList = [];
_removeClass(this.inputContainer, 'active');
}

Expand Down Expand Up @@ -801,6 +802,7 @@
{
if ( this.options.enableSearch ) {
this.input.blur();
this.searching = false;
}

_removeClass(this.container, 'open');
Expand Down
Loading

0 comments on commit 652d580

Please sign in to comment.