Skip to content

Commit c914ef9

Browse files
committed
fix textarea autosize
1 parent 1114c52 commit c914ef9

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

resources/views/components/textarea/index.blade.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,25 @@
1414
x-data="{
1515
native: false,
1616
minHeight: null,
17-
height: null,
1817
init() {
1918
this.native = CSS.supports('field-sizing: content');
2019
20+
this.minHeight = this.$el.getBoundingClientRect().height;
21+
2122
if (!this.native) {
2223
this.$nextTick(() => {
23-
this.minHeight = this.$el.getBoundingClientRect().height;
24-
this.height = this.$el.scrollHeight;
24+
this.resize();
2525
});
2626
}
2727
2828
},
29+
resize() {
30+
this.$el.style.height = `${this.minHeight}px`;
31+
this.$el.style.height = `${this.$el.scrollHeight}px`;
32+
},
2933
onInput(event) {
3034
if (!this.native) {
31-
this.height = this.minHeight;
32-
this.$nextTick(() => {
33-
this.height = this.$el.scrollHeight;
34-
});
35+
this.resize();
3536
}
3637
},
37-
}" x-on:input="onInput" x-on:focus="onInput"
38-
x-bind:style="{
39-
'height': height ? `${height}px` : '',
40-
}">{{ $slot }}</textarea>
38+
}" x-on:input="onInput" x-intersect="onInput">{{ $slot }}</textarea>

0 commit comments

Comments
 (0)