-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathTextarea.vue
executable file
·60 lines (55 loc) · 1.5 KB
/
Textarea.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<template>
<textarea :class="['p-inputtextarea p-inputtext p-component', {'p-filled': filled, 'p-inputtextarea-resizable ': autoResize}]" v-bind="$attrs" :value="modelValue" @input="onInput"></textarea>
</template>
<script>
export default {
emits: ['update:modelValue'],
props: {
modelValue: null,
autoResize: Boolean
},
mounted() {
if (this.$el.offsetParent && this.autoResize) {
this.resize();
}
},
updated() {
if (this.$el.offsetParent && this.autoResize) {
this.resize();
}
},
methods: {
resize() {
this.$el.style.height = 'auto';
this.$el.style.height = this.$el.scrollHeight + 'px';
if (parseFloat(this.$el.style.height) >= parseFloat(this.$el.style.maxHeight)) {
this.$el.style.overflowY = "scroll";
this.$el.style.height = this.$el.style.maxHeight;
}
else {
this.$el.style.overflow = "hidden";
}
},
onInput(event) {
if (this.autoResize) {
this.resize();
}
this.$emit('update:modelValue', event.target.value);
}
},
computed: {
filled() {
return (this.modelValue != null && this.modelValue.toString().length > 0)
}
}
}
</script>
<style>
.p-inputtextarea-resizable {
overflow: hidden;
resize: none;
}
.p-fluid .p-inputtextarea {
width: 100%;
}
</style>