Skip to content

Commit 3f4905d

Browse files
committed
[frontend] contentmenu tweaks
1 parent a41f413 commit 3f4905d

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

frontend/src/components/Menu.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ export const Menu: Component<{
66
y: number;
77
items: { label: string; action?: () => void }[];
88
}> = function (cx) {
9-
const close = () => {
9+
const close = (e: MouseEvent) => {
1010
cx.root.remove();
1111
browser.unfocusframes = false;
12+
13+
e.stopImmediatePropagation();
14+
e.preventDefault();
1215
};
1316

1417
cx.mount = () => {
@@ -20,8 +23,11 @@ export const Menu: Component<{
2023
if (this.x > maxX) this.x = maxX;
2124
if (this.y > maxY) this.y = maxY;
2225

23-
document.body.addEventListener("click", close, { once: true });
24-
document.body.addEventListener("contextmenu", close, { once: true });
26+
window.addEventListener("click", close, { once: true, capture: true });
27+
window.addEventListener("contextmenu", close, {
28+
once: true,
29+
capture: true,
30+
});
2531

2632
cx.root.addEventListener("click", (e) => {
2733
e.stopPropagation();
@@ -33,7 +39,7 @@ export const Menu: Component<{
3339
<button
3440
on:click={(e: MouseEvent) => {
3541
item.action?.();
36-
close();
42+
close(e);
3743
e.stopPropagation();
3844
}}
3945
>

frontend/src/components/TabStrip.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ export const DragTab: Component<
117117
e.stopPropagation();
118118
this.destroy();
119119
}}
120+
on:contextmenu={(e: MouseEvent) => {
121+
e.preventDefault();
122+
e.stopPropagation();
123+
}}
120124
>
121125
<Icon icon={iconClose} />
122126
</button>
@@ -209,6 +213,10 @@ DragTab.style = css`
209213
padding: 0;
210214
margin-left: 8px;
211215
}
216+
.close:hover {
217+
background: grey;
218+
border-radius: 0.5em;
219+
}
212220
213221
.main:not(.active):hover {
214222
transition: background 250ms;
@@ -475,7 +483,14 @@ export const Tabs: Component<
475483
tabcache
476484
)
477485
)}
478-
<div class="extra after" this={use(this.afterEl)}>
486+
<div
487+
class="extra after"
488+
this={use(this.afterEl)}
489+
on:contextmenu={(e: MouseEvent) => {
490+
e.preventDefault();
491+
e.stopPropagation();
492+
}}
493+
>
479494
<IconButton icon={iconAdd} click={this.addTab}></IconButton>
480495
</div>
481496
<div class="extra right" this={use(this.rightEl)}></div>

0 commit comments

Comments
 (0)