diff --git a/app/javascript/controllers/textarea_resize_controller.js b/app/javascript/controllers/textarea_resize_controller.js index ce11757..215b2fe 100644 --- a/app/javascript/controllers/textarea_resize_controller.js +++ b/app/javascript/controllers/textarea_resize_controller.js @@ -10,4 +10,19 @@ export default class extends Controller { this.element.style.height = "auto"; this.element.style.height = `${this.element.scrollHeight + 2}px`; } + + commentResize() { + this.element.style.height = "auto"; + this.element.style.height = `${this.element.scrollHeight + 2}px`; + } + + resetComment(event) { + if (event.target === this.element.form) { + requestAnimationFrame(() => { + this.element.value = ""; + this.element.style.height = "auto"; + this.element.style.height = `${this.element.scrollHeight + 2}px`; + }); + } + } } diff --git a/app/views/projects/_project_comments.html.erb b/app/views/projects/_project_comments.html.erb index 0d547ea..d891b87 100644 --- a/app/views/projects/_project_comments.html.erb +++ b/app/views/projects/_project_comments.html.erb @@ -148,11 +148,12 @@ > <%= form.text_area :user_comment, class: - "w-full bg-transparent border-0 text-sm text-gray-800 placeholder-gray-400 py-2 px-2 focus:outline-none resize-none overflow-y-auto max-h-[120px]", + "w-full bg-transparent border-0 text-sm text-gray-800 placeholder-gray-400 py-2 px-2 focus:outline-none resize-none overflow-y-auto max-h-[200px]", rows: 1, data: { controller: "textarea-resize", - action: "input->textarea-resize#resize", + action: + "input->textarea-resize#commentResize turbo:submit-end@window->textarea-resize#resetComment", }, placeholder: "Write a comment..." %> diff --git a/app/views/projects/show.html.erb b/app/views/projects/show.html.erb index e27a53e..62388bc 100644 --- a/app/views/projects/show.html.erb +++ b/app/views/projects/show.html.erb @@ -95,7 +95,7 @@
@@ -128,10 +128,16 @@ <%# -- MOBILE-ONLY-PROJECT-ACTION, hidden on xl and up -- %> <% if policy(@project).update? || @current_version != @latest_version %> -
+

textarea-resize#resize", + action: + "input->textarea-resize#commentResize turbo:submit-end@window->textarea-resize#resetComment", }, placeholder: "Write a comment..." %> diff --git a/app/views/topics/show.html.erb b/app/views/topics/show.html.erb index ce534a0..96fe015 100644 --- a/app/views/topics/show.html.erb +++ b/app/views/topics/show.html.erb @@ -119,7 +119,7 @@ <%# --- Comments Section --- %>