Skip to content

Commit

Permalink
resize text area when input changes (#440)
Browse files Browse the repository at this point in the history
  • Loading branch information
bprize15 authored Sep 19, 2024
1 parent 860dbab commit 5cc5a79
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/main/webapp/app/shared/firebase/input/RealtimeBasicInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ const RealtimeBasicInput: React.FunctionComponent<IRealtimeBasicInput> = (props:

const resizeObserver = new ResizeObserver(() => {
window.requestAnimationFrame(() => {
input.style.height = 'auto';
input.style.height = `${input.scrollHeight}px`;
resizeTextArea(input);
});
});
resizeObserver.observe(input);
Expand All @@ -155,6 +154,11 @@ const RealtimeBasicInput: React.FunctionComponent<IRealtimeBasicInput> = (props:
if (onChange) {
onChange(e);
}

const input = inputRef.current;
if (type === RealtimeInputType.TEXTAREA && input) {
resizeTextArea(input);
}
};

function isChecked() {
Expand All @@ -164,6 +168,11 @@ const RealtimeBasicInput: React.FunctionComponent<IRealtimeBasicInput> = (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 = (
<>
Expand Down

0 comments on commit 5cc5a79

Please sign in to comment.