Forms
Input
Free12.7 KB gzippedA single-line text field built on the native <input>. Supports every text-like type (text, email, url, tel, number, search, password, date, ...), addons, decorative icons, interactive slots, a clear button, and a loading state.
Accessibility: WCAG 2.2 AA · No A or AA violations in light or dark mode · Keys: Tab · Full report
Import
import { Input } from "@vjdesigns/vjdesigns-ui";
Importing only Input adds about 12.7 KB of minified, gzipped JavaScript to your app (React not included). The stylesheet is shared by every component and loaded once: 75.1 KB gzipped.
Examples
Basic
Wrap inputs in a Field for a label, hint and error message.
We'll send the receipt here.
import {
Field,
Input,
MailIcon,
SearchIcon,
Stack,
} from "@vjdesigns/vjdesigns-ui";
export function Basic() {
return (
<Stack gap={5} style={{ width: "100%", maxWidth: "22rem" }}>
<Field label="Email" hint="We'll send the receipt here.">
<Input type="email" placeholder="you@example.com" startIcon={<MailIcon />} />
</Field>
<Field label="Search">
<Input type="search" startIcon={<SearchIcon />} clearable defaultValue="Card components" />
</Field>
</Stack>
);
}
Addons and elements
Addons attach static text to an edge; elements put interactive controls inside it.
import { useState } from "react";
import {
Field,
IconButton,
Input,
Stack,
CopyIcon,
} from "@vjdesigns/vjdesigns-ui";
export function AddonsAndElements() {
const [link] = useState("https://dhui.dev/invite/7Hq2");
return (
<Stack gap={5} style={{ width: "100%", maxWidth: "22rem" }}>
<Field label="Price">
<Input inputMode="decimal" startAddon="quot; endAddon="USD" defaultValue="49.00" />
</Field>
<Field label="Invite link">
<Input
readOnly
value={link}
endElement={
<IconButton aria-label="Copy link" size="xs" variant="ghost" tone="neutral" onClick={() => navigator.clipboard.writeText(link)}>
<CopyIcon />
</IconButton>
}
/>
</Field>
</Stack>
);
}
Sizes and variants
import { Input, Stack } from "@vjdesigns/vjdesigns-ui";
export function SizesAndVariants() {
return (
<Stack gap={3} style={{ width: "100%", maxWidth: "22rem" }}>
<Input aria-label="Small" size="sm" placeholder="Small" />
<Input aria-label="Medium" placeholder="Medium (default)" />
<Input aria-label="Large" size="lg" placeholder="Large" />
<Input aria-label="Filled" variant="filled" placeholder="Filled variant" />
</Stack>
);
}
States
That username is taken.
import { Field, Input, Stack } from "@vjdesigns/vjdesigns-ui";
export function States() {
return (
<Stack gap={5} style={{ width: "100%", maxWidth: "22rem" }}>
<Field label="Disabled" disabled>
<Input defaultValue="Can't change this" />
</Field>
<Field label="Username" error="That username is taken.">
<Input defaultValue="jordan" />
</Field>
<Field label="Checking availability">
<Input defaultValue="jordan.lee" loading />
</Field>
</Stack>
);
}
Accessibility
Every input needs a visible label. Field connects the label, hint and error to the input (aria-labelledby, aria-describedby, aria-invalid), the right autoComplete lets browsers and password managers fill it, and the clear button is named by clearLabel.
We send the invoice here.
Enter an email like name@company.com.
import { useState } from "react";
import { Field, Input, MailIcon } from "@vjdesigns/vjdesigns-ui";
export function Accessibility() {
const [email, setEmail] = useState("ana@example");
const invalid = !/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(email);
return (
<div style={{ width: "100%", maxWidth: "22rem" }}>
<Field
label="Work email"
hint="We send the invoice here."
error={invalid ? "Enter an email like name@company.com." : undefined}
required
>
<Input
type="email"
autoComplete="email"
value={email}
onValueChange={setEmail}
startIcon={<MailIcon />}
clearable
clearLabel="Clear email"
fullWidth
/>
</Field>
</div>
);
}
Translated
Inside a LocaleProvider, the input's built-in words, like the clear button's name, come from the locale (German here). The label and value are your own text, so you translate those yourself.
Mindestens drei Zeichen.
import {
Field,
Input,
SearchIcon,
LocaleProvider,
} from "@vjdesigns/vjdesigns-ui";
import de from "@vjdesigns/vjdesigns-ui/locales/de";
export function Translated() {
return (
<LocaleProvider locale="de" messages={de}>
<div style={{ width: "100%", maxWidth: "22rem" }}>
<Field label="Suche" hint="Mindestens drei Zeichen.">
<Input defaultValue="Wanderschuhe" startIcon={<SearchIcon />} clearable fullWidth />
</Field>
</div>
</LocaleProvider>
);
}
Right to left
The first example again, inside a right-to-left LocaleProvider (Arabic). Layout, spacing and arrow icons mirror, and the components' built-in text is translated. The example's own text stays in English.
Basic
We'll send the receipt here.
import { LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import ar from "@vjdesigns/vjdesigns-ui/locales/ar";
// Basic is the "Basic" example above.
<LocaleProvider locale="ar" messages={ar}>
<Basic />
</LocaleProvider>
Usage notes
Works controlled (value + onChange/onValueChange) or uncontrolled (defaultValue). Inside a Field, the id, description, invalid, required, disabled, read-only, and size are wired automatically.
ref points at the <input>; className styles the wrapper and inputClassName the input itself.
<label htmlFor="team">Team name</label>
<Input id="team" placeholder="The Villains" clearable onValueChange={setName} />
API reference
Input
| Prop | Type | Default |
|---|---|---|
sizeControl height, padding, and type size. Inherits from a surrounding | "sm""md""lg" | "md" |
variantVisual style. | "outline""filled" | "outline" |
radiusCorner rounding. When omitted, uses | "none""xs""sm""md""lg""xl""2xl""pill" | — |
invalidMarks the value as invalid: sets | boolean | false |
startIconDecorative icon before the text. Hidden from assistive technology. | ReactNode | — |
endIconDecorative icon after the text. Hidden from assistive technology. | ReactNode | — |
startAddonStatic content attached to the start edge, such as | ReactNode | — |
endAddonStatic content attached to the end edge, such as | ReactNode | — |
startElementInteractive content inside the start edge (for example an | ReactNode | — |
endElementInteractive content inside the end edge (for example a copy or show-password | ReactNode | — |
clearableShows a clear button ( | boolean | false |
clearLabelAccessible name of the clear button. | string | "Clear" |
onClearCalled after the clear button empties the field (after | () => void | — |
loadingShows a decorative spinner at the end and sets | boolean | false |
fullWidthStretches the field to fill its container. | boolean | true |
htmlSizeThe native | number | — |
onValueChangeCalled with the new value on every change (typing, pasting, clearing). | (value: string) => void | — |
inputClassNameClass name for the | string | — |
refRef to the | Ref<HTMLInputElement> | — |
Also accepts native <input> attributes, plus className, style and ref.
See what changed in each version in the Changelog.
Accessibility report
Input targets WCAG 2.2 AA. Below: a live axe-core audit of this page's examples, Lighthouse scores for the page in both modes, the accessibility behavior built into the component, and the checks only a person can do.
axe-core audit (live)
Checking the examples above…
Lighthouse audit
Light mode
Score 10037 passed · 0 failed · 28 not applicable · 10 to check by hand
Dark mode
Score 10037 passed · 0 failed · 28 not applicable · 10 to check by hand
Lighthouse 13.5.0 audits the whole docs page (header and sidebar included), not just the examples, in English. Last run 11/27/2026. Some failed audits carry no weight in the score, so a page can score 100 and still list one.
Built-in behavior
Keyboard
| Key | Action |
|---|---|
| Tab | Moves focus into the field. |
| Typing | Edits the text, with the browser's usual caret and selection keys. |
Roles and states
| Element | Role | States and properties |
|---|---|---|
<input> | textbox (searchbox for type="search") | aria-invalid, aria-describedby → hint and error, aria-busy while loading |
| Clear button | button | aria-label, aria-controls → input |
Manual checks
Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.
| Check | What to test | WCAG 2.2 |
|---|---|---|
| Keyboard | Every action works with Tab, Shift+Tab, Enter, Space and the arrow keys, and focus never gets stuck. | 2.1.1 (A), 2.1.2 (A) |
| Focus | Focus moves in a logical order, is always visible, and isn't hidden behind sticky headers. | 2.4.3 (A), 2.4.7 (AA), 2.4.11 (AA), 2.4.13 (AAA) |
| Screen readers | Names, roles and states are announced correctly, and status changes are announced without moving focus. | 1.3.1 (A), 4.1.2 (A), 4.1.3 (AA) |
| Color | Meaning never depends on color alone; your own colors meet contrast in both modes. | 1.4.1 (A), 1.4.3 (AA), 1.4.11 (AA), 1.4.6 (AAA) |
| Zoom and reflow | At 200% text size and at 320px wide (400% zoom), nothing is cut off and no sideways scrolling is needed. | 1.4.4 (AA), 1.4.10 (AA), 1.4.12 (AA) |
| Pointer targets | Click and tap targets are at least 24×24px (44×44px for AAA), or spaced so they don't overlap. | 2.5.8 (AA), 2.5.5 (AAA) |
| Motion | Animations respect the reduced-motion setting. | 2.3.3 (AAA) |