Skip to main content

CamoRadio

Concept​

1. Why​

Radio buttons choose exactly one option from a small visible set (2–5 options). Camouflage offers two levels:

  • CamoRadioGroup: the usual way. It takes a list of options and a selected value, handles keyboard navigation between options, and announces "2 of 3" to screen readers.
  • CamoRadio: a single radio, for custom layouts (a radio inside a card).

2. Shape​

Material mapping preview: the M3 radio button.

  • A 20 dp circle, with an onSurfaceVariant outline when unselected.
  • Selected: a primary ring with an inner dot.
  • The label is bodyLarge in onSurface.
  • Error: error ring.

3. API​

Contract​

fun <T> CamoRadioGroup(
value: T?, // null = nothing selected yet
onValueChange: (T) -> Unit,
options: List<RadioOption<T>>,
label: String? = null, // group label, announced with the group
error: String? = null, // shown below the group
orientation: Orientation = Vertical,
enabled: Boolean = true,
)
data class RadioOption<T>(val value: T, val label: String, val description: String? = null, val enabled: Boolean = true)

fun CamoRadio(
selected: Boolean,
onClick: (() -> Unit)?, // null → display-only (a parent row handles it)
label: String? = null,
labelSpans: List<CamoSpan>? = null,
enabled: Boolean = true,
)

// inside a form: CamoRadioGroupFormField<T>(key, initialValue, rules, options, …)

State → renderer: RadioState(selected, label?, enabled, error: Boolean, interaction). Slots: none. The group layout (column or row, the group label, the error text) is drawn by core with the skin's text styles.

Tokens used​

  • colors.primary (selected), onSurfaceVariant (unselected), error, onSurface (label and disabled)
  • typography.bodyLarge (option label), bodyMedium (description), labelLarge (group label)
  • spacing.m between the radio and its label

Component theme​

theme.components.radio: RadioTheme?. Every field is nullable in the theme. The skin's defaults(theme) fills whatever isn't set (Material defaults shown). See Theme §3.10.

FieldTypeMaterial defaultWhat it's for
sizeDp20the visual circle
dotSizeDp10the inner dot when selected
borderWidthDp2ring thickness
labelStyle / descriptionStyleCamoTextStylebodyLarge / bodyMediumoption texts
labelPositionLabelPosition (Start | End)Endwhich side of the circle the option label sits on (ADR-28)
labelGapDpspacing.m (12)space between radio and label
colorsRadioColors(selected, unselected, error, label)primary, onSurfaceVariant, error, onSurfaceevery color the radio uses

Accessibility​

  • The group is a selectable group with its label. Each option is a radio announced as "Label, radio button, 2 of 3, selected".
  • Keyboard: Tab enters the group at the selected option (or the first one). Arrow keys move and select. Tab leaves the group. This is the standard radio-group pattern (roving focus).
  • Each option row is the touch target (48 minimum height).
  • The group error is linked to the group and announced when it appears.

4. Build steps​

  1. CamoRadio + RadioRenderer (the circle, selected animation with motion.durationShort).
  2. CamoRadioGroup: the row layout, group semantics, roving focus with arrow keys, and error text.
  3. CamoRadioGroupFormField (the CamoForm pattern).
  4. Tests:
    • tapping a row selects its value;
    • Down arrow moves and selects;
    • Tab leaves the group;
    • the announcement includes "n of m";
    • a disabled option is skipped by the arrows;
    • error sets invalid semantics.

Done when

  • A "delivery method" group works by touch, keyboard and screen reader, and inside a CamoForm with a required rule.

5. Edge cases​

CaseDecided behavior
Nothing selected initiallyAllowed (value = null). Tab focuses the first enabled option without selecting it.
More than ~5 optionsGuidance: use CamoSelect instead (CamoSelect).
Horizontal orientation with long labelsThe row wraps (flow layout). It never truncates labels.
RTLThe radio is at the start (right), and Left/Right arrows follow the reading direction.

Implementation​

1. Why​

Compose gives single selection through Modifier.selectable and Modifier.selectableGroup(), but no arrow-key navigation between radios. The Kotlin work is that keyboard behavior, the group semantics, the horizontal and vertical layouts, and the form field.

2. Shape​

3. API​

@Composable
public fun <T> CamoRadioGroup(
value: T?,
onValueChange: (T) -> Unit,
options: List<RadioOption<T>>,
modifier: Modifier = Modifier,
label: String? = null,
error: String? = null,
orientation: Orientation = Orientation.Vertical,
enabled: Boolean = true,
)

@Composable
public fun CamoRadio(
selected: Boolean,
onClick: (() -> Unit)?, // null → display-only (a parent row handles it)
modifier: Modifier = Modifier,
label: String? = null,
labelSpans: List<CamoSpan>? = null,
enabled: Boolean = true,
interactionSource: MutableInteractionSource? = null,
)

@Composable
public fun <T> CamoRadioGroupFormField(key: String, options: List<RadioOption<T>>, initialValue: T? = null,
rules: List<CamoRule<T?>> = emptyList(), label: String? = null, orientation: Orientation = Orientation.Vertical)

Keyboard (the part Compose doesn't give): each option gets a FocusRequester. onPreviewKeyEvent on an option handles Key.DirectionDown/Right (next) and Key.DirectionUp/Left (previous, mirrored in RTL for Left/Right): it moves focus and selects (onValueChange), like a native radio group. Tab enters the group on the selected option (or the first one when nothing is selected) and leaves it with the next Tab: options other than the focus target get Modifier.focusProperties { canFocus = … } so the group is one Tab stop.

Semantics: the group has selectableGroup() plus semantics { contentDescription = label } when labelled; each row is selectable(selected, role = Role.RadioButton, onClick) with mergeDescendants, which announces "Weekly, radio button, 2 of 3, selected" (collection position from selectableGroup).

Label position: the row reads style.labelPosition (Start | End, ADR-28) and swaps the circle and the text with Arrangement order; the whole row is the target either way.

4. Build steps​

  1. RadioTheme / RadioStyle, RadioOption, CamoRadio, CamoRadioGroup (layout, group label, error text with the skin's styles).
  2. The focus logic (one Tab stop, arrows select) as an internal rememberRovingFocus(count) helper, reused by the segmented control and chip group.
  3. CamoRadioGroupFormField on the form's entry API (CamoForm).
  4. commonTest: tap selects; arrows move and select (and mirror in RTL); Tab enters on the selected option; the error text appears and the group is announced invalid; display-only CamoRadio(onClick = null) has no own node.

Done when

  • A shipping-speed group and a plan picker in a form work by touch, keyboard (desktop and web) and screen reader.

5. Edge cases​

CaseDecided behavior
value not among the optionsNothing is selected; a debug log names the value.
Horizontal group that doesn't fitFlowRow wraps it. Guidance: more than 3 horizontal options → vertical.
Disabled optionSkipped by arrow keys, still announced as dimmed ("unavailable").