File tree Expand file tree Collapse file tree 1 file changed +30
-3
lines changed
Expand file tree Collapse file tree 1 file changed +30
-3
lines changed Original file line number Diff line number Diff line change @@ -116,14 +116,41 @@ watch(
116116 { immediate: true },
117117);
118118
119+ /**
120+ * Checks if the given HTMLElement overflows
121+ * copied from stackoverflow: https://stackoverflow.com/questions/143815/determine-if-an-html-elements-content-overflows
122+ * @param el The HTMLElement to check
123+ */
124+ function checkOverflow(el : HTMLElement ) {
125+ const curOverflow = el .style .overflow ;
126+ if (! curOverflow || curOverflow === ' visible' ) {
127+ el .style .overflow = ' hidden' ;
128+ }
129+
130+ const isOverflowing = el .clientWidth < el .scrollWidth || el .clientHeight < el .scrollHeight ;
131+
132+ el .style .overflow = curOverflow ;
133+
134+ return isOverflowing ;
135+ }
136+
119137function resizeTextarea() {
120- if (! textareaRef .value || ! inputWrapperRef .value ) {
138+ if (textareaRef .value === undefined ) {
139+ return ; // cannot chnge textarea if element is not available
140+ }
141+
142+ if (! multiline ) {
143+ return ; // textarea wont be displayed if multiline === false
144+ }
145+
146+ if (! checkOverflow (textareaRef .value )) {
121147 return ;
122148 }
123149
124- const scrollHeight = textareaRef .value . scrollHeight + 2 ;
150+ const textAreaElement = textareaRef .value ! ;
125151
126- inputWrapperRef .value .style .height = ` ${scrollHeight }px ` ;
152+ const scrollHeight = textAreaElement .scrollHeight + 2 ;
153+ textAreaElement .style .height = ` ${scrollHeight }px ` ;
127154}
128155
129156const htmlInputType = computed (() => {
You can’t perform that action at this time.
0 commit comments