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>( const ChatInput = React.forwardRef<HTMLTextAreaElement, ChatInputProps>(
({ className, ...props }, ref) => ( ({ className, ...props }, ref) => (
<Textarea <Textarea
mockOnChange={false}
autoComplete="off" autoComplete="off"
ref={ref} ref={ref}
name="message" name="message"

View File

@@ -1,16 +1,22 @@
import * as React from "react"; import { forwardRef, ComponentProps, useState } from "react";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
const Textarea = React.forwardRef< const Textarea = forwardRef<
HTMLTextAreaElement, HTMLTextAreaElement,
React.ComponentProps<"textarea"> ComponentProps<"textarea"> & { mockOnChange?: boolean }
>(({ className, value, onChange, ...props }, ref) => { >(({ className, value, onChange, mockOnChange = true, ...props }, ref) => {
const [innerValue, setInnerValue] = React.useState(value); const [innerValue, setInnerValue] = useState(value);
return ( return (
<textarea <textarea
value={innerValue} value={mockOnChange ? innerValue : value}
onChange={(e) => setInnerValue(e.target.value)} onChange={(e) => {
if (mockOnChange) {
setInnerValue(e.target.value);
} else {
onChange?.(e);
}
}}
className={cn( 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", "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 className