Input
A text input on Base UI, sized to the 30px control.
With a label
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
export default function InputWithALabel() {
return (
<div className="grid w-full max-w-xs gap-2">
<Label htmlFor="input-project-name">Project name</Label>
<Input id="input-project-name" placeholder="Atlas onboarding" />
</div>
)
}
Types
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
export default function InputTypes() {
return (
<div className="grid w-full max-w-xs gap-4">
<div className="grid gap-2">
<Label htmlFor="input-email">Email</Label>
<Input id="input-email" type="email" autoComplete="email" placeholder="name@example.com" />
</div>
<div className="grid gap-2">
<Label htmlFor="input-password">Password</Label>
<Input id="input-password" type="password" autoComplete="new-password" />
</div>
<div className="grid gap-2">
<Label htmlFor="input-search">Search invoices</Label>
<Input id="input-search" type="search" placeholder="INV-2041" />
</div>
<div className="grid gap-2">
<Label htmlFor="input-seats">Seats</Label>
<Input id="input-seats" type="number" min={1} defaultValue={5} />
</div>
</div>
)
}
File
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
export default function InputFile() {
return (
<div className="grid w-full max-w-xs gap-2">
<Label htmlFor="input-receipt">Receipt</Label>
<Input id="input-receipt" type="file" accept="application/pdf,image/*" />
</div>
)
}
Disabled
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
export default function InputDisabled() {
return (
<div className="group grid w-full max-w-xs gap-2" data-disabled="true">
<Label htmlFor="input-workspace">Workspace address</Label>
<Input id="input-workspace" defaultValue="atlas.example.com" disabled />
</div>
)
}
Invalid
Enter an address with a domain, such as accounts@example.com.
import { Field, FieldError, FieldLabel } from "@/components/ui/field"
import { Input } from "@/components/ui/input"
export default function InputInvalid() {
return (
<Field data-invalid="true" className="max-w-xs">
<FieldLabel htmlFor="input-billing-email">Billing email</FieldLabel>
<Input
id="input-billing-email"
type="email"
defaultValue="accounts@example"
aria-invalid
aria-describedby="input-billing-email-error"
/>
<FieldError id="input-billing-email-error">Enter an address with a domain, such as accounts@example.com.</FieldError>
</Field>
)
}
Installation
npx shadcn@latest add @khaeli/inputbunx --bun shadcn@latest add @khaeli/inputInstall @khaeli/foundation first: this item's styling lives in its tokens and [data-slot] rules.
Installs with
- Registry items
- npm packages
- @base-ui/react ^1.7.0
Keyboard
Tab- Moves focus to the input. A
disabledinput leaves the tab order. ArrowUpArrowDown- On
type="number", raise and lower the value by itsstep. Escape- On
type="search", clears the text in Chromium. Space- On
type="file", opens the browser's file chooser.
Accessible name
- Every input needs a name. Give it an
idand point a @khaeli/label at it withhtmlFor. - A placeholder is not a name: it goes as soon as something is typed. Use it for an example of the value.
- Where a visible label would repeat what is beside the input, such as a search box next to a Search button, use
aria-label. - An invalid control carries
aria-invalidand lists theidof its message inaria-describedby, so the message is read as its description. @khaeli/field lays the label, control and message out.
Registry JSON
The item as the shadcn CLI reads it, with every file it ships: https://ui.khaeli.com/r/input.json