Skip to content

Commit

Permalink
textarea autosize (#432)
Browse files Browse the repository at this point in the history
  • Loading branch information
an-lee committed Mar 22, 2024
1 parent 8fc8905 commit d2a777a
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions enjoy/src/renderer/pages/conversation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,17 @@ export default () => {
}, 500);
};

const resizeTextarea = () => {
if (!inputRef?.current) return;

inputRef.current.style.height = "auto";
inputRef.current.style.height = inputRef.current.scrollHeight + "px";
};

useEffect(() => {
resizeTextarea();
}, [content]);

useEffect(() => {
setOffest(0);
setContent(searchParams.get("text") || "");
Expand Down Expand Up @@ -299,27 +310,29 @@ export default () => {
</ScrollArea>
</MediaPlayerProvider>

<div className="px-4 absolute w-full bottom-0 left-0 h-14 bg-muted z-50">
<div className="focus-within:bg-background px-4 py-2 flex items-center space-x-4 rounded-lg border">
<div className="px-4 absolute w-full bottom-0 left-0 bg-muted z-50">
<div className="focus-within:bg-background pr-4 py-2 flex items-end space-x-4 rounded-lg shadow-lg border scrollbar">
<Textarea
ref={inputRef}
disabled={submitting}
value={content}
onChange={(e) => setContent(e.target.value)}
placeholder={t("pressEnterToSend")}
data-testid="conversation-page-input"
className="px-0 py-0 shadow-none border-none focus-visible:outline-0 focus-visible:ring-0 border-none bg-muted focus:bg-background min-h-[1.25rem] max-h-[3.5rem] !overflow-x-hidden"
className="text-base px-4 py-0 shadow-none border-none focus-visible:outline-0 focus-visible:ring-0 border-none bg-muted focus:bg-background min-h-[1rem] max-h-[70vh] scrollbar-thin scrollbar-thumb-sky-500 !overflow-x-hidden"
/>
<Button
type="submit"
ref={submitRef}
disabled={submitting || !content}
data-testid="conversation-page-submit"
onClick={() => handleSubmit(content)}
className=""
>
<SendIcon className="w-5 h-5" />
</Button>
<div className="h-12 py-1">
<Button
type="submit"
ref={submitRef}
disabled={submitting || !content}
data-testid="conversation-page-submit"
onClick={() => handleSubmit(content)}
className="h-10"
>
<SendIcon className="w-5 h-5" />
</Button>
</div>
</div>
</div>
</div>
Expand Down

0 comments on commit d2a777a

Please sign in to comment.