Label
Renders an accessible caption for a form control.
Installation
Install the following dependencies:
Set up the token layer and the StyleX compiler, if you have not already. See
Installation, and paste states.ts from the same page,
which is where the dimmed disabled label comes from. The label also needs
interop.css, which sizes an icon the label does not render.
Copy and paste the following code into your project.
Update the import paths to match your project setup.
Usage
Disabled
Use the disabled prop to dim the label and take it out of the hit test. It is
a prop rather than an inherited state. Inside a Field
the FieldLabel reads it from the field; a bare label has nothing to read it
from.
Content
The label is a flex row with a 0.5rem gap, so an icon or a
Badge sits beside the text without extra markup.
Give the label either an htmlFor matching the control's id or the control
itself as a child. Without one of the two the label is decoration, and clicking
it does not focus anything.
API reference
Pass render to replace a part's element or compose it with another component.
Label renders a <label> and accepts every <label> attribute.
Label
| Prop | Type | Default |
|---|---|---|
disabled | boolean | false |
htmlFor | string | — |
xstyle | StyleXStyles | — |
className | string | — |
The line height is 1 rather than the sm leading the type scale pairs with
text.sm. A label is one line. With the tight box, the stack's gap alone sets the
distance to the control below.
labelStyles
The style maps behind the component. Spread them onto any element.
| Key | What it is |
|---|---|
base | The row: gap, type, weight, icon size |
disabled | The dimmed, non-interactive state |
disabled is states.disabled from theme/states.ts, the same dimmed style
every control uses.
Data attributes
| Attribute | On | Effect |
|---|---|---|
data-slot="label" | the label | Targets the label from a parent |
data-disabled | the label | Present when disabled is set |