Input13
A text field with its label, help text and error built in. It lifts off the page when you focus it, leaves a hard shadow in the focus color, and shakes its head when something's wrong.
<Input label="Email" placeholder="you@studio.com" />Usage
import { Input } from "plonk-ui";
export function Profile() {
return <Input label="Email" name="email" type="email" />;
}Input renders a real <input>, and every native prop goes to it: type,
name, value and onChange, defaultValue, autoComplete, inputMode,
ref. className styles the outer wrapper, so use it for width and layout.
Description and errors
description adds help text under the field. error marks it invalid, shows
the message as a small tag, and shakes the field once when the error appears.
Both are connected to the input, so screen readers read them with the label.
Letters, numbers and dashes.
Enter a full email address.
import { Input } from "plonk-ui";
export default function Details() {
return (
<div className="flex w-full max-w-xs flex-col gap-5">
<Input
label="Username"
description="Letters, numbers and dashes."
defaultValue="melih"
/>
<Input
label="Email"
type="email"
defaultValue="melih@"
error="Enter a full email address."
/>
<Input label="Workspace" defaultValue="plonk-studio" disabled />
</div>
);
}Icons and affixes
iconStart and iconEnd take an icon or short text, like a unit or a protocol.
They're decorative and hidden from screen readers, so the label has to say what
the field is for.
import { Input } from "plonk-ui";
const Search = () => (
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={3}>
<circle cx="11" cy="11" r="6.5" />
<path d="m16 16 4.5 4.5" />
</svg>
);
export default function Icons() {
return (
<div className="flex w-full max-w-xs flex-col gap-5">
<Input
aria-label="Search projects"
type="search"
placeholder="Search projects"
iconStart={<Search />}
/>
<Input
label="Budget"
inputMode="decimal"
defaultValue="1200"
iconEnd={<span className="font-bold">USD</span>}
/>
<Input
label="Website"
type="url"
placeholder="studio.com"
iconStart={<span className="font-bold">https://</span>}
/>
</div>
);
}Forms and validation
Inputs are plain form fields: they submit with the form and show up in
FormData under their name. Plonk doesn't validate anything on its own. You
decide what's valid, on the client or the server, and pass the message to
error.
This form uses a React 19 action with useActionState. The action checks the
values and returns errors; the fields keep what was typed through
defaultValue, the button shows loading while the action runs, and focus
moves to the first invalid field. noValidate turns off the browser's own
bubbles so the messages come from you, while required still tells screen
readers the field is required.
import { useActionState, useEffect, useRef } from "react";
import { Button, Input } from "plonk-ui";
interface State {
values: { name: string; email: string };
errors: { name?: string; email?: string };
done: boolean;
}
// Stands in for a server action: validates and returns errors.
async function join(_: State, data: FormData): Promise<State> {
await new Promise((resolve) => setTimeout(resolve, 600));
const values = {
name: String(data.get("name")).trim(),
email: String(data.get("email")).trim(),
};
const errors: State["errors"] = {};
if (!values.name) errors.name = "Tell us your name.";
if (!/^\S+@\S+\.\S+$/.test(values.email)) {
errors.email = "Enter a full email address, like you@studio.com.";
}
return { values, errors, done: Object.keys(errors).length === 0 };
}
const initial: State = {
values: { name: "", email: "" },
errors: {},
done: false,
};
export default function Validation() {
const [state, action, pending] = useActionState(join, initial);
const form = useRef<HTMLFormElement>(null);
// After a failed submit, move focus to the first invalid field.
useEffect(() => {
form.current?.querySelector<HTMLElement>("[aria-invalid]")?.focus();
}, [state]);
return (
<form
ref={form}
action={action}
noValidate
className="flex w-full max-w-xs flex-col gap-4"
>
<Input
label="Name"
name="name"
required
autoComplete="name"
defaultValue={state.values.name}
error={state.errors.name}
/>
<Input
label="Email"
name="email"
type="email"
required
autoComplete="email"
defaultValue={state.values.email}
error={state.errors.email}
/>
<Button type="submit" loading={pending} className="self-start">
Join the beta
</Button>
<p role="status" className="font-bold empty:hidden">
{state.done ? `You're on the list, ${state.values.name}.` : ""}
</p>
</form>
);
}Prefer native validation? Leave out noValidate and use required, type,
pattern or minLength; the browser shows its messages and blocks the submit.
Personalities
Sticker and Comic lift the field toward you when it's focused. Retro does the same in one snap. Arcade keeps it in place and lights a neon ring around it, like a screen switching on. In every personality the error tag sticks on at a slight angle and the field shakes once.
Accessibility
- The label is a real
<label>linked to the input. Without a visible label, passaria-label. descriptionanderrorare linked witharia-describedby;erroralso setsaria-invalid.requiredis announced from the native attribute. The asterisk is visual only.- Icons and affixes are hidden from screen readers.
- After a failed submit, move focus to the first invalid field, as in the validation example.
API
All other <input> props are passed through.
| Prop | Type | Default | Description |
|---|---|---|---|
iconStart | ReactNode | — | Icon or text before the value, like a search glass or https://. Hidden from screen readers. |
iconEnd | ReactNode | — | Icon or text after the value, like a unit. Hidden from screen readers. |
label | ReactNode | — | Visible label, linked to the control. Without one, pass aria-label or aria-labelledby. |
description | ReactNode | — | Help text under the control, read by screen readers after the label. |
error | ReactNode | — | Error message. When set, the control is marked invalid (aria-invalid) and shakes once. Pass true to mark it without a message. |
type | HTMLInputTypeAttribute | — | Native input type: email, password, search, url… |
name | string | — | Field name in the submitted form data. |
required | boolean | — | Marks the field required: an asterisk in the label and native required for validation and screen readers. |
disabled | boolean | — | Disables the field. The border turns dashed. |