Cascader: fix active-item-change event

This commit is contained in:
Leopoldthecoder 2017-11-15 12:03:50 +08:00 committed by 杨奕
parent 292ad8efec
commit bd55a5a593

View File

@ -41,7 +41,8 @@
expandTrigger: 'click', expandTrigger: 'click',
changeOnSelect: false, changeOnSelect: false,
popperClass: '', popperClass: '',
hoverTimer: 0 hoverTimer: 0,
clicking: false
}; };
}, },
@ -148,9 +149,11 @@
let hoverMenuRefs = {}; let hoverMenuRefs = {};
const hoverMenuHandler = e => { const hoverMenuHandler = e => {
const activeMenu = hoverMenuRefs.activeMenu;
if (!activeMenu) return;
const offsetX = e.offsetX; const offsetX = e.offsetX;
const width = hoverMenuRefs.activeMenu.offsetWidth; const width = activeMenu.offsetWidth;
const height = hoverMenuRefs.activeMenu.offsetHeight; const height = activeMenu.offsetHeight;
if (e.target === hoverMenuRefs.activeItem) { if (e.target === hoverMenuRefs.activeItem) {
clearTimeout(this.hoverTimer); clearTimeout(this.hoverTimer);
@ -186,7 +189,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].indexOf(keyCode) > -1) { if ([37, 38, 39, 40, 13, 9, 27].indexOf(keyCode) < 0) {
return; return;
} }
const currentEle = ev.target; const currentEle = ev.target;
@ -228,7 +231,7 @@
click: 'click', click: 'click',
hover: 'mouseenter' hover: 'mouseenter'
}[expandTrigger]; }[expandTrigger];
events.on[triggerEvent] = events.on['focus'] = () => { // focus const triggerHandler = () => {
this.activeItem(item, menuIndex); this.activeItem(item, menuIndex);
this.$nextTick(() => { this.$nextTick(() => {
// adjust self and next level // adjust self and next level
@ -236,6 +239,17 @@
this.scrollMenu(this.$refs.menus[menuIndex + 1]); this.scrollMenu(this.$refs.menus[menuIndex + 1]);
}); });
}; };
events.on[triggerEvent] = triggerHandler;
events.on['mousedown'] = () => {
this.clicking = true;
};
events.on['focus'] = () => { // focus
if (this.clicking) {
this.clicking = false;
return;
}
triggerHandler();
};
} else { } else {
events.on.click = () => { events.on.click = () => {
this.select(item, menuIndex); this.select(item, menuIndex);