Skip to content

Commit 2f14b98

Browse files
authored
UX: add hover delay to reduce annoyance (#2)
1 parent b1c8238 commit 2f14b98

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

javascripts/discourse/components/topic-list-tooltip.gjs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import Component from "@glimmer/component";
22
import { getOwner } from "@ember/owner";
3+
import { cancel } from "@ember/runloop";
34
import { htmlSafe } from "@ember/template";
45
import replaceEmoji from "discourse/helpers/replace-emoji";
6+
import discourseLater from "discourse/lib/later";
57
import DTooltip from "float-kit/components/d-tooltip";
68

79
const triggers = {
810
mobile: ["hover"],
911
desktop: ["hover"],
1012
};
1113

14+
const MILLISECONDS_PER_SECOND = 1000;
15+
1216
let TABLE_AI_LAYOUT = "table-ai";
1317
import("discourse/plugins/discourse-ai/discourse/services/gists")
1418
.then((module) => {
@@ -19,6 +23,23 @@ import("discourse/plugins/discourse-ai/discourse/services/gists")
1923
});
2024

2125
export default class TopicListTooltip extends Component {
26+
hoverTimeout = null;
27+
28+
beforeTrigger = async () => {
29+
this.cancelPending();
30+
31+
return new Promise((resolve) => {
32+
this.hoverTimeout = discourseLater(() => {
33+
this.hoverTimeout = null;
34+
resolve();
35+
}, settings.hover_delay_seconds * MILLISECONDS_PER_SECOND);
36+
});
37+
};
38+
39+
onClose = () => {
40+
this.cancelPending();
41+
};
42+
2243
get gistsService() {
2344
try {
2445
return getOwner(this).lookup("service:gists");
@@ -65,12 +86,21 @@ export default class TopicListTooltip extends Component {
6586
return null;
6687
}
6788

89+
cancelPending() {
90+
if (this.hoverTimeout) {
91+
cancel(this.hoverTimeout);
92+
this.hoverTimeout = null;
93+
}
94+
}
95+
6896
<template>
6997
{{#if this.shouldShowTooltip}}
7098
<DTooltip
7199
@triggers={{triggers}}
72100
@untriggers={{triggers}}
73101
@placement="bottom-start"
102+
@beforeTrigger={{this.beforeTrigger}}
103+
@onClose={{this.onClose}}
74104
>
75105
<:trigger>
76106
{{yield}}

settings.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,10 @@ tooltip_content:
44
choices:
55
- first_post_excerpt
66
- ai_topic_gist
7+
8+
hover_delay_seconds:
9+
type: float
10+
default: 0.25
11+
min: 0
12+
max: 2.0
13+
description: "Delay in seconds before showing the tooltip on hover (helps prevent tooltips from appearing during scrolling)"

0 commit comments

Comments
 (0)