Commit 64f15483 authored by Leopoldthecoder's avatar Leopoldthecoder Committed by 杨奕

Chore: replace includes with indexOf

parent 1833db26
......@@ -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
......
......@@ -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();
}
......
......@@ -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)) { // up、down
if ([38, 40].indexOf(keyCode) > -1) { // up、down
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)) { // left、right 展开
if ([37, 39].indexOf(keyCode) > -1) { // left、right 展开
currentItem.click(); // 选中
}
if ([13, 32].includes(keyCode)) { // space enter选中checkbox
if ([13, 32].indexOf(keyCode) > -1) { // space enter选中checkbox
if (hasInput) {
hasInput.click();
}
......
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