Fragiola

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.

Quantity field
Gallery

Behaviour

  • Naming: as HTML's label: for names a labelable control (an input, a button), or the Label wraps it. A control for cannot name (a Slider's thumb, a group) takes the Label's id in its own aria-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 for names 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 mousedown default is prevented when detail > 1), unless it lands on a control inside the Label.
  • No text: the Label renders its children only.

Anatomy

partelementdata-primitives-partrole
Labellabellabel-rootnames 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

proptypedefaultdescription
htmlFor (react)stringthe 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

entryexports
@fragiola/primitives-react/labelLabel, LabelProps, LabelState, RenderProp
@fragiola/primitives-vue/labelLabel, LabelProps, LabelState, RenderSlotProps
@fragiola/primitives-angular/labelLabel