- Accordion
- Agent Thinking
- Alert
- Alert Dialog
- Announcement
- Aspect Ratio
- Attachment
- Avatar
- Badge
- Breadcrumb
- Bubble
- Button
- Button Group
- Calendar
- Card
- Carousel
- Checkbox
- Checkbox Card
- Code Block
- Collapsible
- Color Picker
- Combobox
- Command
- Composer
- Composer Loader
- Context Menu
- Data Grid
- Data Table
- Date Picker
- Dialog
- Direction
- Drawer
- Dropdown Menu
- Empty
- Field
- File Upload
- Hover Card
- Input
- Input Group
- Input Otp
- Item
- Kbd
- Label
- Marker
- Menubar
- Message
- Message Scroller
- Meter
- Native Select
- Navigation Menu
- Number Field
- Pagination
- Period Switcher
- Popover
- Progress
- Questionnaire
- Radio Card
- Radio Group
- Resizable
- Reveal
- Scroll Area
- Search Field
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Social Button
- Sonner
- Spinner
- Status Dot
- Switch
- Switch Card
- Table
- Tabs
- Tag Group
- Textarea
- Theme Toggle
- Time Field
- Toggle
- Toggle Group
- Tooltip
- Trace
- Tree View
- Agent Creator 01
- Agent Limits Card 01
- Agent Progress 01
- AI Chat 01
- AI Image Generation 01
- AI Profile 01
- Alerts Card 01
- Auth Card 01
- Calendar 01
- Composer 01
- Composer Attachments 01
- Composer Panel 01
- Finance Dashboard 01
- Home Dashboard 01
- Marketing Dashboard 01
- Medical Profile 01
- Meeting Scheduler 01
- Multi Agent Chat 01
- Notification Center 01
- Patient Info Card 01
- Project Board 01
- Questionnaire 01
- Settings Modal 01
- Sidebar 01
- Stat Cards 01
- Task List 01
- Web Search 01
- Activity Rings Card 01
- Area Chart Card 01
- Bar List Card 01
- Combo Chart Card 01
- Contributions Card 01
- Earnings Chart Card 01
- Funnel Chart Card 01
- Heatmap Chart Card 01
- Line Chart Card 01
- Most Active Days Card 01
- Orders Chart Card 01
- Radar Chart Card 01
- Radial Chart Card 01
- Revenue Chart Card 01
- Sankey Chart Card 01
- Scatter Chart Card 01
- Sleep Score Card 01
- Stage Bars Card 01
- Steps Card 01
This is a hint about this input.
Installation
$ pnpm dlx shadcn@latest add @cobalt/input
Sizes
This is a hint about this input.
This is a hint about this input.
States
This is a hint about this input.
This is a hint about this input.
This is a hint about this input.
This is a hint about this input.
Error message
Set aria-invalid on the input and render a FieldError under it.
Options
size="sm"is 32px tall andsize="xs"is 24px tall. A number still sets the nativesizeattribute.variant="ghost"removes the fill, padding, radius and rings, for inline editing inside another surface.
Source
import { Input as InputPrimitive } from "@base-ui/react/input";
import { cn } from "cn";
import * as React from "react";
function Input({
className,
type,
size,
variant = "default",
...props
}: Omit<React.ComponentProps<"input">, "size"> & {
size?: "default" | "sm" | "xs" | number;
/** `ghost` removes the fill, padding and rings, for inline editing. */
variant?: "default" | "ghost";
}) {
return (
<InputPrimitive
type={type}
data-slot="input"
data-size={typeof size === "string" ? size : "default"}
data-variant={variant}
size={typeof size === "number" ? size : undefined}
className={cn(
// cobalt-allow-focus-within -- text input
"h-9 w-full min-w-0 rounded-[10px] border-0 bg-[var(--surface-strong,var(--muted))] px-3 py-2 text-base text-foreground ring-2 ring-transparent ring-inset outline-none transition-[background-color,box-shadow,color] duration-150 ease-[ease] motion-reduce:transition-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-[color:var(--foreground-subtle,var(--muted-foreground))] hover:not-focus:not-disabled:not-aria-invalid:ring-[var(--border-hover,var(--border))] focus:not-disabled:not-aria-invalid:ring-[var(--foreground-subtle,var(--ring))] focus:placeholder:text-foreground disabled:cursor-not-allowed disabled:bg-[var(--input-disabled-surface,var(--muted))] disabled:text-[color:var(--input-disabled-foreground,var(--muted-foreground))] disabled:placeholder:text-[color:var(--input-disabled-foreground,var(--muted-foreground))] aria-invalid:bg-[var(--input-invalid-surface,color-mix(in_srgb,var(--destructive)_15%,transparent))] aria-invalid:placeholder:text-[color:var(--input-invalid-placeholder,var(--destructive))] md:text-sm data-[size=sm]:h-8 data-[size=sm]:px-2.5 data-[size=xs]:h-6 data-[size=xs]:rounded-[8px] data-[size=xs]:p-1.5 data-[size=xs]:text-xs data-[size=xs]:md:text-xs",
variant === "ghost" &&
// 2px on the left so the caret is not cut in half at the box edge.
// cobalt-allow-focus-within -- text input
"rounded-none bg-transparent py-0 pr-0 pl-0.5 hover:not-focus:not-disabled:not-aria-invalid:ring-transparent focus:not-disabled:not-aria-invalid:ring-transparent disabled:bg-transparent focus:placeholder:text-[color:var(--foreground-subtle,var(--muted-foreground))] data-[size=sm]:pr-0 data-[size=sm]:pl-0.5 data-[size=xs]:rounded-none data-[size=xs]:py-0 data-[size=xs]:pr-0 data-[size=xs]:pl-0.5",
className
)}
{...props}
/>
);
}
export { Input };