Pantrix UI

Radio Button

A radio button: a ring that is selected or not, and the label it is the ring of. One of several, of which one is chosen.

import com.pantrixui.components.elements.radiobutton.PantrixRadioButton

Examples

Disabled and read-only

The group's enabled = false disables every option; the label and the supporting text are written in the disabled text colour too. Which option is selected can still be seen.

A PantrixRadioButton given onClick = null is read-only: it takes no press and no focus, its colours do not change, and it still says its name and that it is selected.

PantrixRadioGroup(
    options = listOf(
        RadioOption("card", "Card", tagKey = "card"),
        RadioOption("transfer", "Bank transfer", tagKey = "transfer")
    ),
    selected = "card",
    onSelect = {},
    orientation = Orientation.Horizontal,
    enabled = false,
    label = "Payment",
    supportingText = "Disabled: your saved card will be charged",
    tagKey = "payment"
)
PantrixRadioButton(
    selected = true,
    onClick = null,
    label = "Read-only",
    supportingText = "Cannot be pressed; it only shows what was chosen",
    tagKey = "read_only"
)

On its own: inside cards

On its own, PantrixRadioButton is for a layout a group cannot make: here each option is inside a card. The caller holds the selection: each button is told whether it is selected through selected, and asks through onClick when it is pressed.

The buttons are in a column that carries Modifier.selectableGroup(): a screen reader hears them as one choice. Moving with the arrow keys is the group's work, and there is none of it here: each button is a separate stop for Tab.

var plan by rememberSaveable { mutableStateOf("monthly") }
Column(
    modifier = Modifier.widthIn(max = 360.dp).selectableGroup(),
    verticalArrangement = Arrangement.spacedBy(PantrixTheme.spacing.sm)
) {
    PantrixCard(modifier = Modifier.fillMaxWidth(), variant = CardVariant.Outlined) {
        PantrixRadioButton(
            selected = plan == "monthly",
            onClick = { plan = "monthly" },
            modifier = Modifier.fillMaxWidth(),
            label = "Monthly",
            supportingText = "Renews every month; you can cancel at any time",
            tagKey = "plan_monthly"
        )
    }
    PantrixCard(modifier = Modifier.fillMaxWidth(), variant = CardVariant.Outlined) {
        PantrixRadioButton(
            selected = plan == "yearly",
            onClick = { plan = "yearly" },
            modifier = Modifier.fillMaxWidth(),
            label = "Yearly",
            supportingText = "Paid once a year",
            tagKey = "plan_yearly"
        )
    }
}

API

selected

A radio button: a ring that is selected or not, and the label it is the ring of. One of several, of which one is chosen.

ParameterTypeDefaultWhat it is
selectedBooleanwhether this is the option chosen.
onClick(() -> Unit)?called when the user presses the radio button, selected already or not. The radio button changes nothing by itself: it is selected when selected says so. Null makes it read-only.
modifierModifierModifierthe row's modifier.
enabledBooleantruewhether the radio button can be selected. One that cannot is drawn in the disabled colours and says so.
labelString?nullthe text beside the ring: part of the target, and the radio button's name for a screen reader.
supportingTextString?nullhelp under the label, in a smaller type: the message, while error is true.
errorBooleanfalsewhether the choice is wrong or missing: the ring and the supporting text turn to the danger role, and a screen reader is told the input is invalid.
styleRadioStyle?nullthis call's own style: over every enclosing one and under the density. Only the fields it sets change, on every platform.
colorsRadioColors?nullthis radio button's own colours: the ones it sets, with the theme's for the rest. A disabled ring and one in error keep the theme's.
contentDescriptionString?nullwhat a screen reader says for the radio button: its name where it has no label, as in a card that is the option, or in place of the label.
tagKeyString?nullthe radio button's automation key: the row is RadioButton_<tagKey>. A press is reported as a RadioButton event, and never by its label.
interactionSourceMutableInteractionSource?nullthe radio button's interactions, hoisted. It keeps a source of its own when this is null.
controlPositionControlPositionControlPosition.Startwhere the ring stands: before the label, as a list of choices has it, or after it. After it, the ring is at the end of the width the row is given, Modifier.fillMaxWidth() lining it up with the others, or right after the label where the row is given none; the label wraps in what the ring leaves.

RadioStyle

PantrixRadioButton's ring and the dot in it: how large each is, and how thick the ring.

ParameterTypeDefaultWhat it is
sizeDpDp.UnspecifiedThe ring's width and height, its line included.
dotSizeDpDp.UnspecifiedThe width and height of the dot in a selected ring.
strokeWidthDpDp.UnspecifiedHow thick the ring's line is.

RadioColors

What PantrixRadioButton and the options of PantrixRadioGroup are painted with, for ones that do not take the theme's: a colour that is set is used, and one that is left out stays the theme's role.

ParameterTypeDefaultWhat it is
selectedColorColor.UnspecifiedThe ring and the dot of the option that is chosen. The theme's primary.
unselectedColorColor.UnspecifiedThe ring of an option that is not. The theme's borderStrong: an empty ring is nothing but its line.

Accessibility