Skip to content

Commit

Permalink
ui(chat): increase textarea size with user input
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcMcIntosh committed Feb 12, 2024
1 parent 6bdda38 commit edfd0b1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/components/TextArea/TextArea.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
border: none;
box-shadow: none;
outline: none;
max-height: 50dvh;
}

.textarea :global(.rt-TextAreaInput) {
Expand Down
16 changes: 14 additions & 2 deletions src/components/TextArea/TextArea.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useEffect, useImperativeHandle, useRef } from "react";
import { TextArea as RadixTextArea } from "@radix-ui/themes";
import classNames from "classnames";
import styles from "./TextArea.module.css";
Expand All @@ -10,11 +10,23 @@ export type TextAreaProps = React.ComponentProps<typeof RadixTextArea> & {

export const TextArea = React.forwardRef<HTMLTextAreaElement, TextAreaProps>(
(props, ref) => {
const innerRef = useRef<HTMLTextAreaElement>(null);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
useImperativeHandle(ref, () => innerRef.current!, []);

useEffect(() => {
if (innerRef.current) {
innerRef.current.style.height = "1px";
innerRef.current.style.height =
2 + innerRef.current.scrollHeight + "px";
}
}, [innerRef.current?.value]);

return (
<RadixTextArea
{...props}
className={classNames(styles.textarea, props.className)}
ref={ref}
ref={innerRef}
/>
);
},
Expand Down

0 comments on commit edfd0b1

Please sign in to comment.