Dropdown add custom and visible prop

Dropdown add custom and visible prop
This commit is contained in:
梁灏 2017-01-13 11:32:56 +08:00
parent d509d2b2af
commit 51f9f894eb

View file

@ -22,7 +22,7 @@
props: { props: {
trigger: { trigger: {
validator (value) { validator (value) {
return oneOf(value, ['click', 'hover']); return oneOf(value, ['click', 'hover', 'custom']);
}, },
default: 'hover' default: 'hover'
}, },
@ -31,6 +31,10 @@
return oneOf(value, ['top', 'top-start', 'top-end', 'bottom', 'bottom-start', 'bottom-end', 'left', 'left-start', 'left-end', 'right', 'right-start', 'right-end']); return oneOf(value, ['top', 'top-start', 'top-end', 'bottom', 'bottom-start', 'bottom-end', 'left', 'left-start', 'left-end', 'right', 'right-start', 'right-end']);
}, },
default: 'bottom' default: 'bottom'
},
visible: {
type: Boolean,
default: false
} }
}, },
computed: { computed: {
@ -40,18 +44,19 @@
}, },
data () { data () {
return { return {
prefixCls: prefixCls, prefixCls: prefixCls
visible: false
}; };
}, },
methods: { methods: {
handleClick () { handleClick () {
if (this.trigger === 'custom') return false;
if (this.trigger !== 'click') { if (this.trigger !== 'click') {
return false; return false;
} }
this.visible = !this.visible; this.visible = !this.visible;
}, },
handleMouseenter () { handleMouseenter () {
if (this.trigger === 'custom') return false;
if (this.trigger !== 'hover') { if (this.trigger !== 'hover') {
return false; return false;
} }
@ -61,6 +66,7 @@
}, 250); }, 250);
}, },
handleMouseleave () { handleMouseleave () {
if (this.trigger === 'custom') return false;
if (this.trigger !== 'hover') { if (this.trigger !== 'hover') {
return false; return false;
} }
@ -70,6 +76,7 @@
}, 150); }, 150);
}, },
handleClose () { handleClose () {
if (this.trigger === 'custom') return false;
if (this.trigger !== 'click') { if (this.trigger !== 'click') {
return false; return false;
} }
@ -103,17 +110,20 @@
const $parent = this.hasParent(); const $parent = this.hasParent();
if ($parent) { if ($parent) {
this.$nextTick(() => { this.$nextTick(() => {
if (this.trigger === 'custom') return false;
this.visible = false; this.visible = false;
}); });
$parent.$emit('on-hover-click'); $parent.$emit('on-hover-click');
} else { } else {
this.$nextTick(() => { this.$nextTick(() => {
if (this.trigger === 'custom') return false;
this.visible = false; this.visible = false;
}); });
} }
}, },
'on-haschild-click' () { 'on-haschild-click' () {
this.$nextTick(() => { this.$nextTick(() => {
if (this.trigger === 'custom') return false;
this.visible = true; this.visible = true;
}); });
const $parent = this.hasParent(); const $parent = this.hasParent();