Skip to content

CdsLabel

New in v4.0

A label names a field — it says what is expected from the user. It renders as a label tag and binds to the control through for, so a click on the label moves the focus into the field.

Storybook GitLab
Test coverage: 100% — good coverage
API in specs
7 / 7 props, events, slots and exposed members with a test
Test cases
10 unit · 0 browser
Known bugs
2 pinned by an it.fails test
Code coverage
100% lines · 100% branches measured in v4.0.0-alpha.13
A11y (axe)
1 recommendations in 3 stories measured in v4.0.0-alpha.11

The ready-made fields already have the label built in — the label prop of CdsTextInput and the other controls. A standalone CdsLabel is needed for groups of fields and for your own controls. The explanation under the label is added by CdsDescription.

Variations ​

Text ​

The text prop sets the caption. The default slot accepts arbitrary markup — an icon with an explanation next to the text, for example.

States ​

The disabled and readonly props mute the label together with the field: both stop reacting to a click, and disabled also changes the color.

Scenarios ​

A label for your own control ​

The for prop takes the id of the control — the browser binds them itself: a click on the label sets the focus, and the screen reader reads the caption together with the field.

API ​

Props

NameTypeDefaultDescription
contentstring | number | undefined—Content displayed in the component.
disabledboolean | null | undefinednullDisabled state
forstring | undefined—Identifier of the field the label belongs to — the value of the for HTML attribute
readonlyboolean | null | undefinednullRead-only state
sizenumber | "xs" | "sm" | "md" | "lg" | "xl" | undefined'md'Size of the component
textstring | number | undefined—Text displayed in the component.

Slots

NameTypeDescription
defaultanyText of the label for the field