diff --git a/src/components/Tooltip/Tooltip.vue b/src/components/Tooltip/Tooltip.vue index 00aab9f6..93640d6d 100644 --- a/src/components/Tooltip/Tooltip.vue +++ b/src/components/Tooltip/Tooltip.vue @@ -2,15 +2,21 @@
- + + + + + {{ label }} + + + + + +
- - - {{ label }} - -
@@ -23,48 +29,58 @@ props: { label: { type: String, - required: true }, placement: { type: String, - default: 'bottom' + default: 'bottom', }, disabled: { type: Boolean, - default: false + default: false, }, offset: { type: String, - default: '0,5' + default: '0,5', }, appendToBody: { type: Boolean, - default: false + default: false, }, boundariesElement: { type: String, - default: 'viewport' - } + default: 'viewport', + }, + delay: { + type: Number, + default: 0, + }, }, data() { return { - show: false + timeoutId: undefined, + show: false, }; }, methods: { onMouseEnter() { - this.show = true; - if (this.appendToBody) { - this.$nextTick(() => { - this.append(); - }); - } + if (this.timeoutId) clearTimeout(this.timeoutId); + this.timeoutId = setTimeout(() => { + this.show = true; + if (this.appendToBody) { + this.$nextTick(() => { + this.append(); + }); + } + }, this.delay); }, onMouseLeave() { - if (this.appendToBody) { - document.body.removeChild(this.$refs.label); - } - this.show = false; + if (this.timeoutId) clearTimeout(this.timeoutId); + this.timeoutId = setTimeout(() => { + if (this.appendToBody) { + document.body.removeChild(this.$refs.label); + } + this.show = false; + }, this.delay); }, append() { document.body.appendChild(this.$refs.label); @@ -73,8 +89,8 @@ this.$refs.popper.update(); } }, 0); - } - } + }, + }, }; @@ -92,12 +108,15 @@ font-weight: 400; box-shadow: 0 1px 2px 1px rgba(0, 1, 0, 0.2); white-space: nowrap; - pointer-events: none; border-radius: 3px; background-color: var(--ds-background-neutral-bold, #172b4d); color: var(--ds-text-inverse, #FFF); } +.no-click { + pointer-events: none; +} + .fade-enter-active, .fade-leave-active { transition: opacity 0.3s; diff --git a/stories/Tooltip/TooltipWithHtmlLabel.story.vue b/stories/Tooltip/TooltipWithHtmlLabel.story.vue new file mode 100644 index 00000000..ff6382b3 --- /dev/null +++ b/stories/Tooltip/TooltipWithHtmlLabel.story.vue @@ -0,0 +1,37 @@ + + + +