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