@@ -265,6 +265,10 @@ document.addEventListener('DOMContentLoaded', () => {
265265 textareaSaverAndResizerFunc ( ) ;
266266 attachEmojiInputListeners ( ) ;
267267 attachAutoSendToggleListeners ( ) ;
268+ // Call the function for your specific textarea by ID
269+ textareaInputAreaResizerFun ( 'buttonText' ) ;
270+
271+
268272
269273 // -------------------------
270274 // Open external links in new tabs
@@ -418,6 +422,39 @@ function textareaSaverAndResizerFunc() {
418422 } ) ;
419423}
420424
425+ /**
426+ * Adds an input listener to a textarea (by its ID) so that its height
427+ * dynamically adjusts to fit its content.
428+ *
429+ * @param {string } textareaId - The ID of the textarea element.
430+ */
431+ function textareaInputAreaResizerFun ( textareaId ) {
432+ const textarea = document . getElementById ( textareaId ) ;
433+ if ( ! textarea ) {
434+ console . error ( `Textarea with id "${ textareaId } " not found.` ) ;
435+ return ;
436+ }
437+
438+ // Ensure the textarea doesn't show scrollbars or allow manual resizing
439+ textarea . style . overflow = 'hidden' ;
440+ textarea . style . resize = 'none' ;
441+
442+ // Function to resize the textarea to fit its content
443+ const resizeTextarea = ( ) => {
444+ // Reset the height to allow shrinking if content is removed
445+ textarea . style . height = 'auto' ;
446+ // Set the height to match the content's scrollHeight
447+ textarea . style . height = textarea . scrollHeight + 'px' ;
448+ } ;
449+
450+ // Adjust the textarea size on input events
451+ textarea . addEventListener ( 'input' , resizeTextarea ) ;
452+
453+ // Initial resize in case there is preset content
454+ resizeTextarea ( ) ;
455+ }
456+
457+
421458/**
422459 * Attaches input listeners to emoji input fields to update button icons.
423460 */
0 commit comments