Fix: enable input but don't be allowed to submit when agent init (#1353)

* Fix: enable input but don't be allowed to submit when agent initializing.

* Prevent Enter from adding a newline when disabled.

---------

Co-authored-by: Jim Su <jimsu@protonmail.com>
Co-authored-by: Robert Brennan <accounts@rbren.io>
This commit is contained in:
Leo
2024-04-27 20:17:58 +08:00
committed by GitHub
parent 546be7ca8e
commit 6f90239521

View File

@@ -27,7 +27,9 @@ function ChatInput({ disabled, onSendMessage }: ChatInputProps) {
const onKeyPress = (event: React.KeyboardEvent<HTMLInputElement>) => {
if (event.key === "Enter" && !event.shiftKey && !isComposing) {
event.preventDefault(); // prevent a new line
handleSendChatMessage();
if (!disabled) {
handleSendChatMessage();
}
}
};
@@ -36,7 +38,6 @@ function ChatInput({ disabled, onSendMessage }: ChatInputProps) {
<Textarea
value={message}
onChange={(e) => setMessage(e.target.value)}
disabled={disabled}
onKeyDown={onKeyPress}
onCompositionStart={() => setIsComposing(true)}
onCompositionEnd={() => setIsComposing(false)}
@@ -54,6 +55,7 @@ function ChatInput({ disabled, onSendMessage }: ChatInputProps) {
<button
type="button"
onClick={handleSendChatMessage}
disabled={disabled}
className={twMerge(
"bg-transparent border rounded-lg p-1 border-white hover:opacity-80 cursor-pointer select-none absolute right-5 bottom-[19px] transition active:bg-white active:text-black",
disabled