Input clientWidth and scrollWidth are always equal
I'm using Vuetify text-fields and want to display a tooltip containing the content if the content is greater than the field width (user needs to scroll). The tooltip should only appear on hover (default behaviour). I started with the following
<script setup lang="ts">
import { ref, computed } from "vue";
const currentValue = ref("");
const textFieldComponent = ref<VTextField>();
const isTextFieldCuttingOffContent = computed(() => {
if (!textFieldComponent.value) {
return false;
}
if (!currentValue.value) {
return false;
}
return (
textFieldComponent.value.$el.clientWidth <
textFieldComponent.value.$el.scrollWidth
);
});
</script>
<template>
<v-container style="width: 300px">
<v-tooltip :text="currentValue" :disabled="!isTextFieldCuttingOffContent">
<template v-slot:activator="{ props }">
<div v-bind="props">
<v-text-field
ref="textFieldComponent"
label="label goes here"
v-model="currentValue"
/>
</div>
</template>
</v-tooltip>
</v-container>
</template>
I also tried to use a watcher instead of a computed prop (Playground)
The problem is that isTextFieldCuttingOffContent
always returns false because clientWidth
and scrollWidth
are always equal. Do you have any ideas what's wrong or missing?
Comments
Post a Comment