@@ -3,11 +3,9 @@ import tippy from 'tippy.js';
33const visibleInstances = new Set ( ) ;
44
55export 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 ;
119 const instance = tippy ( target , {
1210 appendTo : document . body ,
1311 animation : false ,
@@ -18,11 +16,11 @@ export function createTippy(target, opts = {}) {
1816 maxWidth : 500 , // increase over default 350px
1917 onHide : ( instance ) => {
2018 visibleInstances . delete ( instance ) ;
21- return optsOnHide ?. ( instance ) ;
19+ return onHide ?. ( instance ) ;
2220 } ,
2321 onDestroy : ( instance ) => {
2422 visibleInstances . delete ( instance ) ;
25- return optsOnDestroy ?. ( instance ) ;
23+ return onDestroy ?. ( instance ) ;
2624 } ,
2725 onShow : ( instance ) => {
2826 // hide other tooltip instances so only one tooltip shows at a time
@@ -32,19 +30,19 @@ export function createTippy(target, opts = {}) {
3230 }
3331 }
3432 visibleInstances . add ( instance ) ;
35- return optOnShow ?. ( instance ) ;
33+ return onShow ?. ( instance ) ;
3634 } ,
3735 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>` ,
3836 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 ,
4139 } ) ;
4240
4341 // for popups where content refers to a DOM element, we use the 'tippy-target' class
4442 // to initially hide the content, now we can remove it as the content has been removed
4543 // 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' ) ;
4846 }
4947
5048 return instance ;
0 commit comments