Skip to content

Commit 1795628

Browse files
BijinDevhrb-hub
andcommitted
Don't close snackbar if it is hovered
close #9534 Co-authored-by: hrb-hub <[email protected]>
1 parent b7ee82b commit 1795628

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

src/common/gui/base/SnackBar.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ export type SnackBarButtonAttrs = {
2121
type SnackBarAttrs = {
2222
message: MaybeTranslation
2323
button: ButtonAttrs | null
24+
onHoverChange: (hovered: boolean) => void
2425
}
25-
type QueueItem = SnackBarAttrs & {
26+
type QueueItem = Omit<SnackBarAttrs, "onHoverChange"> & {
2627
onClose: ((timedOut: boolean) => unknown) | null
2728
onShow: (() => unknown) | null
2829
doCancel: { cancel: () => unknown }
@@ -36,10 +37,21 @@ let cancelCurrentSnackbar: (() => unknown) | null = null
3637
class SnackBar implements Component<SnackBarAttrs> {
3738
view(vnode: Vnode<SnackBarAttrs>) {
3839
// use same padding as MinimizedEditor
39-
return m(".snackbar-content.flex.flex-space-between.border-radius.plr.pb-xs.pt-xs", [
40-
m(".flex.center-vertically.smaller", lang.getTranslationText(vnode.attrs.message)),
41-
vnode.attrs.button ? m(".flex-end.center-vertically.pl", m(Button, vnode.attrs.button)) : null,
42-
])
40+
return m(
41+
".snackbar-content.flex.flex-space-between.border-radius.plr.pb-xs.pt-xs",
42+
{
43+
onmouseenter: () => {
44+
vnode.attrs.onHoverChange(true)
45+
},
46+
onmouseleave: () => {
47+
vnode.attrs.onHoverChange(false)
48+
},
49+
},
50+
[
51+
m(".flex.center-vertically.smaller", lang.getTranslationText(vnode.attrs.message)),
52+
vnode.attrs.button ? m(".flex-end.center-vertically.pl", m(Button, vnode.attrs.button)) : null,
53+
],
54+
)
4355
}
4456
}
4557

@@ -147,13 +159,18 @@ function showNextNotification() {
147159
const { message, button, onClose, onShow, doCancel, showingTime } = notificationQueue[0] //we shift later because it is still shown
148160
clearTimeout(currentAnimationTimeout)
149161
currentAnimationTimeout = null
162+
let hovered = false
163+
150164
const closeFunction = displayOverlay(
151165
() => getSnackBarPosition(),
152166
{
153167
view: () =>
154168
m(SnackBar, {
155169
message,
156170
button,
171+
onHoverChange: (isHovered) => {
172+
hovered = isHovered
173+
},
157174
}),
158175
},
159176
"slide-bottom",
@@ -164,6 +181,11 @@ function showNextNotification() {
164181
let closed = false
165182

166183
const closeAndOpenNext = (timedOut: boolean) => {
184+
if (timedOut && hovered) {
185+
debounce(1000, closeAndOpenNext)(true)
186+
return
187+
}
188+
167189
closed = true
168190
cancelCurrentSnackbar = null
169191

0 commit comments

Comments
 (0)