Components · Inputs
Label
A standalone form label in the field-label style, with an optional marker and a line of secondary text.
Also called LabelAsterisk, LabelOptional, LabelSub
import { Label } from "@botiverse/raft-ui";Label is a label element in the style of a field label: text-footnote, semibold, in foreground-muted. Use it where a control needs a label but isn't in a Field; inside a field, FieldLabel is the label and wires itself to the control.
When to use
Anatomy
Label: the label. Its text says what the control holds. Required.LabelOptional: the optional marker after the text, "(optional)", inforeground-hint.LabelAsterisk: a required marker, an asterisk inforeground-hint. Deprecated, and it will be removed: required fields aren't marked (Forms).LabelSub: any other secondary text after the label, inforeground-hintat regular weight.
The markers are also Label.Optional, Label.Asterisk and Label.Sub. FieldLabel draws the optional marker through its optional prop; its required prop, which draws the asterisk, is deprecated too.
Variants
States
- Disabled:
disabledturns the label and its markersforeground-disabledand setsaria-disabled. It doesn't disable the control: disable that too.
Content
- Write the label as a noun for what the control holds, in sentence case: Email address (Writing).
- Mark optional fields with
LabelOptional, and don't mark required ones: keeparia-required(orrequired) on a required control, so a screen reader still says so (Forms).
Accessibility
- Label renders a native
label. Connect it to its control withhtmlForand the control'sid, or wrap the control in it. - The markers are read as part of the label: "Middle name (optional)".
API
Label
Also takes the attributes of its element.
LabelAsterisk
The asterisk marks a required field, and required fields aren't
marked: mark the optional ones with `LabelOptional`, and put `required` or
`aria-required` on the control, so a screen reader still says so. The part
still renders; it will be removed in a later release.
Takes the attributes of its element.
LabelOptional, LabelSub
Takes the attributes of its element.
Related
Changes
- 0.101.0 · Changed
FieldLabel'srequiredprop andLabelAsteriskare deprecated: a required field carries no asterisk ([Field › Content](https://raft-design.botiverse.build/components/field/#content), [Forms › Fields](https://raft-design.botiverse.build/patterns/forms/#fields)). Both are marked@deprecatedin the types (Label.Asterisktoo), and the API tables of Field and Label say so. Mark an optional field with<FieldLabel optional>(orLabelOptional), leave a required one unmarked, and putrequiredoraria-requiredon the control.