Skip to content

Commit

Permalink
Allows input while generating answer
Browse files Browse the repository at this point in the history
  • Loading branch information
wong2 committed Mar 12, 2023
1 parent 844397d commit 5f3404b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/app/components/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,28 @@ type Props = TextareaAutosizeProps & {
}

const TextInput = React.forwardRef<HTMLTextAreaElement, Props>((props, ref) => {
const { className, value = '', onValueChange, minRows = 1, formref, ...textareaProps } = props
const { className, value = '', onValueChange, minRows = 1, formref, disabled, ...textareaProps } = props

const onKeyDown: KeyboardEventHandler<HTMLTextAreaElement> = useCallback(
(e) => {
if (e.keyCode === 13) {
e.preventDefault()
if (e.shiftKey) {
onValueChange(value + '\n')
} else {
} else if (!disabled) {
formref?.current?.requestSubmit()
}
}
},
[formref, onValueChange, value],
[disabled, formref, onValueChange, value],
)

return (
<TextareaAutosize
ref={ref}
className={cx(
'resize-none overflow-hidden w-full outline-none text-sm text-[#303030] disabled:cursor-wait bg-white',
'resize-none overflow-hidden w-full outline-none text-sm text-[#303030] bg-white',
disabled && 'cursor-wait',
className,
)}
onKeyDown={onKeyDown}
Expand Down

0 comments on commit 5f3404b

Please sign in to comment.