dropdown: reactive disabled trigger element

pull/6972/head
Leopoldthecoder 2017-09-12 11:19:15 +08:00 committed by 杨奕
parent 8fc973c51a
commit bd7ef92583
1 changed files with 9 additions and 6 deletions

View File

@ -39,7 +39,8 @@
data() {
return {
timeout: null,
visible: false
visible: false,
triggerElm: null
};
},
@ -57,37 +58,39 @@
methods: {
show() {
if (this.triggerElm.disabled) return;
clearTimeout(this.timeout);
this.timeout = setTimeout(() => {
this.visible = true;
}, 250);
},
hide() {
if (this.triggerElm.disabled) return;
clearTimeout(this.timeout);
this.timeout = setTimeout(() => {
this.visible = false;
}, 150);
},
handleClick() {
if (this.triggerElm.disabled) return;
this.visible = !this.visible;
},
initEvent() {
let { trigger, show, hide, handleClick, splitButton } = this;
let triggerElm = splitButton
this.triggerElm = splitButton
? this.$refs.trigger.$el
: this.$slots.default[0].elm;
if (triggerElm.disabled) return;
if (trigger === 'hover') {
triggerElm.addEventListener('mouseenter', show);
triggerElm.addEventListener('mouseleave', hide);
this.triggerElm.addEventListener('mouseenter', show);
this.triggerElm.addEventListener('mouseleave', hide);
let dropdownElm = this.$slots.dropdown[0].elm;
dropdownElm.addEventListener('mouseenter', show);
dropdownElm.addEventListener('mouseleave', hide);
} else if (trigger === 'click') {
triggerElm.addEventListener('click', handleClick);
this.triggerElm.addEventListener('click', handleClick);
}
},
handleMenuItemClick(command, instance) {