Components
- Accordion
- Alert
- Alert Dialog
- Autocomplete
- Avatar
- Badge
- Breadcrumb
- Button
- Card
- Checkbox
- Checkbox Group
- Collapsible
- Combobox
- Dialog
- EmptyNew
- Field
- Fieldset
- Form
- Frame
- Group
- Input
- Input GroupNew
- KbdNew
- Label
- Menu
- Meter
- Number Field
- Pagination
- Popover
- Preview Card
- Progress
- Radio Group
- Scroll Area
- Select
- Separator
- Sheet
- SkeletonNew
- Slider
- SpinnerNew
- Switch
- Table
- Tabs
- Textarea
- Toast
- Toggle
- Toggle Group
- Toolbar
- Tooltip
Resources
Input
A native input element.
import { Input } from "@/components/ui/input";
export default function Particle() {
return <Input aria-label="Enter text" placeholder="Enter text" type="text" />;
}
Installation
pnpm dlx shadcn@latest add @coss/input
Usage
import { Input } from "@/components/ui/input"<Input />Examples
For accessible labelling and validation, prefer using the Field component to wrap inputs, or the FieldControl component. See some related examples.
Small Size
import { Input } from "@/components/ui/input";
export default function Particle() {
return (
<Input
aria-label="Enter text"
placeholder="Enter text"
size="sm"
type="text"
/>
);
}
Large Size
import { Input } from "@/components/ui/input";
export default function Particle() {
return (
<Input
aria-label="Enter text"
placeholder="Enter text"
size="lg"
type="text"
/>
);
}
Disabled
import { Input } from "@/components/ui/input";
export default function Particle() {
return (
<Input aria-label="Disabled" disabled placeholder="Disabled" type="text" />
);
}
File
import { Input } from "@/components/ui/input";
export default function Particle() {
return <Input aria-label="File" type="file" />;
}
With Label
import { useId } from "react";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
export default function Particle() {
const id = useId();
return (
<div className="flex flex-col items-start gap-2">
<Label htmlFor={id}>Email</Label>
<Input
aria-label="Email"
id={id}
placeholder="[email protected]"
type="email"
/>
</div>
);
}
With Button
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
export default function Particle() {
return (
<div className="flex gap-2">
<Input aria-label="Email" placeholder="[email protected]" type="email" />
<Button variant="outline">Send</Button>
</div>
);
}
Form Integration
"use client";
import * as React from "react";
import { Button } from "@/components/ui/button";
import { Field, FieldError, FieldLabel } from "@/components/ui/field";
import { Form } from "@/components/ui/form";
import { Input } from "@/components/ui/input";
export default function Particle() {
const [loading, setLoading] = React.useState(false);
const onSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
const formData = new FormData(e.currentTarget);
setLoading(true);
await new Promise((r) => setTimeout(r, 800));
setLoading(false);
alert(`Email: ${formData.get("email") || ""}`);
};
return (
<Form className="max-w-64" onSubmit={onSubmit}>
<Field>
<FieldLabel>Email</FieldLabel>
<Input
disabled={loading}
name="email"
placeholder="[email protected]"
required
type="email"
/>
<FieldError>Please enter a valid email.</FieldError>
</Field>
<Button disabled={loading} type="submit">
Submit
</Button>
</Form>
);
}
Comparing with shadcn
Compared to shadcn/ui, our Input component includes size variants for better density control. shadcn/ui inputs have a fixed height of 36px, while our component offers flexible sizing with sm (28px), default (32px), and lg (36px) options.
So, if you want to preserve the original shadcn/ui input height (36px), you should use the lg size in coss ui.