Skip to content

Commit

Permalink
use first index that can be active instead of 0 (#2483)
Browse files Browse the repository at this point in the history
  • Loading branch information
caseyjhol committed Jun 17, 2020
1 parent a9f8afa commit 3572350
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions js/bootstrap-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,7 @@
setPositionData: function () {
this.selectpicker.view.canHighlight = [];
this.selectpicker.view.size = 0;
this.selectpicker.view.firstHighlightIndex = false;

for (var i = 0; i < this.selectpicker.current.data.length; i++) {
var li = this.selectpicker.current.data[i],
Expand All @@ -1151,6 +1152,7 @@
if (canHighlight) {
this.selectpicker.view.size++;
li.posinset = this.selectpicker.view.size;
if (this.selectpicker.view.firstHighlightIndex === false) this.selectpicker.view.firstHighlightIndex = i;
}

li.position = (i === 0 ? 0 : this.selectpicker.current.data[i - 1].position) + li.height;
Expand Down Expand Up @@ -2863,7 +2865,7 @@
}
} else if (e.which === keyCodes.ARROW_DOWN || downOnTab) { // down
index++;
if (index + position0 >= that.selectpicker.view.canHighlight.length) index = 0;
if (index + position0 >= that.selectpicker.view.canHighlight.length) index = that.selectpicker.view.firstHighlightIndex;

if (!that.selectpicker.view.canHighlight[index + position0]) {
index = index + 1 + that.selectpicker.view.canHighlight.slice(index + position0 + 1).indexOf(true);
Expand All @@ -2888,10 +2890,10 @@
}
} else if (e.which === keyCodes.ARROW_DOWN || downOnTab) { // down
// scroll to top and highlight first option
if (index === 0) {
if (index === that.selectpicker.view.firstHighlightIndex) {
that.$menuInner[0].scrollTop = 0;

liActiveIndex = 0;
liActiveIndex = that.selectpicker.view.firstHighlightIndex;
} else {
activeLi = that.selectpicker.current.data[liActiveIndex];
offset = activeLi.position - that.sizeInfo.menuInnerHeight;
Expand Down

0 comments on commit 3572350

Please sign in to comment.