fix(sidebar): show tooltips only for truncated labels
This commit is contained in:
@@ -129,7 +129,10 @@ const labelRef = ref<HTMLElement>();
|
||||
const rowRef = ref<HTMLElement>();
|
||||
function isLabelTruncated(): boolean {
|
||||
const el = labelRef.value;
|
||||
return !!el && el.scrollWidth > el.clientWidth;
|
||||
if (!el) return false;
|
||||
const style = window.getComputedStyle(el);
|
||||
if (style.overflowX === "visible" || style.textOverflow !== "ellipsis") return false;
|
||||
return el.scrollWidth - el.clientWidth > 2;
|
||||
}
|
||||
const connectionStore = useConnectionStore();
|
||||
const queryStore = useQueryStore();
|
||||
@@ -266,8 +269,8 @@ function visibleLabel(node: TreeNode): string {
|
||||
return displayLabel(node);
|
||||
}
|
||||
|
||||
function isTooltipDisabled(node: TreeNode): boolean {
|
||||
return !isLabelTruncated() && visibleLabel(node) === displayLabel(node);
|
||||
function isTooltipDisabled(): boolean {
|
||||
return !isLabelTruncated();
|
||||
}
|
||||
|
||||
async function toggle() {
|
||||
@@ -2304,13 +2307,7 @@ function treeItemMenuItems(): ContextMenuItem[] {
|
||||
@keydown.escape.prevent="isRenamingGroup = false"
|
||||
@click.stop
|
||||
/>
|
||||
<LightTooltip
|
||||
v-else
|
||||
:text="displayLabel(node)"
|
||||
:disabled="isTooltipDisabled(node)"
|
||||
side="right"
|
||||
:side-offset="8"
|
||||
>
|
||||
<LightTooltip v-else :text="displayLabel(node)" :disabled="isTooltipDisabled" side="right" :side-offset="8">
|
||||
<span ref="labelRef" class="min-w-0 flex-1 truncate">{{ visibleLabel(node) }}</span>
|
||||
</LightTooltip>
|
||||
<span
|
||||
|
||||
@@ -4,7 +4,7 @@ import { computed, onBeforeUnmount, ref, watch } from "vue";
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
text: string;
|
||||
disabled?: boolean;
|
||||
disabled?: boolean | (() => boolean);
|
||||
side?: "top" | "right" | "bottom" | "left";
|
||||
sideOffset?: number;
|
||||
delay?: number;
|
||||
@@ -70,6 +70,10 @@ function isTriggerActive(): boolean {
|
||||
return el.matches(":hover") || (active instanceof Node && el.contains(active));
|
||||
}
|
||||
|
||||
function isDisabled(): boolean {
|
||||
return typeof props.disabled === "function" ? props.disabled() : props.disabled;
|
||||
}
|
||||
|
||||
function updatePosition() {
|
||||
const el = triggerElement();
|
||||
if (!el) return;
|
||||
@@ -127,7 +131,7 @@ function removeGlobalListeners() {
|
||||
}
|
||||
|
||||
function open() {
|
||||
if (props.disabled || !props.text) return;
|
||||
if (isDisabled() || !props.text) return;
|
||||
if (!isTriggerActive()) return;
|
||||
updatePosition();
|
||||
show.value = true;
|
||||
@@ -135,7 +139,7 @@ function open() {
|
||||
}
|
||||
|
||||
function scheduleOpen() {
|
||||
if (props.disabled || !props.text) return;
|
||||
if (isDisabled() || !props.text) return;
|
||||
clearTimer();
|
||||
timer = setTimeout(open, props.delay);
|
||||
}
|
||||
@@ -145,7 +149,7 @@ onBeforeUnmount(close);
|
||||
watch(
|
||||
() => [props.disabled, props.text] as const,
|
||||
() => {
|
||||
if (props.disabled || !props.text) close();
|
||||
if (isDisabled() || !props.text) close();
|
||||
else if (show.value) updatePosition();
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user