mirror of https://github.com/ElemeFE/element
Tooltip: displays when initial value is true (#14826)
parent
314e7fbaee
commit
afaec24a03
|
@ -1,7 +1,6 @@
|
||||||
import Popper from 'element-ui/src/utils/vue-popper';
|
import Popper from 'element-ui/src/utils/vue-popper';
|
||||||
import debounce from 'throttle-debounce/debounce';
|
import debounce from 'throttle-debounce/debounce';
|
||||||
import { addClass, removeClass, on, off } from 'element-ui/src/utils/dom';
|
import { addClass, removeClass, on, off } from 'element-ui/src/utils/dom';
|
||||||
import { getFirstComponentChild } from 'element-ui/src/utils/vdom';
|
|
||||||
import { generateId } from 'element-ui/src/utils/util';
|
import { generateId } from 'element-ui/src/utils/util';
|
||||||
import Vue from 'vue';
|
import Vue from 'vue';
|
||||||
|
|
||||||
|
@ -54,15 +53,11 @@ export default {
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
tooltipId: `el-tooltip-${generateId()}`,
|
||||||
timeoutPending: null,
|
timeoutPending: null,
|
||||||
focusing: false
|
focusing: false
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
|
||||||
tooltipId() {
|
|
||||||
return `el-tooltip-${generateId()}`;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
beforeCreate() {
|
beforeCreate() {
|
||||||
if (this.$isServer) return;
|
if (this.$isServer) return;
|
||||||
|
|
||||||
|
@ -98,16 +93,13 @@ export default {
|
||||||
</transition>);
|
</transition>);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.$slots.default || !this.$slots.default.length) return this.$slots.default;
|
const firstElement = this.getFirstElement();
|
||||||
|
if (!firstElement) return null;
|
||||||
|
|
||||||
const vnode = getFirstComponentChild(this.$slots.default);
|
const data = firstElement.data = firstElement.data || {};
|
||||||
|
data.staticClass = this.addTooltipClass(data.staticClass);
|
||||||
|
|
||||||
if (!vnode) return vnode;
|
return firstElement;
|
||||||
|
|
||||||
const data = vnode.data = vnode.data || {};
|
|
||||||
data.staticClass = this.concatClass(data.staticClass, 'el-tooltip');
|
|
||||||
|
|
||||||
return vnode;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
|
@ -132,6 +124,14 @@ export default {
|
||||||
on(this.referenceElm, 'blur', this.handleBlur);
|
on(this.referenceElm, 'blur', this.handleBlur);
|
||||||
on(this.referenceElm, 'click', this.removeFocusing);
|
on(this.referenceElm, 'click', this.removeFocusing);
|
||||||
}
|
}
|
||||||
|
// fix issue https://github.com/ElemeFE/element/issues/14424
|
||||||
|
if (this.value && this.popperVM) {
|
||||||
|
this.popperVM.$nextTick(() => {
|
||||||
|
if (this.value) {
|
||||||
|
this.updatePopper();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
focusing(val) {
|
focusing(val) {
|
||||||
|
@ -164,9 +164,12 @@ export default {
|
||||||
this.focusing = false;
|
this.focusing = false;
|
||||||
},
|
},
|
||||||
|
|
||||||
concatClass(a, b) {
|
addTooltipClass(prev) {
|
||||||
if (a && a.indexOf(b) > -1) return a;
|
if (!prev) {
|
||||||
return a ? b ? (a + ' ' + b) : a : (b || '');
|
return 'el-tooltip';
|
||||||
|
} else {
|
||||||
|
return 'el-tooltip ' + prev.replace('el-tooltip', '');
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
handleShowPopper() {
|
handleShowPopper() {
|
||||||
|
@ -202,6 +205,18 @@ export default {
|
||||||
clearTimeout(this.timeoutPending);
|
clearTimeout(this.timeoutPending);
|
||||||
}
|
}
|
||||||
this.expectedState = expectedState;
|
this.expectedState = expectedState;
|
||||||
|
},
|
||||||
|
|
||||||
|
getFirstElement() {
|
||||||
|
const slots = this.$slots.default;
|
||||||
|
if (!Array.isArray(slots)) return null;
|
||||||
|
let element = null;
|
||||||
|
for (let index = 0; index < slots.length; index++) {
|
||||||
|
if (slots[index] && slots[index].tag) {
|
||||||
|
element = slots[index];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return element;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,3 @@ import { hasOwn } from 'element-ui/src/utils/util';
|
||||||
export function isVNode(node) {
|
export function isVNode(node) {
|
||||||
return node !== null && typeof node === 'object' && hasOwn(node, 'componentOptions');
|
return node !== null && typeof node === 'object' && hasOwn(node, 'componentOptions');
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getFirstComponentChild(children) {
|
|
||||||
return children && children.filter(c => c && c.tag)[0];
|
|
||||||
};
|
|
||||||
|
|
|
@ -70,9 +70,7 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
showPopper(val) {
|
showPopper(val) {
|
||||||
if (this.disabled) {
|
if (this.disabled) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
val ? this.updatePopper() : this.destroyPopper();
|
val ? this.updatePopper() : this.destroyPopper();
|
||||||
this.$emit('input', val);
|
this.$emit('input', val);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue