Skip to content

Commit b8d3a37

Browse files
author
taku10101
committed
fix: form component ui
1 parent 4ae5b31 commit b8d3a37

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

src/components/form/InputField.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useFormContext } from "react-hook-form";
2+
import { Input } from "../ui/Field";
23

34
type Props = {
45
name: string;
@@ -9,7 +10,7 @@ function InputField(props: Props) {
910

1011
return (
1112
<>
12-
<input {...methods.register(props.name)} />
13+
<Input {...methods.register(props.name)} />
1314
{methods.formState.errors[props.name] && (
1415
<p>{methods.formState.errors[props.name]?.message as string}</p>
1516
)}

src/components/form/SampleForm.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import { useForm, FormProvider } from "react-hook-form";
22
import { zodResolver } from "@hookform/resolvers/zod";
33
import InputField from "./InputField";
44
import SelectField from "./SelectField";
5-
import { Button } from "../ui/Button/Button";
5+
import { Button } from "../ui/Button/";
66
import { z } from "zod";
7+
import { Form } from "../ui/Form";
78
const sampleFormSchema = z.object({
89
input: z.string().min(1),
910
select: z.string().min(1),
@@ -16,11 +17,11 @@ const SampleForm = () => {
1617
const { handleSubmit } = methods;
1718
return (
1819
<FormProvider {...methods}>
19-
<form onSubmit={handleSubmit((data) => console.log(data))}>
20+
<Form onSubmit={handleSubmit((data) => console.log(data))}>
2021
<InputField name='input' />
2122
<SelectField name='select' />
2223
<Button type='submit'>Submit</Button>
23-
</form>
24+
</Form>
2425
</FormProvider>
2526
);
2627
}

src/components/form/SelectField.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useFormContext } from "react-hook-form";
2+
import { Select } from "../ui/Select";
23
const options = ["", "one", "two", "three"];
34
type Props = {
45
name: string;
@@ -7,13 +8,13 @@ function SelectField(props: Props) {
78
const methods = useFormContext();
89
return (
910
<>
10-
<select {...methods.register(props.name)}>
11+
<Select {...methods.register(props.name)}>
1112
{options.map((value) => (
1213
<option key={value} value={value}>
1314
{value}
1415
</option>
1516
))}
16-
</select>
17+
</Select>
1718

1819
{methods.formState.errors[props.name] && (
1920
<p>{methods.formState.errors[props.name]?.message as string}</p>

0 commit comments

Comments
 (0)