SplitSelectableChip

Functions summary

Unit
@Composable
SplitSelectableChip(
    selected: Boolean,
    onSelectionClick: (Boolean) -> Unit,
    label: @Composable RowScope.() -> Unit,
    onContainerClick: () -> Unit,
    modifier: Modifier,
    secondaryLabel: (@Composable RowScope.() -> Unit)?,
    colors: SplitSelectableChipColors,
    enabled: Boolean,
    selectionInteractionSource: MutableInteractionSource?,
    containerInteractionSource: MutableInteractionSource?,
    contentPadding: PaddingValues,
    shape: Shape,
    selectionControl: @Composable BoxScope.() -> Unit
)

A SplitSelectableChip is a specialized type of Chip that includes a slot for a selection control, such as a radio button.

Functions

SplitSelectableChip

@Composable
fun SplitSelectableChip(
    selected: Boolean,
    onSelectionClick: (Boolean) -> Unit,
    label: @Composable RowScope.() -> Unit,
    onContainerClick: () -> Unit,
    modifier: Modifier = Modifier,
    secondaryLabel: (@Composable RowScope.() -> Unit)? = null,
    colors: SplitSelectableChipColors = SelectableChipDefaults.splitSelectableChipColors(),
    enabled: Boolean = true,
    selectionInteractionSource: MutableInteractionSource? = null,
    containerInteractionSource: MutableInteractionSource? = null,
    contentPadding: PaddingValues = SelectableChipDefaults.ContentPadding,
    shape: Shape = MaterialTheme.shapes.large,
    selectionControl: @Composable BoxScope.() -> Unit = { RadioButton(selected = selected, enabled = enabled) }
): Unit

A SplitSelectableChip is a specialized type of Chip that includes a slot for a selection control, such as a radio button. The SplitSelectableChip differs from the SelectableChip by having two "tappable" areas, one clickable and one selectable.

The SplitSelectableChip provides suitable accessibility semantics for a selectable control like RadioButton. For toggleable controls like Checkbox and Switch, use SplitToggleChip.

The Wear Material SplitSelectableChip offers three slots and a specific layout for a label, secondaryLabel and selection control. The secondaryLabel is optional. The items are laid out with a column containing the two label slots and a slot for the selection control at the end.

A SplitSelectableChip has two tappable areas, one tap area for the labels and another for the selection control. The onContainerClick callback will be associated with the main body of the SplitSelectableChip with the onSelectionClick callback associated with the selection control area only.

For a SplitSelectableChip the background of the tappable background area behind the selection control will have a visual effect applied to provide a "divider" between the two tappable areas.

The SplitSelectableChip 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 SplitSelectableChip height adjusts to accommodate the contents. The label and secondary label should be consistently aligned.

The recommended set of SplitSelectableChipColors can be obtained from SelectableChipDefaults, e.g. SelectableChipDefaults.splitSelectableChipColors.

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

Example of a SplitSelectableChip with a label and the radio button selection control:

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.wear.compose.material.SelectableChip
import androidx.wear.compose.material.SplitSelectableChip
import androidx.wear.compose.material.Text

var selectedRadioIndex by remember { mutableStateOf(0) }
Column(
    modifier = Modifier.fillMaxSize(),
    verticalArrangement = Arrangement.Center,
    horizontalAlignment = Alignment.CenterHorizontally,
) {
    SplitSelectableChip(
        modifier = Modifier.fillMaxWidth(),
        selected = selectedRadioIndex == 0,
        onSelectionClick = { 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)
        },
        onContainerClick = {
            /* Do something */
        },
        enabled = true,
    )
    Spacer(modifier = Modifier.height(8.dp))
    SplitSelectableChip(
        modifier = Modifier.fillMaxWidth(),
        selected = selectedRadioIndex == 1,
        onSelectionClick = { 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)
        },
        onContainerClick = {
            /* Do something */
        },
        enabled = true,
    )
}

For more information, see the Toggle Chips guide.

Parameters
selected: Boolean

Boolean flag indicating whether this button is currently selected.

onSelectionClick: (Boolean) -> Unit

Callback to be invoked when this button is selected.

label: @Composable RowScope.() -> Unit

A slot for providing the chip's main label. The contents are expected to be text which is "start" aligned.

onContainerClick: () -> Unit

Callback to be invoked when the user clicks the main body of the chip, the area containing the labels.

modifier: Modifier = Modifier

Modifier to be applied to the chip

secondaryLabel: (@Composable RowScope.() -> Unit)? = null

A slot for providing the chip's secondary label. The contents are expected to be "start" or "center" aligned. label and secondaryLabel contents should be consistently aligned.

colors: SplitSelectableChipColors = SelectableChipDefaults.splitSelectableChipColors()

SplitSelectableChipColors that will be used to resolve the background and content color for this chip in different states, see SelectableChipDefaults.splitSelectableChipColors.

enabled: Boolean = true

Controls the enabled state of the chip. When false, this chip will not be clickable

selectionInteractionSource: MutableInteractionSource? = null

an optional hoisted MutableInteractionSource for observing and emitting Interactions 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.

containerInteractionSource: MutableInteractionSource? = null

an optional hoisted MutableInteractionSource for observing and emitting Interactions for this chip's "clickable" 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.

contentPadding: PaddingValues = SelectableChipDefaults.ContentPadding

The spacing values to apply internally between the container and the content

shape: Shape = MaterialTheme.shapes.large

Defines the chip's shape. It is strongly recommended to use the default as this shape is a key characteristic of the Wear Material Theme

selectionControl: @Composable BoxScope.() -> Unit = { RadioButton(selected = selected, enabled = enabled) }

A slot for providing the chip's selection control. One built-in selection control is provided, see RadioButton. For Checkbox and Switch, use SplitToggleChip instead.