Input Field
A form field input designed to be used with react-hook-form and Zod for validation. It combines a label, input, error handling, and optional description into a single reusable component.
Installation
npx shadcn@latest add https://shuip.xyz/r/input-field.json
Preview
Less verbose code in forms
<FormFieldcontrol={form.control}name="email"render={({ field }) => (<FormItem><FormLabel>Email</FormLabel><FormControl><Input placeholder="your@email.com" {...field} /></FormControl><FormDescription>Your email address</FormDescription><FormMessage /></FormItem>)}/>
With InputField
, the same result in a single line:
<InputFieldregister={form.register('email')}label="Email"description="Your email address"placeholder="your@email.com"/>
Built-in features
- Automatic type handling: Native support for
text
,password
,number
- Visibility toggle: Automatic eye/eye-off button for password fields
- Zod validation: Native integration with react-hook-form and Zod
- Error display: Responsive error messages (hidden on mobile at top, shown at bottom)
- Automatic conversion:
number
fields automatically convert values
react-hook-form integration
The component is specifically designed for react-hook-form:
const form = useForm({defaultValues: { name: '', age: 0 },resolver: zodResolver(schema),});// Direct usage with form register<InputField register={form.register('name')} label="Name" /><InputField register={form.register('age')} label="Age" type="number" />
Examples
Default
Props
Name | Type | Description |
---|---|---|
register | UseFormRegisterReturn | react-hook-form register function result |
label | string | Label displayed above the field |
description | string? | Optional description below the field |
type | string? | HTML field type (text, password, email, number...) |
...props | InputProps | All shadcn/ui Input props |