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。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(sidebar): constrain tooltip position to clipping scroll container (#13717) (#13723)
lxk955bdbf4544744a
diff --git a/apps/desktop/src/components/ui/LightTooltip.vue b/apps/desktop/src/components/ui/LightTooltip.vueindex 4eded3844a..ede2a13bd9 100644--- a/apps/desktop/src/components/ui/LightTooltip.vue+++ b/apps/desktop/src/components/ui/LightTooltip.vue@@ -1,7 +1,7 @@<script setup lang="ts">import { computed, nextTick, onBeforeUnmount, ref, watch } from "vue";import { cn } from "@/lib/common/utils";-import { floatingArrowOffset, floatingViewportShift } from "@/lib/common/floatingViewportPosition";+import { floatingArrowOffset, floatingViewportShift, visibleTriggerRect } from "@/lib/common/floatingViewportPosition";const props = withDefaults(defineProps<{@@ -133,7 +133,7 @@ function updatePosition() {const el = triggerElement();if (!el) return;arrowOffset.value = undefined;- const rect = el.getBoundingClientRect();+ const rect = visibleTriggerRect(el);const offset = props.sideOffset;switch (props.side) {case "right":diff --git a/apps/desktop/src/components/ui/__tests__/LightTooltip.spec.ts b/apps/desktop/src/components/ui/__tests__/LightTooltip.spec.tsindex 5f6abadbb2..ebb6000ca2 100644--- a/apps/desktop/src/components/ui/__tests__/LightTooltip.spec.ts+++ b/apps/desktop/src/components/ui/__tests__/LightTooltip.spec.ts@@ -136,3 +136,120 @@ describe("LightTooltip nowrap overflow", () => {app.unmount();});});++describe("LightTooltip positioning with clipping ancestors", () => {+ it("anchors right-side tooltip to the clipping container boundary when trigger is wider (#13717)", async () => {+ vi.useFakeTimers();++ const root = defineComponent({+ setup() {+ return () =>+ h(+ "div",+ { id: "scroll-container", style: { overflowX: "auto" } },+ h(+ LightTooltip,+ { text: "Connection Details", side: "right", sideOffset: 8, delay: 0 },+ {+ default: () => h("div", { id: "tree-row" }, "Wide tree row"),+ },+ ),+ );+ },+ });++ const container = document.createElement("div");+ document.body.append(container);+ const app = createApp(root);+ app.mount(container);++ const scroller = container.querySelector<HTMLElement>("#scroll-container");+ const row = container.querySelector<HTMLElement>("#tree-row");+ expect(scroller).toBeTruthy();+ expect(row).toBeTruthy();++ vi.spyOn(HTMLElement.prototype, "getBoundingClientRect").mockImplementation(function (this: HTMLElement) {+ if (this.id === "scroll-container") {+ return { left: 0, right: 260, top: 50, bottom: 600, width: 260, height: 550 } as DOMRect;+ }+ if (this.id === "tree-row") {+ return { left: 0, right: 600, top: 100, bottom: 128, width: 600, height: 28 } as DOMRect;+ }+ if (this.getAttribute("role") === "tooltip") {+ return { left: 268, right: 388, top: 100, bottom: 128, width: 120, height: 28 } as DOMRect;+ }+ return { left: 0, right: 0, top: 0, bottom: 0, width: 0, height: 0 } as DOMRect;+ });++ vi.spyOn(row!, "matches").mockImplementation((selector) => selector === ":hover");+ row?.dispatchEvent(new MouseEvent("mouseenter", { bubbles: true }));+ await vi.runAllTimersAsync();+ await nextTick();++ const tooltip = document.querySelector<HTMLElement>("[role=tooltip]");+ expect(tooltip).toBeTruthy();+ // Clipped right edge is 260, offset is 8 -> left: 268px (NOT 608px)+ expect(tooltip!.style.left).toBe("268px");+ expect(tooltip!.style.top).toBe("114px");++ app.unmount();+ });++ it("centers top-side tooltip over visible trigger width inside clipping container", async () => {+ vi.useFakeTimers();++ const root = defineComponent({+ setup() {+ return () =>+ h(+ "div",+ { id: "scroll-container", style: { overflowX: "auto" } },+ h(+ LightTooltip,+ { text: "Table Header", side: "top", sideOffset: 8, delay: 0 },+ {+ default: () => h("div", { id: "tree-row" }, "Wide header"),+ },+ ),+ );+ },+ });++ const container = document.createElement("div");+ document.body.append(container);+ const app = createApp(root);+ app.mount(container);++ const scroller = container.querySelector<HTMLElement>("#scroll-container");+ const row = container.querySelector<HTMLElement>("#tree-row");+ expect(scroller).toBeTruthy();+ expect(row).toBeTruthy();++ vi.spyOn(HTMLElement.prototype, "getBoundingClientRect").mockImplementation(function (this: HTMLElement) {+ if (this.id === "scroll-container") {+ return { left: 0, right: 260, top: 50, bottom: 600, width: 260, height: 550 } as DOMRect;+ }+ if (this.id === "tree-row") {+ return { left: 0, right: 600, top: 100, bottom: 128, width: 600, height: 28 } as DOMRect;+ }+ if (this.getAttribute("role") === "tooltip") {+ return { left: 100, right: 160, top: 64, bottom: 92, width: 60, height: 28 } as DOMRect;+ }+ return { left: 0, right: 0, top: 0, bottom: 0, width: 0, height: 0 } as DOMRect;+ });++ vi.spyOn(row!, "matches").mockImplementation((selector) => selector === ":hover");+ row?.dispatchEvent(new MouseEvent("mouseenter", { bubbles: true }));+ await vi.runAllTimersAsync();+ await nextTick();++ const tooltip = document.querySelector<HTMLElement>("[role=tooltip]");+ expect(tooltip).toBeTruthy();+ // Visible trigger rect has left: 0, right: 260 -> center is 130 (NOT 300)+ // top: 100 - 8 = 92px+ expect(tooltip!.style.left).toBe("130px");+ expect(tooltip!.style.top).toBe("92px");++ app.unmount();+ });+});diff --git a/apps/desktop/src/lib/__tests__/common/floatingViewportPosition.spec.ts b/apps/desktop/src/lib/__tests__/common/floatingViewportPosition.spec.tsindex a0afefe14f..b5b9c7441c 100644--- a/apps/desktop/src/lib/__tests__/common/floatingViewportPosition.spec.ts+++ b/apps/desktop/src/lib/__tests__/common/floatingViewportPosition.spec.ts@@ -1,5 +1,7 @@+// @vitest-environment happy-dom+import { describe, expect, it } from "vitest";-import { floatingArrowOffset, floatingCursorPosition, floatingViewportShift } from "@/lib/common/floatingViewportPosition";+import { floatingArrowOffset, floatingCursorPosition, floatingViewportShift, visibleTriggerRect } from "@/lib/common/floatingViewportPosition";describe("floating viewport position", () => {it.each([@@ -36,3 +38,118 @@ describe("floating viewport position", () => {expect(floatingArrowOffset(40, -100)).toBe(32);});});++describe("visibleTriggerRect", () => {+ it("returns unclipped bounding rect when there are no clipping ancestors", () => {+ const parent = document.createElement("div");+ const trigger = document.createElement("button");+ parent.append(trigger);+ document.body.append(parent);++ trigger.getBoundingClientRect = () => ({ left: 50, right: 250, top: 100, bottom: 130, width: 200, height: 30 }) as DOMRect;++ expect(visibleTriggerRect(trigger)).toEqual({+ left: 50,+ right: 250,+ top: 100,+ bottom: 130,+ width: 200,+ height: 30,+ });++ parent.remove();+ });++ it("clamps right edge to clipping container when trigger is wider than the scroll container", () => {+ const scroller = document.createElement("div");+ scroller.style.overflowX = "auto";+ const trigger = document.createElement("div");+ scroller.append(trigger);+ document.body.append(scroller);++ scroller.getBoundingClientRect = () => ({ left: 0, right: 260, top: 50, bottom: 600, width: 260, height: 550 }) as DOMRect;+ trigger.getBoundingClientRect = () => ({ left: 0, right: 580, top: 120, bottom: 148, width: 580, height: 28 }) as DOMRect;++ expect(visibleTriggerRect(trigger)).toEqual({+ left: 0,+ right: 260,+ top: 120,+ bottom: 148,+ width: 260,+ height: 28,+ });++ scroller.remove();+ });++ it("clamps left edge when trigger is scrolled out to the left", () => {+ const scroller = document.createElement("div");+ scroller.style.overflowX = "scroll";+ const trigger = document.createElement("div");+ scroller.append(trigger);+ document.body.append(scroller);++ scroller.getBoundingClientRect = () => ({ left: 0, right: 260, top: 50, bottom: 600, width: 260, height: 550 }) as DOMRect;+ trigger.getBoundingClientRect = () => ({ left: -150, right: 200, top: 120, bottom: 148, width: 350, height: 28 }) as DOMRect;++ expect(visibleTriggerRect(trigger)).toEqual({+ left: 0,+ right: 200,+ top: 120,+ bottom: 148,+ width: 200,+ height: 28,+ });++ scroller.remove();+ });++ it("clamps top and bottom edges for vertical scroll container", () => {+ const scroller = document.createElement("div");+ scroller.style.overflowY = "auto";+ const trigger = document.createElement("div");+ scroller.append(trigger);+ document.body.append(scroller);++ scroller.getBoundingClientRect = () => ({ left: 0, right: 300, top: 100, bottom: 400, width: 300, height: 300 }) as DOMRect;+ trigger.getBoundingClientRect = () => ({ left: 10, right: 200, top: 80, bottom: 140, width: 190, height: 60 }) as DOMRect;++ expect(visibleTriggerRect(trigger)).toEqual({+ left: 10,+ right: 200,+ top: 100,+ bottom: 140,+ width: 190,+ height: 40,+ });++ scroller.remove();+ });++ it("computes intersection across nested clipping ancestors", () => {+ const outer = document.createElement("div");+ outer.style.overflow = "hidden";+ const inner = document.createElement("div");+ inner.style.overflowX = "auto";+ const trigger = document.createElement("div");++ inner.append(trigger);+ outer.append(inner);+ document.body.append(outer);++ outer.getBoundingClientRect = () => ({ left: 20, right: 280, top: 40, bottom: 500, width: 260, height: 460 }) as DOMRect;+ inner.getBoundingClientRect = () => ({ left: 0, right: 350, top: 40, bottom: 500, width: 350, height: 460 }) as DOMRect;+ trigger.getBoundingClientRect = () => ({ left: 0, right: 600, top: 100, bottom: 130, width: 600, height: 30 }) as DOMRect;++ expect(visibleTriggerRect(trigger)).toEqual({+ left: 20,+ right: 280,+ top: 100,+ bottom: 130,+ width: 260,+ height: 30,+ });++ outer.remove();+ });+});diff --git a/apps/desktop/src/lib/common/floatingViewportPosition.ts b/apps/desktop/src/lib/common/floatingViewportPosition.tsindex 9af79d741f..1608d9e7af 100644--- a/apps/desktop/src/lib/common/floatingViewportPosition.ts+++ b/apps/desktop/src/lib/common/floatingViewportPosition.ts@@ -44,3 +44,77 @@ export function floatingArrowOffset(length: number, shift: number, padding = 8):const maximum = Math.max(padding, length - padding);return Math.min(Math.max(padding, length / 2 - shift), maximum);}++function isClippingOverflow(overflow: string): boolean {+ return overflow === "auto" || overflow === "scroll" || overflow === "hidden" || overflow === "clip";+}++/**+ * Computes the visible intersection rectangle of a trigger element within all of+ * its clipping ancestor containers (overflow: auto | scroll | hidden | clip).+ * If the element is not clipped by any ancestor, returns its bounding client rect.+ */+export function visibleTriggerRect(el: HTMLElement): FloatingRect & { width: number; height: number } {+ const rect = el.getBoundingClientRect();+ let left = rect.left;+ let right = rect.right;+ let top = rect.top;+ let bottom = rect.bottom;++ if (typeof window === "undefined") {+ return {+ left,+ right,+ top,+ bottom,+ width: right - left,+ height: bottom - top,+ };+ }++ let parent: Element | null = el.parentElement;+ while (parent && parent !== document.body && parent !== document.documentElement) {+ const style = window.getComputedStyle(parent);+ const overflowX = style.overflowX || style.overflow;+ const overflowY = style.overflowY || style.overflow;+ const clipsX = isClippingOverflow(overflowX);+ const clipsY = isClippingOverflow(overflowY);++ if (clipsX || clipsY) {+ const parentRect = parent.getBoundingClientRect();+ if (clipsX) {+ left = Math.max(left, parentRect.left);+ right = Math.min(right, parentRect.right);+ }+ if (clipsY) {+ top = Math.max(top, parentRect.top);+ bottom = Math.min(bottom, parentRect.bottom);+ }+ }+ parent = parent.parentElement;+ }++ if (left > right) {+ if (rect.right < left) {+ right = left;+ } else {+ left = right;+ }+ }+ if (top > bottom) {+ if (rect.bottom < top) {+ bottom = top;+ } else {+ top = bottom;+ }+ }++ return {+ left,+ right,+ top,+ bottom,+ width: right - left,+ height: bottom - top,+ };+}