Skip to content

Commit 76150bf

Browse files
committed
Textarea for initial button text is now auto resizing
1 parent 8215379 commit 76150bf

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

popup-page-scripts/popup-page-script.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/

popup-page-styles/popup-buttons.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ This file is responsible for:
88
individual custom button items (with hover and dragging effects), drag handles, and separator items.
99
*/
1010

11+
12+
/* input for creating new buttons */
13+
14+
.text-input {
15+
overflow: hidden;
16+
resize: none;
17+
}
18+
19+
1120
/* ------------------------------------------------------------------------- */
1221
/* 1. Base Button Styling for All Buttons */
1322
/* ------------------------------------------------------------------------- */

0 commit comments

Comments
 (0)