diff --git a/chrome/content/zotero/elements/itemBox.js b/chrome/content/zotero/elements/itemBox.js index a83da1800b..902010a035 100644 --- a/chrome/content/zotero/elements/itemBox.js +++ b/chrome/content/zotero/elements/itemBox.js @@ -1563,7 +1563,6 @@ var t; if (Zotero.ItemFields.isMultiline(fieldName) || Zotero.ItemFields.isLong(fieldName)) { t = document.createElement("textarea"); - t.setAttribute('rows', 8); } // Add auto-complete for certain fields else if (field == 'creator' || Zotero.ItemFields.isAutocompleteField(fieldName)) { @@ -1732,6 +1731,18 @@ }); t.addEventListener('keypress', event => this.handleKeyPress(event)); + if (t instanceof HTMLTextAreaElement) { + let updateHeight = () => { + // Reset height before getting scrollHeight + // Prevents field from growing slightly each time + // https://stackoverflow.com/a/58073583 + t.style.height = 'auto'; + t.style.height = `calc(max(6em, ${t.scrollHeight}px))`; + }; + t.addEventListener('input', updateHeight); + updateHeight(); + } + return t; }