API: components
Label
A standalone label that names a control outside a Field, focuses or activates it on press, and selects no text on a double press, in each framework.
A native <label> for a control outside a Field: a text input, a Checkbox, a
Switch, a Select's trigger, a NumberField's input, a Slider's thumb. It
names its control by for (React htmlFor) or by wrapping it, a press on it reaches the control,
and a double press selects none of its text. Inside a Field, Field.Label does this and wires the
ids and the description: use one or the other.
Behaviour
- Naming: as HTML's
label:fornames a labelable control (aninput, abutton), or the Label wraps it. A controlforcannot name (a Slider's thumb, a group) takes the Label'sidin its ownaria-labelledby. - Press: activates the control as a native label does: a text input takes the focus, a
Checkbox or a Switch toggles, a button is clicked. When
fornames an element that is not labelable (a Slider's thumb), the press focuses it, or its first focusable descendant. - Double press: selects none of the Label's text (its
mousedowndefault is prevented whendetail > 1), unless it lands on a control inside the Label. - No text: the Label renders its children only.
Anatomy
| part | element | data-primitives-part | role |
|---|---|---|---|
| Label | label | label-root | names its control |
Usage
import { Label } from "@fragiola/primitives-react/label";
<Label htmlFor="email">Email</Label>
<input id="email" type="email" />;Props
It also takes what the primitive contract gives: render
(Vue: as and the render slot), a class and a style, a ref, and any attribute, which it
forwards (Vue and Angular: for and id, native attributes).
Label
| prop | type | default | description |
|---|---|---|---|
htmlFor (react) | string | the id of the control it names; without it, the labelable control it wraps |
State and part attributes
None but its part attribute, data-primitives-part="label-root".
Keyboard
None: a label is not focusable.
Exports
| entry | exports |
|---|---|
@fragiola/primitives-react/label | Label, LabelProps, LabelState, RenderProp |
@fragiola/primitives-vue/label | Label, LabelProps, LabelState, RenderSlotProps |
@fragiola/primitives-angular/label | Label |