refactor: Input, Textarea maintain their own value, fix #8
This commit is contained in:
@@ -141,7 +141,7 @@ const SelectModel = (props: { help: string }) => {
|
|||||||
{useCustomModel ? (
|
{useCustomModel ? (
|
||||||
<Input
|
<Input
|
||||||
value={chatStore.model}
|
value={chatStore.model}
|
||||||
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
|
onBlur={(e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
chatStore.model = e.target.value;
|
chatStore.model = e.target.value;
|
||||||
setChatStore({ ...chatStore });
|
setChatStore({ ...chatStore });
|
||||||
}}
|
}}
|
||||||
@@ -205,7 +205,7 @@ const LongInput = (props: {
|
|||||||
<Textarea
|
<Textarea
|
||||||
className="h-24 w-full"
|
className="h-24 w-full"
|
||||||
value={chatStore[props.field]}
|
value={chatStore[props.field]}
|
||||||
onChange={async (event: any) => {
|
onBlur={async (event: any) => {
|
||||||
chatStore[props.field] = event.target.value;
|
chatStore[props.field] = event.target.value;
|
||||||
await setChatStore({ ...chatStore });
|
await setChatStore({ ...chatStore });
|
||||||
autoHeight(event.target);
|
autoHeight(event.target);
|
||||||
@@ -257,7 +257,7 @@ const InputField = (props: {
|
|||||||
<Input
|
<Input
|
||||||
type={hideInput ? "password" : "text"}
|
type={hideInput ? "password" : "text"}
|
||||||
value={chatStore[props.field]}
|
value={chatStore[props.field]}
|
||||||
onChange={(event: React.ChangeEvent<HTMLInputElement>) => {
|
onBlur={(event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
chatStore[props.field] = event.target.value;
|
chatStore[props.field] = event.target.value;
|
||||||
setChatStore({ ...chatStore });
|
setChatStore({ ...chatStore });
|
||||||
}}
|
}}
|
||||||
@@ -351,7 +351,7 @@ const Slicer = (props: {
|
|||||||
disabled={!enabled}
|
disabled={!enabled}
|
||||||
className="w-24"
|
className="w-24"
|
||||||
value={chatStore[props.field]}
|
value={chatStore[props.field]}
|
||||||
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
|
onBlur={(e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
const value = parseFloat(e.target.value);
|
const value = parseFloat(e.target.value);
|
||||||
chatStore[props.field] = value;
|
chatStore[props.field] = value;
|
||||||
setChatStore({ ...chatStore });
|
setChatStore({ ...chatStore });
|
||||||
@@ -415,7 +415,7 @@ const Number = (props: {
|
|||||||
props.field === "maxGenTokens" && !chatStore.maxGenTokens_enabled
|
props.field === "maxGenTokens" && !chatStore.maxGenTokens_enabled
|
||||||
}
|
}
|
||||||
value={chatStore[props.field]}
|
value={chatStore[props.field]}
|
||||||
onChange={(event: React.ChangeEvent<HTMLInputElement>) => {
|
onBlur={(event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
let newNumber = parseFloat(event.target.value);
|
let newNumber = parseFloat(event.target.value);
|
||||||
if (newNumber < 0) newNumber = 0;
|
if (newNumber < 0) newNumber = 0;
|
||||||
chatStore[props.field] = newNumber;
|
chatStore[props.field] = newNumber;
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
import * as React from "react";
|
import { useState, ComponentProps, forwardRef } from "react";
|
||||||
|
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
const Input = React.forwardRef<HTMLInputElement, React.ComponentProps<"input">>(
|
const Input = forwardRef<HTMLInputElement, ComponentProps<"input">>(
|
||||||
({ className, type, ...props }, ref) => {
|
({ className, type, value, ...props }, ref) => {
|
||||||
|
const [innerValue, setInnerValue] = useState(value);
|
||||||
return (
|
return (
|
||||||
<input
|
<input
|
||||||
|
value={innerValue}
|
||||||
|
onChange={(e) => setInnerValue(e.target.value)}
|
||||||
type={type}
|
type={type}
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground 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 h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground 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",
|
||||||
|
|||||||
@@ -5,9 +5,12 @@ import { cn } from "@/lib/utils";
|
|||||||
const Textarea = React.forwardRef<
|
const Textarea = React.forwardRef<
|
||||||
HTMLTextAreaElement,
|
HTMLTextAreaElement,
|
||||||
React.ComponentProps<"textarea">
|
React.ComponentProps<"textarea">
|
||||||
>(({ className, ...props }, ref) => {
|
>(({ className, value, onChange, ...props }, ref) => {
|
||||||
|
const [innerValue, setInnerValue] = React.useState(value);
|
||||||
return (
|
return (
|
||||||
<textarea
|
<textarea
|
||||||
|
value={innerValue}
|
||||||
|
onChange={(e) => setInnerValue(e.target.value)}
|
||||||
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