Skip to content

Commit 02fd55e

Browse files
committed
feat(input): resize on type
1 parent b6a9f4c commit 02fd55e

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

pages/index.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,20 @@ export default function Page() {
291291
rows={1}
292292
placeholder=""
293293
onKeyUp={(e) => {
294-
if (e.key === "Enter") {
294+
if (e.key === "Enter" && !e.shiftKey) {
295295
e.preventDefault()
296296
handleSubmit(onSubmit)()
297+
} else {
298+
const textarea = e.target as HTMLTextAreaElement
299+
textarea.style.height = "auto" // Reset the height to its default to allow it to shrink when deleting text
300+
textarea.style.height = `${textarea.scrollHeight}px` // Set the height to the scroll height so that it expands on new lines
297301
}
298302
}}
299303
className="max-h-52 h-6 overflow-y-hidden m-0 w-full resize-none border-0 bg-transparent p-0 pl-2 pr-7 focus:ring-0 focus-visible:ring-0 dark:bg-transparent md:pl-0"
300-
{...register("prompt", { required: true })}
304+
{...register("prompt", {
305+
required: true,
306+
disabled: streaming,
307+
})}
301308
/>
302309
<button
303310
type="submit"

0 commit comments

Comments
 (0)