New Compose Multiplatform components arrived on Composables UICheck it out →

Component in Wear Material Compose

SelectableChip

Android

A [SelectableChip] is a specialized type of [Chip] that includes a slot for a bi-state selection control such as a radio button. This overload provides suitable accessibility semantics for a selectable control like [RadioButton]. For toggleable controls like [Checkbox] and [Switch], use [ToggleChip] instead.

The Wear Material [SelectableChip] offers four slots and a specific layout for an application icon, a label, a secondaryLabel and selection control. The application icon and secondaryLabel are optional. The items are laid out in a row with the optional icon at the start, a column containing the two label slots in the middle and a slot for the selection control at the end.

The [SelectableChip] is Stadium shaped and has a max height designed to take no more than two lines of text of [Typography.button] style. With localisation and/or large font sizes, the [SelectableChip] height adjusts to accommodate the contents. The label and secondary label should be consistently aligned.

The recommended set of [SelectableChipColors] can be obtained from [SelectableChipDefaults], e.g. [SelectableChipDefaults.selectableChipColors].

Chips can be enabled or disabled. A disabled chip will not respond to click events.

Last updated:

Installation

dependencies {
   implementation("androidx.wear.compose:compose-material:1.4.0-beta03")
}

Overloads

@Composable
fun SelectableChip(
    selected: Boolean,
    onClick: (Boolean) -> Unit,
    label: @Composable RowScope.() -> Unit,
    modifier: Modifier = Modifier,
    appIcon: @Composable (BoxScope.() -> Unit)? = null,
    secondaryLabel: @Composable (RowScope.() -> Unit)? = null,
    colors: SelectableChipColors = SelectableChipDefaults.selectableChipColors(),
    enabled: Boolean = true,
    interactionSource: MutableInteractionSource? = null,
    contentPadding: PaddingValues = SelectableChipDefaults.ContentPadding,
    shape: Shape = MaterialTheme.shapes.large,
    selectionControl: @Composable () -> Unit = {
        RadioButton(selected = selected, enabled = enabled)
    }
)

Parameters

namedescription
selectedBoolean flag indicating whether this button is currently selected.
onClickCallback to be invoked when this button is selected.
labelA slot for providing the chip's main label. The contents are expected to be text which is "start" aligned.
modifierModifier to be applied to the chip
appIconAn optional slot for providing an icon to indicate the purpose of the chip. The contents are expected to be a horizontally and vertically centre aligned icon of size [SelectableChipDefaults.IconSize]. In order to correctly render when the Chip is not enabled the icon must set its alpha value to [LocalContentAlpha].
secondaryLabelA slot for providing the chip's secondary label. The contents are expected to be text which is "start" aligned if there is an icon preset and "start" or "center" aligned if not. label and secondaryLabel contents should be consistently aligned.
colors[SelectableChipColors] that will be used to resolve the background and content color for this chip in different states, see [SelectableChipDefaults.selectableChipColors].
enabledControls the enabled state of the chip. When false, this chip will not be clickable
interactionSourcean optional hoisted [MutableInteractionSource] for observing and emitting [Interaction]s for this chip's "selectable" tap area. You can use this to change the chip's appearance or preview the chip in different states. Note that if null is provided, interactions will still happen internally.
contentPaddingThe spacing values to apply internally between the container and the content
shapeDefines the chip's shape. It is strongly recommended to use the default as this shape is a key characteristic of the Wear Material Theme
selectionControlA slot for providing the chip's selection control. One built-in type of selection control is supported, see [RadioButton]. For [Checkbox] and [Switch], use [ToggleChip] in order to provide the correct semantics for accessibility.

Code Example

SelectableChipWithRadioButton

@Composable
@Sampled
fun SelectableChipWithRadioButton() {
    var selectedRadioIndex by remember { mutableStateOf(0) }
    Column(
        modifier = Modifier.fillMaxSize(),
        verticalArrangement = Arrangement.Center,
        horizontalAlignment = Alignment.CenterHorizontally,
    ) {
        SelectableChip(
            modifier = Modifier.fillMaxWidth(),
            selected = selectedRadioIndex == 0,
            onClick = { selectedRadioIndex = 0 },
            label = {
                // The primary label should have a maximum 3 lines of text
                Text("Primary label", maxLines = 3, overflow = TextOverflow.Ellipsis)
            },
            secondaryLabel = {
                // and the secondary label should have max 2 lines of text.
                Text("Secondary label", maxLines = 2, overflow = TextOverflow.Ellipsis)
            },
            appIcon = {
                Icon(
                    painter = painterResource(id = R.drawable.ic_airplanemode_active_24px),
                    contentDescription = "airplane",
                    modifier = Modifier.size(24.dp).wrapContentSize(align = Alignment.Center),
                )
            },
            enabled = true,
        )
        Spacer(modifier = Modifier.height(8.dp))
        SelectableChip(
            modifier = Modifier.fillMaxWidth(),
            selected = selectedRadioIndex == 1,
            onClick = { selectedRadioIndex = 1 },
            label = {
                // The primary label should have a maximum 3 lines of text
                Text("Alternative label", maxLines = 3, overflow = TextOverflow.Ellipsis)
            },
            secondaryLabel = {
                // and the secondary label should have max 2 lines of text.
                Text("Alternative secondary", maxLines = 2, overflow = TextOverflow.Ellipsis)
            },
            appIcon = {
                Icon(
                    painter = painterResource(id = R.drawable.ic_airplanemode_active_24px),
                    contentDescription = "airplane",
                    modifier = Modifier.size(24.dp).wrapContentSize(align = Alignment.Center),
                )
            },
            enabled = true,
        )
    }
}