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

51 lines
1.4 KiB
Vue
Raw Normal View History

2022-09-06 12:03:37 +00:00
<template>
2023-05-29 09:19:55 +00:00
<textarea :class="cx('root')" :value="modelValue" @input="onInput" v-bind="ptm('root')" data-pc-name="textarea"></textarea>
2022-09-06 12:03:37 +00:00
</template>
<script>
2023-05-24 14:15:21 +00:00
import BaseTextarea from './BaseTextarea.vue';
2023-05-07 06:29:10 +00:00
2022-09-06 12:03:37 +00:00
export default {
name: 'Textarea',
2023-05-24 14:15:21 +00:00
extends: BaseTextarea,
2022-09-06 12:03:37 +00:00
emits: ['update:modelValue'],
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>