primevue-mirror/components/lib/textarea/Textarea.vue

66 lines
1.7 KiB
Vue
Raw Normal View History

2022-09-06 12:03:37 +00:00
<template>
2023-05-07 06:29:10 +00:00
<textarea :class="['p-inputtextarea p-inputtext p-component', { 'p-filled': filled, 'p-inputtextarea-resizable ': autoResize }]" :value="modelValue" @input="onInput" v-bind="ptm('root')"></textarea>
2022-09-06 12:03:37 +00:00
</template>
<script>
2023-05-07 06:29:10 +00:00
import BaseComponent from 'primevue/basecomponent';
2022-09-06 12:03:37 +00:00
export default {
name: 'Textarea',
2023-05-07 06:29:10 +00:00
extends: BaseComponent,
2022-09-06 12:03:37 +00:00
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>