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

View File

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

View File

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