From 39e5f4611542d7824a4b30a6353666b46e4fac33 Mon Sep 17 00:00:00 2001 From: bprize15 Date: Tue, 17 Sep 2024 16:27:28 -0400 Subject: [PATCH] resize text area when input changes --- .../shared/firebase/input/RealtimeBasicInput.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/webapp/app/shared/firebase/input/RealtimeBasicInput.tsx b/src/main/webapp/app/shared/firebase/input/RealtimeBasicInput.tsx index b2d1451cf..d7cf55cf4 100644 --- a/src/main/webapp/app/shared/firebase/input/RealtimeBasicInput.tsx +++ b/src/main/webapp/app/shared/firebase/input/RealtimeBasicInput.tsx @@ -127,8 +127,7 @@ const RealtimeBasicInput: React.FunctionComponent = (props: const resizeObserver = new ResizeObserver(() => { window.requestAnimationFrame(() => { - input.style.height = 'auto'; - input.style.height = `${input.scrollHeight}px`; + resizeTextArea(input); }); }); resizeObserver.observe(input); @@ -155,6 +154,11 @@ const RealtimeBasicInput: React.FunctionComponent = (props: if (onChange) { onChange(e); } + + const input = inputRef.current; + if (type === RealtimeInputType.TEXTAREA && input) { + resizeTextArea(input); + } }; function isChecked() { @@ -164,6 +168,11 @@ const RealtimeBasicInput: React.FunctionComponent = (props: return label === RADIO_OPTION_NONE; } + function resizeTextArea(textArea: HTMLInputElement | HTMLTextAreaElement) { + textArea.style.height = 'auto'; + textArea.style.height = `${textArea.scrollHeight}px`; + } + const inputStyle: React.CSSProperties | undefined = isCheckType ? { marginRight: '0.25rem', ...style } : undefined; const inputComponent = ( <>