Raft Design System

Components · Inputs

Label

A standalone form label in the field-label style, with an optional marker and a line of secondary text.

StableAlso 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

SituationUse
A control in a form: an input, a textarea, a selectFieldLabel in a Field
A checkbox, radio or switch with its label beside it, in a formFieldItem in a Field
A label for a control outside a field, such as a checkbox in a listLabel
The title of a selectable option cardCardTitle in a Card with variant="option"

Anatomy

  • Label: the label. Its text says what the control holds. Required.
  • LabelOptional: the optional marker after the text, "(optional)", in foreground-hint.
  • LabelAsterisk: a required marker, an asterisk in foreground-hint. Deprecated, and it will be removed: required fields aren't marked (Forms).
  • LabelSub: any other secondary text after the label, in foreground-hint at 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

VariantUse for
size="md" (default)Labels in forms and settings
size="sm"Dense layouts where the default is too large for the space

States

  • Disabled: disabled turns the label and its markers foreground-disabled and sets aria-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: keep aria-required (or required) on a required control, so a screen reader still says so (Forms).

Accessibility

  • Label renders a native label. Connect it to its control with htmlFor and the control's id, or wrap the control in it.
  • The markers are read as part of the label: "Middle name (optional)".

API

Label

PropTypeDefault
disabledboolean
size"sm" | "md""md"
renderAllows you to replace the component's HTML element with a different tag, or compose it with another component.ReactElement | ((props, state) => ReactElement)

Also takes the attributes of its element.

LabelAsterisk

DeprecatedThe 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.

Changes

  • 0.101.0 · ChangedFieldLabel's required prop and LabelAsterisk are 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 @deprecated in the types (Label.Asterisk too), and the API tables of Field and Label say so. Mark an optional field with <FieldLabel optional> (or LabelOptional), leave a required one unmarked, and put required or aria-required on the control.