Input
Displays a form input field or a component that looks like an input field.
tsx
import { Input } from "@/components/ui/input"
export function InputDemo() { return <Input type="email" placeholder="Email" />}
Installation
CLI
bash
npx fivui add input
Manual
Copy and paste the following code into your project.
components/ui/input.tsx
import * as React from "react"
import { cn } from "@/lib/utils"
export interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {}
const Input = React.forwardRef<HTMLInputElement, InputProps>( ({ className, type, ...props }, ref) => { return ( <input type={type} className={cn( "flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background 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-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50", className )} ref={ref} {...props} /> ) })Input.displayName = "Input"
export { Input }
Usage
tsx
import { Input } from "@/components/ui/input"
tsx
<Input />
Examples
Default
tsx
import { Input } from "@/components/ui/input"
export function InputDemo() { return <Input type="email" placeholder="Email" />}
File
tsx
import { Input } from "@/components/ui/input"import { Label } from "@/components/ui/label"
export function InputFile() { return ( <div className="grid w-full max-w-sm items-center gap-1.5"> <Label htmlFor="picture">Picture</Label> <Input id="picture" type="file" /> </div> )}
Disabled
tsx
import { Input } from "@/components/ui/input"
export function InputDisabled() { return <Input disabled type="email" placeholder="Email" />}
With Label
tsx
import { Input } from "@/components/ui/input"import { Label } from "@/components/ui/label"
export function InputWithLabel() { return ( <div className="grid w-full max-w-sm items-center gap-1.5"> <Label htmlFor="email">Email</Label> <Input type="email" id="email" placeholder="Email" /> </div> )}
With Button
tsx
import { Button } from "@/components/ui/button"import { Input } from "@/components/ui/input"
export function InputWithButton() { return ( <div className="flex w-full max-w-sm items-center space-x-2"> <Input type="email" placeholder="Email" /> <Button type="submit">Subscribe</Button> </div> )}
Password
tsx
import { Input } from "@/components/ui/input"import { Label } from "@/components/ui/label"
export function InputPassword() { return ( <div className="grid w-full max-w-sm items-center gap-1.5"> <Label htmlFor="password">Password</Label> <Input type="password" id="password" placeholder="Password" /> </div> )}
API Reference
Input
Prop | Type | Default | Description |
---|---|---|---|
type | string | "text" | The type of input (text, email, password, etc.) |
placeholder | string | - | Placeholder text to display when the input is empty |
disabled | boolean | false | When true, prevents the user from interacting with the input |
value | string | - | The controlled value of the input |
onChange | function | - | Event handler called when the input value changes |
Input inherits all props from the standard HTML input
element.