Documentation / Forms
Input
The library’s text input: a native <input> surrounded by its label, a helper text and an error state, in three sizes. With multiline, the same component renders a resizable <textarea>.
It forwards every native attribute (type, placeholder, value, onChange, required…) and links the label to the field itself, through the id you pass it or a generated one. The value is controlled or not, like an ordinary HTML field.
Client component ("use client"): focused focuses the field as soon as it turns true, and the ref points to the native element.
Examples
Basic usage
label shows the label above the field, helperText a hint below it.
import { Input } from "@synertech/ui";
export function Basic() {
return (
<Input
label="Adresse e-mail"
type="email"
placeholder="prenom.nom@exemple.fr"
helperText="Nous ne la partagerons jamais."
/>
);
}Sizes and inline label
size sets the padding and the type size; inline places the label to the left of the field.
import { Input } from "@synertech/ui";
export function Sizes() {
return (
<div className="flex flex-col gap-4">
<Input size="sm" label="Petit" placeholder="size=sm" />
<Input size="md" label="Moyen" placeholder="size=md" />
<Input size="lg" label="Grand" placeholder="size=lg" />
<Input inline label="Ville" placeholder="Lyon" />
</div>
);
}Icon and hidden label
icon sits on the left by default (iconPosition="right" for the opposite). Without a visible label, hideLabel takes it off the screen and keeps it for screen readers: it still names the field.
import { Input } from "@synertech/ui";
const SearchIcon = () => (
<svg className="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" aria-hidden="true">
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="m21 21-4.35-4.35M17 10.5a6.5 6.5 0 1 1-13 0 6.5 6.5 0 0 1 13 0Z"
/>
</svg>
);
export function WithIcon() {
return (
<Input
type="search"
label="Rechercher un client"
hideLabel
placeholder="Rechercher un client…"
icon={<SearchIcon />}
/>
);
}Controlled validation
The value lives in state. error takes the message: it replaces the help under the field, which turns red, aria-invalid and described by that message. Every field of the library reads error that way; true marks the field without a message.
import { useState } from "react";
import { Input } from "@synertech/ui";
export function Validation() {
const [siret, setSiret] = useState("");
const invalid = siret.length > 0 && !/^\d{14}$/.test(siret);
return (
<Input
label="Numéro SIRET"
inputMode="numeric"
value={siret}
onChange={(event) => setSiret(event.target.value)}
error={invalid ? "Le SIRET compte exactement 14 chiffres." : undefined}
helperText="14 chiffres, sans espace."
/>
);
}Text area
multiline renders a <textarea>; rows sets its initial height.
import { Input } from "@synertech/ui";
export function Multiline() {
return (
<Input
multiline
rows={4}
label="Commentaire"
placeholder="Décrivez votre demande…"
maxLength={500}
helperText="500 caractères maximum."
/>
);
}Programmatic focus and read-only
focused focuses the field when it turns true; readOnly and disabled take the field out of the tab order.
import { useState } from "react";
import { Button, Input } from "@synertech/ui";
export function FocusAndStates() {
const [editing, setEditing] = useState(false);
return (
<div className="flex flex-col gap-4">
<Button size="sm" className="self-start" onClick={() => setEditing(true)}>
Modifier le nom
</Button>
<Input
label="Nom du projet"
defaultValue="Refonte du site"
focused={editing}
readOnly={!editing}
/>
<Input label="Identifiant" defaultValue="PRJ-2041" disabled />
</div>
);
}API reference
Components
import { Input } from "@synertech/ui";Props — InputProps
| Prop | Type | Default | Description |
|---|---|---|---|
borderColor |
string |
— | |
error |
boolean | string |
— |
|
focused |
boolean |
false |
|
helperText |
string |
— | Written under the field; a message passed as |
hideLabel |
boolean |
false |
Keeps the label for screen readers only: it is still the field's name. |
icon |
React.ReactNode |
— | |
iconPosition |
"left" | "right" |
"left" |
|
inline |
boolean |
false |
|
label |
string |
— | |
labelColor |
string |
— | |
multiline |
boolean |
false |
|
onChange |
ChangeEventHandler<FieldElement> |
— | Receives the change of the field rendered: an |
rows |
number |
3 |
|
size |
"sm" | "md" | "lg" |
"md" |
|
textColor |
string |
— |
+ 311 inherited native attributes from InputHTMLAttributes, HTMLAttributes, AriaAttributes (className, id, aria-*, event handlers…).