For independent options that are turned on separately use CdsCheckbox, for an on/off setting that applies immediately — CdsToggle. If there are more than five options, fold the list into CdsSelect.
Anatomy
The heading and the description caption the whole set, below them are the radio buttons: each one has a control with a state icon, a label and an optional description. At the bottom is the common messages block of the group. A click on the label selects the button exactly like a click on the control.
Variations
Heading and description
The label prop names the group, description explains the choice. Every button has its own label and description: name the option briefly in the label and move the details — the price, the deadlines, the limits — into the description.
Direction
By default the buttons are stacked in a column. direction="horizontal" puts them in a row — handy for short sets of two or three options such as a period or a sort order.
States
disabled blocks the whole group and lowers the contrast, readonly forbids changing the choice but does not change the appearance. A single option is blocked by the disabled prop of the button itself.
Messages and errors
messages shows a supporting text under the group, error-messages — a ready error message (the one coming from the server, for example) together with the error state on all the buttons. Validation rules through rules are in the "Submitting a form" scenario. hide-details removes the bottom block entirely.
Colors
color sets the color of the selected button, base-color — of the unselected ones. The values apply to all the buttons of the group at once.
Slots
When the text props are not enough, the content of the blocks is replaced by slots — both on the group and on every button.
| Slot name | Description |
|---|---|
label | Content of the group heading (replaces label) |
description | Content of the group description (replaces description) |
prepend | Element before the set of buttons |
append | Element after the set of buttons |
messages | Content of the messages block |
details | The whole bottom block |
CdsRadio has its own label and description slots — to highlight a part of the text or add an icon, for example.
Guidelines
Scenarios
Submitting a form
The choice is required: a rule in rules returns the error text while no value is selected. The button starts the check through the validate() of the CdsForm.
Choosing a plan
The descriptions of the buttons state the conditions, and the computed total under the group is updated on every choice — the user sees the consequences right away.
Sorting a list
A horizontal group with hide-details works as a sorting panel: the selected value rebuilds the list on the fly through a computed.
API
The props, events and slots of a single button are on the CdsRadio page.
Props
| Name | Type | Default | Description |
|---|---|---|---|
activeColor | string | undefined | — | Color of the component in its active state |
appendIcon | IconValue | undefined | — | Icon in the append slot, after the content |
baseColor | string | undefined | — | Color of the component in its inactive state |
bgColor | string | undefined | — | Background color of the component |
centerAffix | boolean | undefined | true | Vertically center the appendInner, prependInner, clearIcon and label elements. |
color | string | undefined | — | Component color |
defaultsTarget | string | undefined | — | Name of the child component the group prop values are passed to as defaults |
description | string | undefined | — | Description of the component, shown under the label |
direction | "horizontal" | "vertical" | undefined | 'vertical' | Switches the component between horizontal and vertical layout. |
disabled | boolean | null | undefined | null | Disabled state |
error | boolean | undefined | — | Puts the component into the visual error state |
errorMessages | string | readonly string[] | null | undefined | [] | Puts the component into the error state and passes custom error messages. They are merged with any checks defined in the rules prop. This field does not trigger validation. |
falseIcon | IconValue | undefined | 'radio-off' | Icon of an unselected radio button |
focused | boolean | undefined | — | Controls the focus state of the component. When true, the component is considered focused and may apply the corresponding styles or behavior. |
height | string | number | undefined | 'auto' | Height of the component |
hideDetails | boolean | "auto" | undefined | — | Hides the details block (messages and hints). With the 'auto' value the block is hidden when there are no messages |
hideMessages | boolean | undefined | — | Hide the messages under the input |
hint | string | undefined | — | Hint text shown under the input |
iconColor | string | boolean | undefined | — | Icon color. Accepts a boolean or a color string |
id | string | undefined | — | Unique identifier of the component |
inline | boolean | undefined | — | Renders the control as an inline element — the container does not stretch to the full width |
label | string | undefined | — | Label text of the component |
maxErrors | string | number | undefined | 1 | Maximum number of validation errors shown |
maxWidth | string | number | undefined | — | Maximum component width |
messages | string | readonly string[] | undefined | [] | Messages shown under the input |
minWidth | string | number | undefined | — | Minimum component width |
modelValue | any | — | Value of the component (v-model). In a group it is the value of the selected control, with multiple — an array of the selected values |
name | string | undefined | — | The name attribute of the native input element. In a group one name joins all the nested controls |
persistentHint | boolean | undefined | — | Always show the hint, not only on focus |
prependIcon | IconValue | undefined | — | Icon in the prepend slot, before the content |
readonly | boolean | null | undefined | null | Read-only state |
rules | readonly ValidationRule[] | undefined | [] | Accepts an array of items of different types: functions, booleans and strings. Functions take the input value as an argument and must return either true / false, or a string with an error message. The input goes into the error state if a function returns false (or any value in the array is false) or is a string. |
size | number | "xs" | "sm" | "md" | "lg" | "xl" | undefined | 'md' | Size of the component |
textColor | string | undefined | — | Text color of the component |
theme | string | undefined | — | Component theme |
trueIcon | IconValue | undefined | 'radio-on' | Icon of a selected radio button |
type | string | undefined | 'radio' | Type of the native input element of the group buttons |
validateOn | ValidateOn | undefined | — | Changes the type of the event that triggers validation |
validationValue | any | — | Value used when applying the validation rules |
valueComparator | ValueComparator | undefined | true | Function comparing the model value with the value of the control. Deep comparison by default |
width | string | number | undefined | — | Component width |
Events
| Name | Type | Description |
|---|---|---|
update:modelValue | [value: any] | Fires when the model of the component changes |
Slots
| Name | Type | Description |
|---|---|---|
append | CdsInputSlot | Adds an element after the input |
default | any | Default slot — the radio buttons of the group (CdsRadio) |
description | { description: string | undefined; props: Record<string, any>; } | Default slot of the CdsDescription component |
details | CdsInputSlot | Slot for custom content that lets you customize how the messages are displayed |
label | { label: string | undefined; props: Record<string, any>; } | Default slot of the CdsLabel component |
message | CdsMessageSlot | Slot for customizing the content of a message |
messages | CdsInputSlot | Slot for custom content that lets you customize how the messages are displayed |
prepend | CdsInputSlot | Adds an element before the input |
Exposed
| Name | Type | Description |
|---|---|---|
isDirty | boolean | Whether the input is dirty |
isDisabled | boolean | Whether the input is disabled |
isPure | boolean | Whether the input is pure |
isReadonly | boolean | Whether the input is read-only |
isValid | boolean | null | Whether the input is valid |
isValidating | boolean | Whether the input is being validated |
reset | () => Promise<void> | Resets the input to its initial state |
resetValidation | () => Promise<void> | Resets the validation of the input |
validate | (silent?: boolean) => Promise<string[]> | Validates the input |