From 11bdff31fc5e2bc3f96f4820485c82ea81e850f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nu=C5=A1a=20Puk=C5=A1i=C4=8D?= Date: Wed, 7 Jan 2026 19:10:38 +0100 Subject: [PATCH] Editor: autogrow textarea --- .../utility/autogrow_textarea_controller.js | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 assets/controllers/utility/autogrow_textarea_controller.js diff --git a/assets/controllers/utility/autogrow_textarea_controller.js b/assets/controllers/utility/autogrow_textarea_controller.js new file mode 100644 index 0000000..b6cb64e --- /dev/null +++ b/assets/controllers/utility/autogrow_textarea_controller.js @@ -0,0 +1,27 @@ +import { Controller } from '@hotwired/stimulus'; + +/** + * Auto-grow textarea controller + * Makes textareas automatically resize to fit their content + */ +export default class extends Controller { + connect() { + // Set initial height + this.resize(); + + // Listen for input changes + this.element.addEventListener('input', () => this.resize()); + + // Also resize on focus (in case content was changed programmatically) + this.element.addEventListener('focus', () => this.resize()); + } + + resize() { + // Reset height to auto to get the correct scrollHeight + this.element.style.height = 'auto'; + + // Set height to scrollHeight to fit all content + this.element.style.height = this.element.scrollHeight + 'px'; + } +} +