feat(ui): show instant tooltips for truncated labels

This commit is contained in:
t8y2 committed 2026-06-09 17:51:07 +08:00
1 parent bc3c7c52ea
commit a5d9addbf3
3 files changed
+170 -117

No files matched your search

@@ -0,0 +1,46 @@
<script setup lang="ts">
import { ref } from "vue";
import type { HTMLAttributes } from "vue";
import LightTooltip from "@/components/ui/LightTooltip.vue";
import { cn } from "@/lib/utils";
const props = withDefaults(
defineProps<{
text: string;
class?: HTMLAttributes["class"];
side?: "top" | "right" | "bottom" | "left";
sideOffset?: number;
delay?: number;
openOnFocus?: boolean;
}>(),
{
side: "top",
sideOffset: 8,
delay: 0,
openOnFocus: true,
},
);
const textRef = ref<HTMLElement>();
function isTooltipDisabled(): boolean {
const el = textRef.value;
if (!el) return true;
return el.scrollWidth - el.clientWidth <= 2;
}
</script>
<template>
<LightTooltip
:text="text"
:delay="delay"
:disabled="isTooltipDisabled"
:side="side"
:side-offset="sideOffset"
:open-on-focus="openOnFocus"
>
<span ref="textRef" :class="cn('truncate', props.class)">
<slot>{{ text }}</slot>
</span>
</LightTooltip>
</template>