Auto set number of rows for workout note edit textarea

This commit is contained in:
Peter Stockings
2023-07-12 21:40:07 +10:00
parent 7d1bb0b291
commit 8802d37124

View File

@@ -18,7 +18,7 @@
<div class="flex items-center"> <div class="flex items-center">
<textarea <textarea
class="block ml-1 p-2.5 w-full text-sm text-gray-900 bg-white rounded-lg border border-gray-300 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-800 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" class="block ml-1 p-2.5 w-full text-sm text-gray-900 bg-white rounded-lg border border-gray-300 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-800 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
placeholder="Your note..." name="note" rows="2">{{ note }}</textarea> placeholder="Your note..." name="note">{{ note }}</textarea>
<div class="flex flex-col"> <div class="flex flex-col">
<button <button
class="inline-flex justify-center p-2 text-blue-600 rounded-full cursor-pointer hover:bg-blue-100 dark:text-blue-500 dark:hover:bg-gray-600" class="inline-flex justify-center p-2 text-blue-600 rounded-full cursor-pointer hover:bg-blue-100 dark:text-blue-500 dark:hover:bg-gray-600"
@@ -42,6 +42,18 @@
<span class="sr-only">Save note</span> <span class="sr-only">Save note</span>
</button> </button>
</div> </div>
<script>
(function () {
const tx = document.querySelector('#workout-note textarea');
tx.setAttribute("style", "height:" + (tx.scrollHeight) + "px;overflow-y:hidden;");
tx.addEventListener("input", OnInput, false);
function OnInput() {
this.style.height = 0;
this.style.height = (this.scrollHeight) + "px";
}
})();
</script>
</div> </div>
{% endif %} {% endif %}
</div> </div>