2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
2022-09-14 11:26:01 +00:00
|
|
|
<textarea :class="['p-inputtextarea p-inputtext p-component', { 'p-filled': filled, 'p-inputtextarea-resizable ': autoResize }]" :value="modelValue" @input="onInput"></textarea>
|
2022-09-06 12:03:37 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
name: 'Textarea',
|
|
|
|
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() {
|
|
|
|
const style = window.getComputedStyle(this.$el);
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
this.$el.style.height = 'auto';
|
|
|
|
this.$el.style.height = `calc(${style.borderTopWidth} + ${style.borderBottomWidth} + ${this.$el.scrollHeight}px)`;
|
|
|
|
|
|
|
|
if (parseFloat(this.$el.style.height) >= parseFloat(this.$el.style.maxHeight)) {
|
2022-09-14 11:26:01 +00:00
|
|
|
this.$el.style.overflowY = 'scroll';
|
2022-09-06 12:03:37 +00:00
|
|
|
this.$el.style.height = this.$el.style.maxHeight;
|
2022-09-14 11:26:01 +00:00
|
|
|
} else {
|
|
|
|
this.$el.style.overflow = 'hidden';
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
onInput(event) {
|
|
|
|
if (this.autoResize) {
|
|
|
|
this.resize();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$emit('update:modelValue', event.target.value);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
filled() {
|
2022-09-14 11:26:01 +00:00
|
|
|
return this.modelValue != null && this.modelValue.toString().length > 0;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.p-inputtextarea-resizable {
|
|
|
|
overflow: hidden;
|
|
|
|
resize: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
.p-fluid .p-inputtextarea {
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
</style>
|