Skip to content

CdsMessages

New in v4.0

The block of messages under an input: a hint, an explanation or a validation error. The messages appear and disappear with an animation, so the line under the field does not jerk the layout.

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

The ready-made fields already have the block of messages built in — the messages, hint and error-messages props of CdsTextInput and the other controls. A standalone CdsMessages is needed for groups of fields and for your own controls. For a noticeable notification on the page take CdsNotification.

Variations ​

Messages ​

The messages prop accepts a string or an array of strings — every string becomes a separate line, they are not glued together.

Color ​

The color prop sets the color of the text — take the status tokens (status-danger-content for an error, status-success-content for a confirmation). Without a color the messages are muted, like supporting text.

Appearance ​

The messages are visible only with active. Showing and hiding are animated, and the animation is set by the transition prop.

Slot ​

The message slot overrides a single message and receives its text — you can add an icon or a link. The default slot adds content after all the messages.

Scenarios ​

An error for a group of fields ​

A group of checkboxes has no validation of its own: assemble it yourself and show the result through active. While the selection is empty, the red message hangs under the group and disappears with the very first checkbox.

API ​

Props

NameTypeDefaultDescription
activeboolean | undefined—Active state
activeColorstring | undefined—Color of the component in its active state
baseColorstring | undefined—Color of the component in its inactive state
bgColorstring | undefined—Background color of the component
colorstring | undefined—Component color
hideMessagesboolean | undefined—Hide the messages under the input
messagesstring | readonly string[] | undefined[]Messages shown under the input
textColorstring | undefined—Text color of the component
transitionstring | boolean | (TransitionProps & { component?: Component | undefined; }) | { component: Component; leaveAbsolute: boolean; group: boolean; } | null | undefined{ component: slide-transition-y, leaveAbsolute: true, group: true }Transition animation

Slots

NameTypeDescription
defaultanyYour own look for the whole list of messages instead of the default one
messageCdsMessageSlotTemplate for a single message. The slot props carry the text of the message