fix: mockOnChange on user input textarea

This commit is contained in:
2025-01-08 10:46:08 +08:00
parent 74775b5265
commit f0db9e6b03
2 changed files with 14 additions and 7 deletions

View File

@@ -8,6 +8,7 @@ interface ChatInputProps
const ChatInput = React.forwardRef<HTMLTextAreaElement, ChatInputProps>(
({ className, ...props }, ref) => (
<Textarea
mockOnChange={false}
autoComplete="off"
ref={ref}
name="message"

View File

@@ -1,16 +1,22 @@
import * as React from "react";
import { forwardRef, ComponentProps, useState } from "react";
import { cn } from "@/lib/utils";
const Textarea = React.forwardRef<
const Textarea = forwardRef<
HTMLTextAreaElement,
React.ComponentProps<"textarea">
>(({ className, value, onChange, ...props }, ref) => {
const [innerValue, setInnerValue] = React.useState(value);
ComponentProps<"textarea"> & { mockOnChange?: boolean }
>(({ className, value, onChange, mockOnChange = true, ...props }, ref) => {
const [innerValue, setInnerValue] = useState(value);
return (
<textarea
value={innerValue}
onChange={(e) => setInnerValue(e.target.value)}
value={mockOnChange ? innerValue : value}
onChange={(e) => {
if (mockOnChange) {
setInnerValue(e.target.value);
} else {
onChange?.(e);
}
}}
className={cn(
"flex min-h-[60px] w-full rounded-md border border-input bg-transparent px-3 py-2 text-base shadow-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
className