$npx @dinachi/cli@latest add label
childrendisabledemail-field.tsx
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
export function EmailField() {
return (
// The input comes first so the label can read it with peer-disabled.
<div className="flex w-full max-w-sm flex-col-reverse gap-1.5">
<Input type="email" id="email" placeholder="Email" className="peer" />
<Label htmlFor="email">Email</Label>
</div>
)
}Usage
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
export function EmailField() {
return (
<div className="grid gap-1.5">
<Label htmlFor="email">Email</Label>
<Input id="email" type="email" />
</div>
)
}Examples
A label paired with an input.
import { Label } from '@/components/ui/label';
import { Input } from '@/components/ui/input';
export function Example() {
return (
<div className="grid w-full max-w-sm items-center gap-1.5">
<Label htmlFor="email">Email</Label>
<Input type="email" id="email" placeholder="Email" />
</div>
);
}A label beside a disabled input.
import { Label } from '@/components/ui/label';
import { Input } from '@/components/ui/input';
export function Example() {
return (
<div className="grid w-full max-w-sm items-center gap-1.5">
<Label htmlFor="disabled" className="peer-disabled:cursor-not-allowed peer-disabled:opacity-70">
Disabled
</Label>
<Input type="text" id="disabled" placeholder="Disabled" disabled className="peer" />
</div>
);
}Notes
Disabled styling
The label dims through Tailwind's peer-disabled:, so it must come after a disabled control with the peer class.
Inside a Field
Inside a Field, use FieldLabel. It wires the label to the control and its validation state.
API
htmlForstring
Id of the named control. Clicking the label focuses it.children
The name, read by the agent as the control's label.agent
ReactNodeclassNamestring
Merged with the default classes.Accessibility
- A native label; its text is the control's accessible name.
- Link it with
htmlForand a matching id, or wrap the control inside it. - The agent addresses a labelled field by its label text.