-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Closed
Labels
Description
Demo:
https://plnkr.co/edit/k2xl65uBG8xsFVaX
Steps to reproduce:
- Create a dropdown with an options group at element 1
- Fill your dropdown with enough items to trigger a scrollbar (data-size=5 and 10 elements should do)
- Open the dropdown and use arrow down to traverse the dropdown until you are at the last item.
- Hit arrow down one last time. The selector will select the correct item, but your scroll bar will not be set to the top.
Environment:
Boostrap 4
Boostrap-select 1.13.17
jQuery version 3.4.1
Windows 10
Chrome 83.0.4103.97
Code that seems buggy:
bootstrap-select.js
line: 2876-2881:
else if (e.which === keyCodes.ARROW_DOWN || downOnTab) { // down
index++;
if (index + position0 >= that.selectpicker.view.canHighlight.length) index = 0;
if (!that.selectpicker.view.canHighlight[index + position0]) {
index = index + 1 + that.selectpicker.view.canHighlight.slice(index + position0 + 1).indexOf(true);
}
}
This code selects the first highlightable index. In this case index = 1
Further down in the scroll to top code:
line: 2901-2911:
else if (e.which === keyCodes.ARROW_DOWN || downOnTab) { // down
// scroll to top and highlight first option
if (index === 0) {
that.$menuInner[0].scrollTop = 0;
liActiveIndex = 0;
} else {
activeLi = that.selectpicker.current.data[liActiveIndex];
offset = activeLi.position - that.sizeInfo.menuInnerHeight;
updateScroll = offset > scrollTop;
}
Only scrolls to top if index === 0. Since index 0 is not highlightable. This has to check for the first highlightable index and not 0.
BR,
Lucas