Forms
Input
A labelled single-line text field with description, error, required and optional states, and start/end sections.
import { Input } from '@reactloom/ui';Examples
Basic
import { Input } from '@reactloom/ui';
export default function Example() {
return (
<div style={{ width: '100%', maxWidth: 360 }}>
<Input label="Full name" placeholder="Ada Lovelace" autoComplete="name" />
</div>
);
}States
Description, required, error, read-only and disabled.
We send invoices here.
Enter a full domain, like acme.com.
import { Input, Stack } from '@reactloom/ui';
export default function Example() {
return (
<Stack gap="5" style={{ width: '100%', maxWidth: 360 }}>
<Input label="Work email" description="We send invoices here." type="email" required />
<Input label="Company domain" defaultValue="acme" error="Enter a full domain, like acme.com." />
<Input label="Account ID" defaultValue="acct_9f2c41" readOnly />
<Input label="Region" defaultValue="EU (Frankfurt)" disabled />
</Stack>
);
}Sections
Icons, prefixes and units. Clicking a decorative section focuses the input.
import { Input, Stack } from '@reactloom/ui';
import { AtSign, Globe } from 'lucide-react';
export default function Example() {
return (
<Stack gap="5" style={{ width: '100%', maxWidth: 360 }}>
<Input label="Price" startSection="$" endSection="USD" inputMode="decimal" placeholder="0.00" />
<Input label="Website" startSection={<Globe size={16} />} placeholder="example.com" />
<Input label="Username" startSection={<AtSign size={16} />} placeholder="ada" />
</Stack>
);
}Sizes
import { Input, Stack } from '@reactloom/ui';
export default function Example() {
return (
<Stack gap="4" style={{ width: '100%', maxWidth: 360 }}>
<Input size="sm" label="Small" placeholder="28 px" />
<Input size="md" label="Medium" placeholder="32 px" />
<Input size="lg" label="Large" placeholder="40 px" />
</Stack>
);
}Validation on submit
Move focus to the first invalid field so screen readers announce it.
import { Button, Input, Stack } from '@reactloom/ui';
import { useRef, useState, type FormEvent } from 'react';
export default function Example() {
const [error, setError] = useState<string>();
const ref = useRef<HTMLInputElement>(null);
const submit = (e: FormEvent<HTMLFormElement>) => {
e.preventDefault();
const email = String(new FormData(e.currentTarget).get('email'));
const message = /^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(email) ? undefined : 'Enter an email like name@company.com.';
setError(message);
// Move focus to the invalid field: screen readers announce its label, state and error.
if (message) ref.current?.focus();
};
return (
<form noValidate onSubmit={submit} style={{ width: '100%', maxWidth: 360 }}>
<Stack gap="3">
<Input ref={ref} name="email" type="email" label="Work email" error={error} required />
<Button type="submit">Invite</Button>
</Stack>
</form>
);
}API reference
| Prop | Type | Default |
|---|---|---|
labelVisible label, associated with the control. | ReactNode | — |
descriptionHelp text linked with aria-describedby. | ReactNode | — |
errorError message; marks the control invalid and is described. | ReactNode | — |
invalidInvalid without a message. | boolean | false |
hideLabelKeep the label for screen readers, hide it visually. | boolean | false |
showOptionalAppend “(optional)” to labels of non-required fields. | boolean | false |
size | 'sm' | 'md' | 'lg' | 'md' |
radius | 'none' | 'sm' | 'md' | 'lg' | 'full' | — |
startSection / endSectionContent inside the control. | ReactNode | — |
classNamesPer-slot class names. | Partial<Record<'root' | 'label' | 'description' | 'control' | 'input' | 'section' | 'error', string>> | — |
…Native attributes and the ref go to the <input>; className and style go to the root. | InputHTMLAttributes | — |
Customization
Extracted from the component’s source on every build, so it matches the code. How the layers fit together is explained in Customization.
Slot class names
Add classes to inner parts with classNames (className is shorthand for root): root, label, description, control, input, section, error.
CSS variables
| Variable | Default |
|---|---|
--pl-input-radius | var(--pl-radius-md |
State attributes
Target these in your CSS to style states without depending on class names.
| Attribute | Values |
|---|---|
[data-disabled] | present when on |
[data-invalid] | present when on |
[data-radius] | none · sm · md · lg · full |
[data-readonly] | present when on |
[data-size] | sm · md · lg |
Theme tokens it reads
--pl-color-bg-subtle --pl-color-bg-surface --pl-color-border-default --pl-color-border-focus --pl-color-border-input --pl-color-danger-border --pl-color-fg-default --pl-color-fg-disabled --pl-color-fg-muted --pl-color-fg-subtle --pl-control-height-lg --pl-control-height-md --pl-control-height-sm --pl-focus-ring-color --pl-focus-ring-width --pl-font-size-lg --pl-font-size-md --pl-font-size-sm --pl-radius-full --pl-radius-lg --pl-radius-md --pl-radius-none --pl-radius-sm --pl-shadow-xs
Accessibility
- Label association via for/id; description and error via aria-describedby (in that order).
- aria-invalid is set when there is an error; errors use an icon and text, never colour alone.
- The required asterisk is decorative — the native required attribute carries the state.
- Input borders meet 3:1 non-text contrast in every built-in theme.
| Key | Action |
|---|---|
| Tab | Focus the field |
Usage guidelines
Do
- Use autoComplete tokens (email, name, street-address).
- Validate on submit, then focus the first invalid field.
Don’t
- Don’t use placeholder text as a label.
- Don’t treat type="number" or a visual mask as validation.