fix: mockOnChange on user input textarea
This commit is contained in:
@@ -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"
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user