diff --git a/packages/menu/src/menu-mixin.js b/packages/menu/src/menu-mixin.js index 56479bbb..27ce8894 100644 --- a/packages/menu/src/menu-mixin.js +++ b/packages/menu/src/menu-mixin.js @@ -1,8 +1,8 @@ export default { computed: { indexPath() { - var path = [this.index]; - var parent = this.$parent; + const path = [this.index]; + let parent = this.$parent; while (parent.$options.componentName !== 'ElMenu') { if (parent.index) { path.unshift(parent.index); @@ -12,7 +12,7 @@ export default { return path; }, rootMenu() { - var parent = this.$parent; + let parent = this.$parent; while ( parent && parent.$options.componentName !== 'ElMenu' diff --git a/packages/menu/src/menu.vue b/packages/menu/src/menu.vue index b8a6f48f..e0d420ed 100644 --- a/packages/menu/src/menu.vue +++ b/packages/menu/src/menu.vue @@ -262,9 +262,8 @@ this.$on('item-click', this.handleItemClick); this.$on('submenu-click', this.handleSubmenuClick); if (this.mode === 'horizontal') { - let menu = new Menubar(this.$el); // eslint-disable-line + new Menubar(this.$el); // eslint-disable-line } - } }; diff --git a/src/utils/menu/aria-menubar.js b/src/utils/menu/aria-menubar.js index d7c6fd0f..a5edc503 100644 --- a/src/utils/menu/aria-menubar.js +++ b/src/utils/menu/aria-menubar.js @@ -1,14 +1,14 @@ import MenuItem from './aria-menuitem'; -var menu = function(domNode) { +const Menu = function(domNode) { this.domNode = domNode; this.init(); }; -menu.prototype.init = function() { - let menuChild = this.domNode.childNodes; - menuChild.forEach((child) => { - let menuItem = new MenuItem(child); // eslint-disable-line +Menu.prototype.init = function() { + let menuChildren = this.domNode.childNodes; + [].filter.call(menuChildren, child => child.nodeType === 1).forEach(child => { + new MenuItem(child); // eslint-disable-line }); }; -export default menu; +export default Menu; diff --git a/src/utils/menu/aria-menuitem.js b/src/utils/menu/aria-menuitem.js index d31027a8..8cff9ea7 100644 --- a/src/utils/menu/aria-menuitem.js +++ b/src/utils/menu/aria-menuitem.js @@ -1,13 +1,13 @@ import Utils from '../aria-utils'; import SubMenu from './aria-submenu'; -var menuItem = function(domNode) { +const MenuItem = function(domNode) { this.domNode = domNode; this.submenu = null; this.init(); }; -menuItem.prototype.init = function() { +MenuItem.prototype.init = function() { this.domNode.setAttribute('tabindex', '0'); let menuChild = this.domNode.querySelector('.el-menu'); if (menuChild) { @@ -16,34 +16,34 @@ menuItem.prototype.init = function() { this.addListeners(); }; -menuItem.prototype.addListeners = function() { +MenuItem.prototype.addListeners = function() { const keys = Utils.keys; this.domNode.addEventListener('keydown', event => { - var prevdef = false; + let prevDef = false; switch (event.keyCode) { case keys.down: Utils.triggerEvent(event.currentTarget, 'mouseenter'); this.submenu.gotoSubIndex(0); - prevdef = true; + prevDef = true; break; case keys.up: Utils.triggerEvent(event.currentTarget, 'mouseenter'); this.submenu.gotoSubIndex(this.submenu.subMenuItems.length - 1); - prevdef = true; + prevDef = true; break; case keys.tab: Utils.triggerEvent(event.currentTarget, 'mouseleave'); break; case keys.enter: case keys.space: - prevdef = true; + prevDef = true; event.currentTarget.click(); break; } - if (prevdef) { + if (prevDef) { event.preventDefault(); } }); }; -export default menuItem; +export default MenuItem; diff --git a/src/utils/menu/aria-submenu.js b/src/utils/menu/aria-submenu.js index d8168aea..06a77bbc 100644 --- a/src/utils/menu/aria-submenu.js +++ b/src/utils/menu/aria-submenu.js @@ -1,6 +1,6 @@ import Utils from '../aria-utils'; -var Menu = function(parent, domNode) { +const SubMenu = function(parent, domNode) { this.domNode = domNode; this.parent = parent; this.subMenuItems = []; @@ -8,12 +8,12 @@ var Menu = function(parent, domNode) { this.init(); }; -Menu.prototype.init = function() { +SubMenu.prototype.init = function() { this.subMenuItems = this.domNode.querySelectorAll('li'); this.addListeners(); }; -Menu.prototype.gotoSubIndex = function(idx) { +SubMenu.prototype.gotoSubIndex = function(idx) { if (idx === this.subMenuItems.length) { idx = 0; } else if (idx < 0) { @@ -23,31 +23,31 @@ Menu.prototype.gotoSubIndex = function(idx) { this.subIndex = idx; }; -Menu.prototype.addListeners = function() { +SubMenu.prototype.addListeners = function() { const keys = Utils.keys; const parentNode = this.parent.domNode; Array.prototype.forEach.call(this.subMenuItems, el => { el.addEventListener('keydown', event => { - let prevdef = false; + let prevDef = false; switch (event.keyCode) { case keys.down: this.gotoSubIndex(this.subIndex + 1); - prevdef = true; + prevDef = true; break; case keys.up: this.gotoSubIndex(this.subIndex - 1); - prevdef = true; + prevDef = true; break; case keys.tab: Utils.triggerEvent(parentNode, 'mouseleave'); break; case keys.enter: case keys.space: - prevdef = true; + prevDef = true; event.currentTarget.click(); break; } - if (prevdef) { + if (prevDef) { event.preventDefault(); event.stopPropagation(); } @@ -56,4 +56,4 @@ Menu.prototype.addListeners = function() { }); }; -export default Menu; +export default SubMenu;