Commit bd7ef925 authored by Leopoldthecoder's avatar Leopoldthecoder Committed by 杨奕

dropdown: reactive disabled trigger element

parent 8fc973c5
...@@ -39,7 +39,8 @@ ...@@ -39,7 +39,8 @@
data() { data() {
return { return {
timeout: null, timeout: null,
visible: false visible: false,
triggerElm: null
}; };
}, },
...@@ -57,37 +58,39 @@ ...@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment