From 64f154839cc716b0bf6db91e2a03bb83b641936d Mon Sep 17 00:00:00 2001 From: Leopoldthecoder Date: Sun, 12 Nov 2017 11:56:41 +0800 Subject: [PATCH] Chore: replace includes with indexOf --- packages/cascader/src/menu.vue | 4 ++-- packages/dropdown/src/dropdown.vue | 8 ++++---- packages/tree/src/tree.vue | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/cascader/src/menu.vue b/packages/cascader/src/menu.vue index 09aeb007..70a4bd3c 100644 --- a/packages/cascader/src/menu.vue +++ b/packages/cascader/src/menu.vue @@ -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 diff --git a/packages/dropdown/src/dropdown.vue b/packages/dropdown/src/dropdown.vue index aceee1b6..9125c296 100644 --- a/packages/dropdown/src/dropdown.vue +++ b/packages/dropdown/src/dropdown.vue @@ -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(); } diff --git a/packages/tree/src/tree.vue b/packages/tree/src/tree.vue index 32dce3e7..43ad448c 100644 --- a/packages/tree/src/tree.vue +++ b/packages/tree/src/tree.vue @@ -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(); }