Skip to content
This repository was archived by the owner on Dec 15, 2023. It is now read-only.

Commit f18dea0

Browse files
DT 40 Tooltip tests (#178)
* add documentation for Tippy tooltip * update reactive "show" * update tests * update tests * resolve comments * resolve comments
1 parent aeb1bde commit f18dea0

File tree

4 files changed

+147
-95
lines changed

4 files changed

+147
-95
lines changed

.esplint.rec.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@
3737
},
3838
"components/tooltip/tooltip-tippy-headless.vue": {
3939
"vue/no-deprecated-destroyed-lifecycle": 1
40+
},
41+
"components/tooltip/tooltip_tippy_default.story.vue": {
42+
"vue/no-deprecated-v-bind-sync": 1
43+
},
44+
"components/tooltip/tooltip_tippy_flip.story.vue": {
45+
"vue/no-deprecated-v-bind-sync": 1
4046
}
4147
}
4248
}

components/tooltip/tooltip-tippy-headless.vue

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<template>
2-
<div>
3-
<div ref="anchor">
2+
<div data-qa="dt-tooltip-container">
3+
<div
4+
ref="anchor"
5+
data-qa="dt-tooltip-anchor"
6+
>
47
<slot
58
name="anchor"
69
:attrs="{
@@ -204,28 +207,32 @@ export default {
204207
deep: true,
205208
},
206209
207-
show () {
208-
if (this.tip) {
209-
this.show ? this.tip.show() : this.tip.hide();
210-
}
211-
},
210+
arrowDirection: 'setProps',
211+
212+
show: 'toggleTooltip',
212213
},
213214
214215
mounted () {
215216
const anchorElement = this.$refs.anchor.children[0];
216217
const anchor = anchorElement || this.createAnchor();
217218
this.placement = this.arrowDirection;
218219
this.tip = tippy(anchor, this.initOptions());
219-
if (this.show) {
220-
this.tip.show();
221-
}
220+
this.toggleTooltip();
222221
},
223222
224223
beforeDestroy () {
225-
this.tip?.destroy();
224+
if (this.tip) {
225+
this.tip.destroy();
226+
}
226227
},
227228
228229
methods: {
230+
toggleTooltip () {
231+
if (this.tip) {
232+
this.show ? this.tip.show() : this.tip.hide();
233+
}
234+
},
235+
229236
createAnchor () {
230237
const span = document.createElement('span');
231238
span.setAttribute('tabindex', '0');
@@ -237,10 +244,12 @@ export default {
237244
238245
setProps () {
239246
this.placement = this.arrowDirection;
240-
this.tip?.setProps({
241-
...this.tippyProps,
242-
placement: this.tippyPlacement,
243-
});
247+
if (this.tip && this.tip.setProps) {
248+
this.tip.setProps({
249+
...this.tippyProps,
250+
placement: this.tippyPlacement,
251+
});
252+
}
244253
},
245254
246255
getPopperOptions () {
@@ -267,10 +276,20 @@ export default {
267276
};
268277
},
269278
279+
onMount () {
280+
this.$emit('update:show', true);
281+
},
282+
283+
onHide () {
284+
this.$emit('update:show', false);
285+
},
286+
270287
initOptions () {
271288
return {
272289
allowHTML: true,
273290
placement: this.tippyPlacement,
291+
onMount: this.onMount,
292+
onHide: this.onHide,
274293
...this.tippyProps,
275294
render: () => {
276295
// The recommended structure is to use the popper as an outer wrapper

0 commit comments

Comments
 (0)