From 77ac7de716f1854abe3eeb9444022d4c7fa6b757 Mon Sep 17 00:00:00 2001 From: OFF0 Date: Fri, 17 Mar 2023 10:35:04 +0100 Subject: [PATCH] utils: move updateelemheight to dom utils --- src/main.js | 13 +------------ src/utils/dom.ts | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/main.js b/src/main.js index ebdb7ee..01a0b11 100644 --- a/src/main.js +++ b/src/main.js @@ -1,6 +1,6 @@ import {generatePrivateKey, getPublicKey, nip19, signEvent} from 'nostr-tools'; import {zeroLeadingBitsCount} from './utils/crypto'; -import {elem, elemCanvas, elemShrink, parseTextContent} from './utils/dom'; +import {elem, elemCanvas, elemShrink, parseTextContent, updateElemHeight} from './utils/dom'; import {bounce, dateTime, formatTime} from './utils/time'; import {getHost, getNoxyUrl, isWssUrl} from './utils/url'; import {powEvent} from './system'; @@ -561,17 +561,6 @@ writeInput.addEventListener('input', () => { }); writeInput.addEventListener('blur', () => sendStatus.textContent = ''); -function updateElemHeight(el) { - el.style.removeProperty('height'); - if (el.value) { - el.style.paddingBottom = 0; - el.style.paddingTop = 0; - el.style.height = el.scrollHeight + 'px'; - el.style.removeProperty('padding-bottom'); - el.style.removeProperty('padding-top'); - } -} - diff --git a/src/utils/dom.ts b/src/utils/dom.ts index 81e9d7f..5088a5b 100644 --- a/src/utils/dom.ts +++ b/src/utils/dom.ts @@ -162,3 +162,17 @@ export const elemShrink = (el: HTMLElement) => { shrink.addEventListener('animationend', () => shrink.remove(), {once: true}); return shrink; }; + + +export const updateElemHeight = ( + el: HTMLInputElement | HTMLTextAreaElement +) => { + el.style.removeProperty('height'); + if (el.value) { + el.style.paddingBottom = '0'; + el.style.paddingTop = '0'; + el.style.height = el.scrollHeight + 'px'; + el.style.removeProperty('padding-bottom'); + el.style.removeProperty('padding-top'); + } +};