Skip to content

Commit 5eae586

Browse files
authored
Merge pull request #2324 from Particular/john/elipses
Adding TextEllipses component
2 parents 7b8c69d + 59f8007 commit 5eae586

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<script setup lang="ts">
2+
import { ref, watch, onMounted } from "vue";
3+
4+
const props = withDefaults(
5+
defineProps<{
6+
text: string;
7+
ellipsesStyle?: "RightSide" | "LeftSide";
8+
}>(),
9+
{ ellipsesStyle: "RightSide" }
10+
);
11+
12+
const textContainer = ref<HTMLElement | null>(null);
13+
const tooltipText = ref("");
14+
15+
const updateTooltip = () => {
16+
if (textContainer.value) {
17+
tooltipText.value = textContainer.value.scrollWidth > textContainer.value.clientWidth ? textContainer.value.textContent || "" : "";
18+
}
19+
};
20+
21+
onMounted(() => {
22+
updateTooltip();
23+
});
24+
25+
watch([() => props.text], () => {
26+
updateTooltip();
27+
});
28+
</script>
29+
30+
<template>
31+
<div ref="textContainer" title="" class="text-container hackToPreventSafariFromShowingTooltip" :class="{ 'left-side-ellipsis': ellipsesStyle === 'LeftSide' }" v-tippy="{ content: tooltipText, maxWidth: 'none' }">
32+
{{ text }}
33+
</div>
34+
</template>
35+
36+
<style scoped>
37+
.hackToPreventSafariFromShowingTooltip::after {
38+
content: "";
39+
display: block;
40+
}
41+
42+
.left-side-ellipsis {
43+
direction: rtl;
44+
text-align: left;
45+
}
46+
47+
.text-container {
48+
white-space: nowrap;
49+
overflow: hidden;
50+
text-overflow: ellipsis;
51+
display: inline-block;
52+
}
53+
</style>

0 commit comments

Comments
 (0)