Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix(backup): close and hide detached connection popover on scroll

lxk955ad643fcf78c9
diff --git a/apps/desktop/src/components/backup/DatabaseBackupConfigFields.vue b/apps/desktop/src/components/backup/DatabaseBackupConfigFields.vue
index 22de1117c8..e2aa531f6f 100644
--- a/apps/desktop/src/components/backup/DatabaseBackupConfigFields.vue
+++ b/apps/desktop/src/components/backup/DatabaseBackupConfigFields.vue
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { isTauriRuntime } from "@/lib/backend/tauriRuntime";
-import { computed, nextTick, ref, watch, type ComponentPublicInstance } from "vue";
+import { computed, nextTick, onBeforeUnmount, ref, watch, type ComponentPublicInstance } from "vue";
import { useI18n } from "vue-i18n";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
@@ -103,15 +103,37 @@ function syncConnectionPickerWidth() {
if (width > 0) connectionPickerWidth.value = width;
}
+function handleScrollOutside(event: Event) {
+ if (!connectionPickerOpen.value) return;
+ const target = event.target;
+ if (target instanceof HTMLElement && target.closest?.('[data-slot="popover-content"]')) return;
+ connectionPickerOpen.value = false;
+}
+
watch(connectionPickerOpen, async (open) => {
if (!open) {
+ window.removeEventListener("scroll", handleScrollOutside, { capture: true });
connectionSearch.value = "";
return;
}
+ window.addEventListener("scroll", handleScrollOutside, { capture: true, passive: true });
await nextTick();
syncConnectionPickerWidth();
});
+watch(
+ () => props.draft,
+ () => {
+ connectionPickerOpen.value = false;
+ connectionSearch.value = "";
+ databaseSearch.value = "";
+ },
+);
+
+onBeforeUnmount(() => {
+ window.removeEventListener("scroll", handleScrollOutside, { capture: true });
+});
+
watch(
() => props.draft.connectionId,
() => {
@@ -131,7 +153,7 @@ watch(
<ChevronDown class="ml-2 h-4 w-4 shrink-0 opacity-50" />
</Button>
</PopoverTrigger>
- <PopoverContent align="start" :collision-padding="24" class="w-[var(--reka-popover-trigger-width)] max-w-[calc(100vw-48px)] p-1" :style="connectionPickerWidth ? { width: `${connectionPickerWidth}px` } : undefined">
+ <PopoverContent align="start" :collision-padding="24" :hide-when-detached="true" class="w-[var(--reka-popover-trigger-width)] max-w-[calc(100vw-48px)] p-1" :style="connectionPickerWidth ? { width: `${connectionPickerWidth}px` } : undefined">
<div class="relative">
<Search class="pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
<Input v-model="connectionSearch" data-backup-connection-search class="h-9 pl-8" :aria-label="t('databaseBackup.searchConnections')" :placeholder="t('databaseBackup.searchConnections')" />
diff --git a/apps/desktop/src/components/backup/ScheduledDatabaseBackupSettings.vue b/apps/desktop/src/components/backup/ScheduledDatabaseBackupSettings.vue
index 5d2109bfc4..9e581128d7 100644
--- a/apps/desktop/src/components/backup/ScheduledDatabaseBackupSettings.vue
+++ b/apps/desktop/src/components/backup/ScheduledDatabaseBackupSettings.vue
@@ -1,5 +1,5 @@
<script setup lang="ts">
-import { computed, onMounted, reactive, ref, watch } from "vue";
+import { computed, nextTick, onBeforeUnmount, onMounted, reactive, ref, watch } from "vue";
import { isTauriRuntime } from "@/lib/backend/tauriRuntime";
import { useI18n } from "vue-i18n";
import { Badge } from "@/components/ui/badge";
@@ -155,8 +155,40 @@ const weekdays = computed(() => [
{ value: 6, label: t("databaseBackup.weekdays.saturday") },
]);
+function handleHistoryScrollOutside(event: Event) {
+ if (!historyConnectionPickerOpen.value) return;
+ const target = event.target;
+ if (target instanceof HTMLElement && target.closest?.('[data-slot="popover-content"]')) return;
+ historyConnectionPickerOpen.value = false;
+}
+
watch(historyConnectionPickerOpen, (open) => {
- if (!open) historyConnectionSearch.value = "";
+ if (!open) {
+ window.removeEventListener("scroll", handleHistoryScrollOutside, { capture: true });
+ historyConnectionSearch.value = "";
+ return;
+ }
+ window.addEventListener("scroll", handleHistoryScrollOutside, { capture: true, passive: true });
+});
+
+onBeforeUnmount(() => {
+ window.removeEventListener("scroll", handleHistoryScrollOutside, { capture: true });
+});
+
+watch(scheduleDialogOpen, async (open) => {
+ if (open) {
+ await nextTick();
+ const dialogs = document.querySelectorAll<HTMLElement>(".dbx-backup-dialog");
+ for (const dialog of dialogs) dialog.scrollTop = 0;
+ }
+});
+
+watch(oneShotDialogOpen, async (open) => {
+ if (open) {
+ await nextTick();
+ const dialogs = document.querySelectorAll<HTMLElement>(".dbx-backup-dialog");
+ for (const dialog of dialogs) dialog.scrollTop = 0;
+ }
});
/**
@@ -862,7 +894,7 @@ async function restoreBackup(run: DatabaseBackupRun, file: DatabaseBackupFile) {
<ChevronDown class="ml-2 h-4 w-4 shrink-0 opacity-50" />
</Button>
</PopoverTrigger>
- <PopoverContent align="end" class="w-[var(--reka-popover-trigger-width)] p-1">
+ <PopoverContent align="end" :hide-when-detached="true" class="w-[var(--reka-popover-trigger-width)] p-1">
<div class="relative">
<Search class="pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
<Input v-model="historyConnectionSearch" data-backup-history-connection-search class="h-9 pl-8" :aria-label="t('databaseBackup.searchHistoryConnections')" :placeholder="t('databaseBackup.searchHistoryConnections')" />
diff --git a/apps/desktop/src/components/backup/__tests__/ScheduledDatabaseBackupSettings.spec.ts b/apps/desktop/src/components/backup/__tests__/ScheduledDatabaseBackupSettings.spec.ts
index 30677dd24b..2d59540aaa 100644
--- a/apps/desktop/src/components/backup/__tests__/ScheduledDatabaseBackupSettings.spec.ts
+++ b/apps/desktop/src/components/backup/__tests__/ScheduledDatabaseBackupSettings.spec.ts
@@ -1094,4 +1094,61 @@ describe("ScheduledDatabaseBackupSettings schedule dialog", () => {
expect(mocks.saveSchedule).not.toHaveBeenCalled();
expect(mocks.toast).toHaveBeenCalledWith("backup destination unavailable", 5000);
});
+
+ it("closes the backup connection picker on outside scroll but preserves it when scrolling inside the popover", async () => {
+ mocks.connections.push({ id: "mysql-1", name: "Local MySQL", db_type: "mysql" });
+ await mountSettings();
+
+ addScheduleButton().click();
+ await flush();
+
+ const trigger = currentDialog().querySelector<HTMLButtonElement>("[data-backup-connection-picker]");
+ if (!trigger) throw new Error("Connection picker trigger not found");
+
+ trigger.click();
+ await flush();
+ expect(trigger.getAttribute("aria-expanded")).toBe("true");
+
+ const popoverContent = document.body.querySelector<HTMLElement>('[data-slot="popover-content"]');
+ expect(popoverContent).not.toBeNull();
+
+ // Scroll inside the popover list should not close the picker
+ const internalList = popoverContent?.querySelector<HTMLElement>(".overflow-y-auto");
+ if (!internalList) throw new Error("Internal popover scrollable list not found");
+ internalList.dispatchEvent(new Event("scroll", { bubbles: true }));
+ await flush();
+ expect(trigger.getAttribute("aria-expanded")).toBe("true");
+
+ // Scroll outside the popover (e.g. dialog content or window) should close the picker
+ window.dispatchEvent(new Event("scroll"));
+ await flush();
+ expect(trigger.getAttribute("aria-expanded")).toBe("false");
+ });
+
+ it("closes the history connection picker on outside scroll", async () => {
+ mocks.connections.push({ id: "mysql-1", name: "Local MySQL", db_type: "mysql" });
+ mocks.runs.push({
+ id: "run-1",
+ scheduleName: "Run 1",
+ connectionId: "mysql-1",
+ connectionName: "Local MySQL",
+ trigger: "scheduled",
+ source: "scheduled",
+ status: "success",
+ startedAt: "2026-09-08T02:00:00.000Z",
+ files: [],
+ });
+ await mountSettings();
+
+ const trigger = document.body.querySelector<HTMLButtonElement>("[data-backup-history-connection-picker]");
+ if (!trigger) throw new Error("History connection picker trigger not found");
+
+ trigger.click();
+ await flush();
+ expect(trigger.getAttribute("aria-expanded")).toBe("true");
+
+ window.dispatchEvent(new Event("scroll"));
+ await flush();
+ expect(trigger.getAttribute("aria-expanded")).toBe("false");
+ });
});