Skip to content

Commit

Permalink
fix: test for no-default-values & fix
Browse files Browse the repository at this point in the history
  • Loading branch information
airjp73 committed Jun 17, 2024
1 parent 0e8cbca commit c39ceeb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/dom/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ export const getNextNativeValue = ({
}

if (element.type === "number") {
if (typeof currentValue === "number") return Number(derivedValue);
return String(derivedValue);
if (typeof currentValue === "string") return String(derivedValue);
return Number(derivedValue);
}

return derivedValue;
Expand Down
26 changes: 26 additions & 0 deletions packages/react/src/test/input-types.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,32 @@ describe("number inputs", () => {
expect(screen.getByTestId("age-value").textContent).toEqual("254");
});

it("no default value", async () => {
const TestComp = () => {
const form = useForm({
validator: successValidator,
});

return (
<form {...form.getFormProps()}>
<input
data-testid="age"
{...form.field("age").getInputProps({ type: "number" })}
/>
<pre data-testid="age-value">{JSON.stringify(form.value("age"))}</pre>
</form>
);
};
render(<TestComp />);

expect(screen.getByTestId("age")).not.toHaveValue();
expect(screen.getByTestId("age-value").textContent).toEqual("");

await userEvent.type(screen.getByTestId("age"), "4");
expect(screen.getByTestId("age")).toHaveValue(4);
expect(screen.getByTestId("age-value").textContent).toEqual("4");
});

it("default values set as strings", async () => {
const TestComp = () => {
const form = useForm({
Expand Down

0 comments on commit c39ceeb

Please sign in to comment.