Forms
Radio
A radio button with its label, for picking one value from a small set that is shown all at once. tk:radio.group renders the whole set from data, under a legend.
Nothing to show
A fieldset with "Plan" as its legend and three radio buttons, Pro selected. Choosing Team sets $plan to 'team'. Arrow keys move the choice within the group.
Written one by one #
Two radios sharing the shipping name, Standard selected, each with a description under its label. The form sends the value of the selected one.
Nothing to show
From data, with headings #
A heading per nested array, with its radios under it. required is passed to every radio, so the form cannot be sent without a choice.
Nothing to show
Colors and sizes #
color fills the selected radio and size scales the radios, the legend and the headings. On a group, props for the radios go through radio:.
Nothing to show
Alignment and disabled #
align places the radio before the label, right after it or at the ends of the row; disabled blocks a single option.
Nothing to show
Radios in the group slot #
Radios written in a @foreach inside the group slot, each with its own description, all bound to one property. The group's description goes under the legend.
Nothing to show
Customization #
Classes go to the <input>; prefixed attributes reach the box (control:) and the dot (icon:). On a group, radio: reaches every radio.
Nothing to show
Reference
tk:radio
tk:radio.group
└── tk:radio ...
tk:radio
| Prop | Type | Default | Description |
|---|---|---|---|
checked |
bool | array | false |
Selects the radio on the first render. An array selects it when it contains the radio's value. |
align |
string | left |
Where the button sits next to the label: left, right, justify-left or justify-right, as on tk:checkbox. |
Also accepts the field props (label, description, help, value, size, color...). value is what the form sends when the radio is selected. wire:model and x-model bind the selected value.
Slots
| Slot | Description |
|---|---|
| default | The label, in place of label. |
Prefixes
| Prefix | Goes to |
|---|---|
control: |
The box around the input. |
icon-area: |
The layer over the input that holds the dot. |
icon: |
The dot shown when it is checked. |
tk:radio.group
| Prop | Type | Default | Description |
|---|---|---|---|
options |
array | Collection | LazyCollection | enum class | enum case | model class | model | query | null |
One radio per option: value as the key and label as the value; in a list, each item is both. Keyed nested arrays render a heading followed by their options. |
value |
string | enum case | null |
The value selected on the first render. |
label |
string | slot | from the name | The legend of the group. |
description |
string | slot | null |
Text under the legend. |
size |
string | md |
Passed to every radio, the legend and the headings. |
align |
string | left |
Passed to every radio. |
The attributes option-value, option-label, option-group-label, option-group-children, option-group-children-value and option-group-children-label tell how to read options that are arrays or models, as on tk:select. A keyed array of arrays without option-value, option-label or option-group-children is read as groups, so records indexed by id need option-label.
name, wire:model, x-model and required are given to every radio. Without a name, the radios share a generated one, so they still form one group. Other props for the radios go through the radio: prefix (radio:color="blue").
Slots
| Slot | Description |
|---|---|
| default | Radios written by hand, before those from options. |
Prefixes
| Prefix | Goes to |
|---|---|
radio: |
Every radio of the group. |
heading: |
The headings of nested options. |
error: |
The validation message under the group. |
Customization
Classes and attributes on tk:radio go to the <input>; the parts take the prefixes of the field props, and (listed in the Reference above).
Nothing to show
Accessibility
Native <input type="radio"> elements with labels, grouped in a <fieldset> named by its legend. The validation message of the group is linked to the fieldset with aria-describedby, once, not under each radio. Arrow keys move the selection inside the group and Tab leaves it, as browsers do for radios with one name. Each radio gets aria-invalid while the group has an error.
Behavior notes
- Old input from a failed submit selects the radio that was chosen.
- A group with no options and no slot content renders nothing.