Skip to content

Commit a19e4eb

Browse files
committed
Close sidebar on click outside (when sidebar is not static)
1 parent 7ff86d8 commit a19e4eb

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

web/src/routes/+page.svelte

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,20 @@
2929
import LoadDiffDialog from "./LoadDiffDialog.svelte";
3030
import InfoPopup from "./InfoPopup.svelte";
3131
import { Button } from "bits-ui";
32+
import { onClickOutside } from "runed";
3233
3334
const globalOptions = GlobalOptions.init();
3435
const viewer = MultiFileDiffViewerState.init();
36+
let sidebarElement: HTMLDivElement | undefined = $state();
37+
38+
onClickOutside(
39+
() => sidebarElement,
40+
() => {
41+
if (!staticSidebar.current) {
42+
viewer.sidebarCollapsed = true;
43+
}
44+
},
45+
);
3546
3647
function filterFileNode(file: TreeNode<FileTreeNodeData>): boolean {
3748
return file.data.type === "file" && viewer.filterFile(file.data.data as FileDetails);
@@ -126,6 +137,7 @@
126137

127138
<div class="relative flex min-h-screen flex-row justify-center">
128139
<div
140+
bind:this={sidebarElement}
129141
class="absolute top-0 left-0 z-10 flex h-full w-full flex-col border-e bg-neutral data-[collapsed=true]:hidden md:w-[350px] md:shadow-md lg:static lg:h-auto lg:shadow-none"
130142
data-collapsed={viewer.sidebarCollapsed}
131143
>

0 commit comments

Comments
 (0)