Primitives
Label
The visible name of one form control.
import { Input, Label } from 'ferry-ui'
export default function LabelHero() {
return (
<div className="flex w-full max-w-sm flex-col gap-2">
<Label htmlFor="member-email">Email address</Label>
<Input id="member-email" type="email" placeholder="maya@example.com" />
</div>
)
}Label in a Field or in a FormRow of Form Card.Import the component. A label has one part.
import { Label } from 'ferry-ui'
<Label />Give an id to the control. Pass the same value to htmlFor.
import { Label, Switch } from 'ferry-ui'
export default function LabelHtmlFor() {
return (
<div className="flex items-center gap-2">
<Switch id="two-factor" defaultChecked />
<Label htmlFor="two-factor">Two-factor authentication</Label>
</div>
)
}Put the control in the label. Then htmlFor is not necessary.
The label is a row with a gap of 8px. The control and its text line up.
import { Checkbox, Label } from 'ferry-ui'
export default function LabelWrap() {
return (
<Label>
<Checkbox />
Remember this device
</Label>
)
}The label shows at half opacity when it comes after a disabled control with the peer class. Checkbox, Switch and the RadioGroupItem of Radio Group have this class.
For other controls, use a parent with the group class and data-disabled="true".
import { Checkbox, Input, Label } from 'ferry-ui'
export default function LabelDisabled() {
return (
<div className="flex w-full max-w-sm flex-col gap-5">
<div className="flex items-center gap-2">
<Checkbox id="weekly-digest" disabled />
<Label htmlFor="weekly-digest">Send the weekly digest</Label>
</div>
<div data-disabled="true" className="group flex flex-col gap-2">
<Label htmlFor="billing-contact">Billing email</Label>
<Input id="billing-contact" disabled defaultValue="billing@example.com" />
</div>
</div>
)
}A long label continues on the next line. To align the control with the first line, add items-start to the row.
import { Checkbox, Label } from 'ferry-ui'
export default function LabelLong() {
return (
<div className="flex w-full max-w-sm items-start gap-2">
<Checkbox id="usage-data" className="mt-0.5" />
<Label htmlFor="usage-data">
I agree that the team uses my usage data to make the product better, as the privacy policy describes.
</Label>
</div>
)
}aria-label to the control. Do not add a Label.Label names one control. For a group of controls, pass aria-label or aria-labelledby to the group.Label also accepts the props of the Radix UI Label primitive and each attribute of the <label> element.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | - |
| See the element or the Radix UI primitive this part renders. | ||