The ready-made fields already have the block of messages built in — the
messages,hintanderror-messagesprops of CdsTextInput and the other controls. A standaloneCdsMessagesis 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
| Name | Type | Default | Description |
|---|---|---|---|
active | boolean | undefined | — | Active state |
activeColor | string | undefined | — | Color of the component in its active state |
baseColor | string | undefined | — | Color of the component in its inactive state |
bgColor | string | undefined | — | Background color of the component |
color | string | undefined | — | Component color |
hideMessages | boolean | undefined | — | Hide the messages under the input |
messages | string | readonly string[] | undefined | [] | Messages shown under the input |
textColor | string | undefined | — | Text color of the component |
transition | string | boolean | (TransitionProps & { component?: Component | undefined; }) | { component: Component; leaveAbsolute: boolean; group: boolean; } | null | undefined | { component: slide-transition-y, leaveAbsolute: true, group: true } | Transition animation |
Slots
| Name | Type | Description |
|---|---|---|
default | any | Your own look for the whole list of messages instead of the default one |
message | CdsMessageSlot | Template for a single message. The slot props carry the text of the message |