Fix/1307 input on value change (#1309)

* fix(input): inner event handler implemented

* chore(root): changeset added
This commit is contained in:
Junior Garcia 2023-08-07 23:31:16 -03:00 committed by GitHub
parent 5b343b6181
commit ac605eb71f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 7 deletions

View File

@ -0,0 +1,5 @@
---
"@nextui-org/input": patch
---
onValueChange returned value fixed, it nows return a plain string

View File

@ -179,9 +179,9 @@ const MyButton2 = extendVariants(Button, {
});
export default function NextUIPerf() {
const [textA, setTextA] = useState<string | undefined>("");
const [textB, setTextB] = useState<string | undefined>("");
const [textC, setTextC] = useState<string | undefined>("");
const [textA, setTextA] = useState<string>("");
const [textB, setTextB] = useState<string>("");
const [textC, setTextC] = useState<string>("");
return (
<div className="w-full p-24 gap-4 flex flex-col">

View File

@ -58,7 +58,7 @@ export interface Props<T extends HTMLInputElement | HTMLTextAreaElement = HTMLIn
/**
* React aria onChange event.
*/
onValueChange?: (value: string | undefined) => void;
onValueChange?: (value: string) => void;
}
export type UseInputProps<T extends HTMLInputElement | HTMLTextAreaElement = HTMLInputElement> =
@ -86,10 +86,17 @@ export function useInput<T extends HTMLInputElement | HTMLTextAreaElement = HTML
...otherProps
} = props;
const handleValueChange = useCallback(
(value: string | undefined) => {
onValueChange(value ?? "");
},
[onValueChange],
);
const [inputValue, setInputValue] = useControlledState<string | undefined>(
props.value,
props.defaultValue,
onValueChange,
props.value ?? undefined,
props.defaultValue ?? undefined,
handleValueChange,
);
const Component = as || "div";