Skip to content
This repository was archived by the owner on Mar 18, 2025. It is now read-only.

Commit 4895b08

Browse files
committed
Prevent textarea-resize from firing on hidden textareas
1 parent b6bc8dd commit 4895b08

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

resources/js/directives/textarea-resize.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
11
const resize = el => {
2+
if (! el.style.minHeight) {
3+
el.style.minHeight = `${el.scrollHeight}px`;
4+
}
5+
26
el.style.height = 'auto';
37
el.style.height = `${el.scrollHeight}px`;
48
};
59

10+
const isHidden = el => {
11+
if (el.style.display === 'none') {
12+
return true;
13+
}
14+
15+
return ! el.offsetParent;
16+
};
17+
618
export default Alpine => {
719
Alpine.directive('textarea-resize', (el, {}, { cleanup }) => {
8-
el.style.minHeight = `${el.scrollHeight}px`;
9-
resize(el);
20+
// We should not attempt to resize the textarea when it is not visible,
21+
// otherwise the height will be set to 0.
22+
if (! isHidden(el)) {
23+
resize(el);
24+
}
1025

1126
const inputHandler = () => resize(el);
1227

0 commit comments

Comments
 (0)