BigW Consortium Gitlab

Commit 3680612a by Phil Hughes

Fixed currentIndex being shared across dropdowns

parent 90058cf4
...@@ -58,6 +58,7 @@ var CustomEvent = require('./custom_event_polyfill'); ...@@ -58,6 +58,7 @@ var CustomEvent = require('./custom_event_polyfill');
var utils = require('./utils'); var utils = require('./utils');
var DropDown = function(list) { var DropDown = function(list) {
this.currentIndex = 0;
this.hidden = true; this.hidden = true;
this.list = list; this.list = list;
this.items = []; this.items = [];
...@@ -576,7 +577,7 @@ require('./window')(function(w){ ...@@ -576,7 +577,7 @@ require('./window')(function(w){
var isUpArrow = false; var isUpArrow = false;
var isDownArrow = false; var isDownArrow = false;
var removeHighlight = function removeHighlight(list) { var removeHighlight = function removeHighlight(list) {
var listItems = list.list.querySelectorAll('li'); var listItems = list.list.querySelectorAll('li:not(.divider)');
for(var i = 0; i < listItems.length; i++) { for(var i = 0; i < listItems.length; i++) {
listItems[i].classList.remove('dropdown-active'); listItems[i].classList.remove('dropdown-active');
} }
...@@ -589,8 +590,11 @@ require('./window')(function(w){ ...@@ -589,8 +590,11 @@ require('./window')(function(w){
if(!listItems[currentIndex-1]){ if(!listItems[currentIndex-1]){
currentIndex = currentIndex-1; currentIndex = currentIndex-1;
} }
if (listItems[currentIndex-1]) {
listItems[currentIndex-1].classList.add('dropdown-active'); listItems[currentIndex-1].classList.add('dropdown-active');
} }
}
}; };
var mousedown = function mousedown(e) { var mousedown = function mousedown(e) {
...@@ -617,6 +621,8 @@ require('./window')(function(w){ ...@@ -617,6 +621,8 @@ require('./window')(function(w){
var keydown = function keydown(e){ var keydown = function keydown(e){
var typedOn = e.target; var typedOn = e.target;
var dropdown = e.detail.hook.list;
currentIndex = dropdown.currentIndex;
isUpArrow = false; isUpArrow = false;
isDownArrow = false; isDownArrow = false;
...@@ -649,6 +655,7 @@ require('./window')(function(w){ ...@@ -649,6 +655,7 @@ require('./window')(function(w){
if(isDownArrow){ currentIndex++; } if(isDownArrow){ currentIndex++; }
if(currentIndex < 0){ currentIndex = 0; } if(currentIndex < 0){ currentIndex = 0; }
setMenuForArrows(e.detail.hook.list); setMenuForArrows(e.detail.hook.list);
dropdown.currentIndex = currentIndex;
}; };
w.addEventListener('mousedown.dl', mousedown); w.addEventListener('mousedown.dl', mousedown);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment