Chore: replace includes with indexOf

This commit is contained in:
Leopoldthecoder 2017-11-12 11:56:41 +08:00 committed by 杨奕
parent 1833db26d8
commit 64f154839c
3 changed files with 9 additions and 9 deletions

View File

@ -186,7 +186,7 @@
// keydown up/down/left/right/enter
events.on.keydown = (ev) => {
const keyCode = ev.keyCode;
if (![37, 38, 39, 40, 13, 9, 27].includes(keyCode)) {
if (![37, 38, 39, 40, 13, 9, 27].indexOf(keyCode) > -1) {
return;
}
const currentEle = ev.target;
@ -194,7 +194,7 @@
const menuItemList = parentEle.querySelectorAll("[tabindex='-1']");
const currentIndex = Array.prototype.indexOf.call(menuItemList, currentEle); //
let nextIndex, nextMenu;
if ([38, 40].includes(keyCode)) {
if ([38, 40].indexOf(keyCode) > -1) {
if (keyCode === 38) { // up
nextIndex = currentIndex !== 0 ? (currentIndex - 1) : currentIndex;
} else if (keyCode === 40) { // down

View File

@ -132,7 +132,7 @@
},
handleTriggerKeyDown(ev) {
const keyCode = ev.keyCode;
if ([38, 40].includes(keyCode)) { // up/down
if ([38, 40].indexOf(keyCode) > -1) { // up/down
this.removeTabindex();
this.resetTabindex(this.menuItems[0]);
this.menuItems[0].focus();
@ -140,7 +140,7 @@
ev.stopPropagation();
} else if (keyCode === 13) { // space enter
this.handleClick();
} else if ([9, 27].includes(keyCode)) { // tab || esc
} else if ([9, 27].indexOf(keyCode) > -1) { // tab || esc
this.hide();
}
return;
@ -151,7 +151,7 @@
const currentIndex = this.menuItemsArray.indexOf(target);
const max = this.menuItemsArray.length - 1;
let nextIndex;
if ([38, 40].includes(keyCode)) { // up/down
if ([38, 40].indexOf(keyCode) > -1) { // up/down
if (keyCode === 38) { // up
nextIndex = currentIndex !== 0 ? currentIndex - 1 : 0;
} else { // down
@ -168,7 +168,7 @@
if (!this.hideOnClick) { // click
this.visible = false;
}
} else if ([9, 27].includes(keyCode)) { // tab // esc
} else if ([9, 27].indexOf(keyCode) > -1) { // tab // esc
this.hide();
this.triggerElm.focus();
}

View File

@ -202,7 +202,7 @@
this.treeItems = this.$el.querySelectorAll('.is-focusable[role=treeitem]');
const currentIndex = this.treeItemArray.indexOf(currentItem);
let nextIndex;
if ([38, 40].includes(keyCode)) { // updown
if ([38, 40].indexOf(keyCode) > -1) { // updown
if (keyCode === 38) { // up
nextIndex = currentIndex !== 0 ? currentIndex - 1 : 0;
} else {
@ -211,10 +211,10 @@
this.treeItemArray[nextIndex].focus(); //
}
const hasInput = currentItem.querySelector('[type="checkbox"]');
if ([37, 39].includes(keyCode)) { // leftright
if ([37, 39].indexOf(keyCode) > -1) { // leftright
currentItem.click(); //
}
if ([13, 32].includes(keyCode)) { // space entercheckbox
if ([13, 32].indexOf(keyCode) > -1) { // space entercheckbox
if (hasInput) {
hasInput.click();
}