mirror of
https://gitee.com/ElemeFE/element.git
synced 2024-12-02 04:08:10 +08:00
Menu: fix setAttribute error
This commit is contained in:
parent
399161eacc
commit
186143b138
@ -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'
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user