@@ -3,11 +3,9 @@ import tippy from 'tippy.js';
3
3
const visibleInstances = new Set ( ) ;
4
4
5
5
export function createTippy ( target , opts = { } ) {
6
- const { role, content, onHide : optsOnHide , onDestroy : optsOnDestroy , onShow : optOnShow } = opts ;
7
- delete opts . onHide ;
8
- delete opts . onDestroy ;
9
- delete opts . onShow ;
10
-
6
+ // the callback functions should be destructured from opts,
7
+ // because we should use our own wrapper functions to handle them, do not let the user override them
8
+ const { onHide, onShow, onDestroy, ...other } = opts ;
11
9
const instance = tippy ( target , {
12
10
appendTo : document . body ,
13
11
animation : false ,
@@ -18,11 +16,11 @@ export function createTippy(target, opts = {}) {
18
16
maxWidth : 500 , // increase over default 350px
19
17
onHide : ( instance ) => {
20
18
visibleInstances . delete ( instance ) ;
21
- return optsOnHide ?. ( instance ) ;
19
+ return onHide ?. ( instance ) ;
22
20
} ,
23
21
onDestroy : ( instance ) => {
24
22
visibleInstances . delete ( instance ) ;
25
- return optsOnDestroy ?. ( instance ) ;
23
+ return onDestroy ?. ( instance ) ;
26
24
} ,
27
25
onShow : ( instance ) => {
28
26
// hide other tooltip instances so only one tooltip shows at a time
@@ -32,19 +30,19 @@ export function createTippy(target, opts = {}) {
32
30
}
33
31
}
34
32
visibleInstances . add ( instance ) ;
35
- return optOnShow ?. ( instance ) ;
33
+ return onShow ?. ( instance ) ;
36
34
} ,
37
35
arrow : `<svg width="16" height="7"><path d="m0 7 8-7 8 7Z" class="tippy-svg-arrow-outer"/><path d="m0 8 8-7 8 7Z" class="tippy-svg-arrow-inner"/></svg>` ,
38
36
role : 'menu' , // HTML role attribute, only tooltips should use "tooltip"
39
- theme : role || 'menu' , // CSS theme, we support either "tooltip" or "menu"
40
- ...opts ,
37
+ theme : other . role || 'menu' , // CSS theme, we support either "tooltip" or "menu"
38
+ ...other ,
41
39
} ) ;
42
40
43
41
// for popups where content refers to a DOM element, we use the 'tippy-target' class
44
42
// to initially hide the content, now we can remove it as the content has been removed
45
43
// from the DOM by tippy
46
- if ( content instanceof Element ) {
47
- content . classList . remove ( 'tippy-target' ) ;
44
+ if ( other . content instanceof Element ) {
45
+ other . content . classList . remove ( 'tippy-target' ) ;
48
46
}
49
47
50
48
return instance ;
0 commit comments