Label
The caption of a field.
Usage
Point it at the field with htmlFor: clicking the caption focuses the field. Above an Input, a Select or a TextArea, add spaced to line it up with the text inside.
tsx
<Label spaced htmlFor="email">email</Label>
<Input>
<Input.Text id="email" placeholder="you@domain.com" />
</Input>Disabled
tsx
<Label spaced htmlFor="city" disabled>city</Label>
<Input>
<Input.Text id="city" disabled />
</Input>Next to a control
Beside a Checkbox or a Toggle, leave spaced out: without it the label has no indent and no margin.
tsx
<Checkbox id="terms" />
<Label htmlFor="terms">accept the terms</Label>Without a field
For a caption that labels nothing, like a group title, render it as a span.
tsx
<Label as="span">components</Label>components
Reference
| prop | type | default | |
|---|---|---|---|
as? | ElementType | "label" | the element or component to render |
spaced? | boolean | false | an indent and a bottom margin, to sit above a field |
disabled? | boolean | false | dims it |
className? | string | — | merged last, so it wins |
…rest | props of as | — | htmlFor and the rest of the element's props |