Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit bcd0733

Browse files
authoredMay 11, 2023
Only show one tippy at a time (#24648)
Because our tippy instances have an `interactiveBorder`, it's possible to bring up two instances at once, which is undesirable. <img width="256" alt="Screenshot 2023-05-10 at 23 03 04" src="https://github.com/go-gitea/gitea/assets/115237/3a9a1775-78c1-46d4-a8a5-503ab7dca0d8"> Prevent this by keeping track of visible tippy instances and hiding others when one is shown. Tippy also has the [singleton addon](https://atomiks.github.io/tippyjs/v6/addons/#singleton) for the same purpose, but it's unsuitable to us because we don't init all tooltips at once.
1 parent 3d9ed62 commit bcd0733

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
 

‎web_src/js/modules/tippy.js

+14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import tippy from 'tippy.js';
22

3+
const visibleInstances = new Set();
4+
35
export function createTippy(target, opts = {}) {
46
const instance = tippy(target, {
57
appendTo: document.body,
@@ -9,6 +11,18 @@ export function createTippy(target, opts = {}) {
911
interactiveBorder: 20,
1012
ignoreAttributes: true,
1113
maxWidth: 500, // increase over default 350px
14+
onHide: (instance) => {
15+
visibleInstances.delete(instance);
16+
},
17+
onDestroy: (instance) => {
18+
visibleInstances.delete(instance);
19+
},
20+
onShow: (instance) => {
21+
for (const visibleInstance of visibleInstances) {
22+
visibleInstance.hide(); // hide other instances
23+
}
24+
visibleInstances.add(instance);
25+
},
1226
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>`,
1327
...(opts?.role && {theme: opts.role}),
1428
...opts,

0 commit comments

Comments
 (0)
Please sign in to comment.