Button group

Arranges related buttons and moves the ones that do not fit into an overflow menu.

When to use

ButtonGroup lays out clickable and toggleable items in a row. Items grow slightly when pressed and push their neighbors aside. When the available width is too small, the remaining items move into an overflow menu.

Use items through the group scope instead of placing buttons directly. That lets the group measure every item, decide what fits and build the overflow menu from the same data.

Playground

The interactive page has a playground with live property controls for this component and generated code.

Examples

Overflow

Narrow the window or use the playground to see items move into the menu.

var starred by rememberSaveable { mutableStateOf(false) }

ButtonGroup(
    modifier = Modifier.width(360.dp),
    overflowIndicator = { menuState -> ButtonGroupDefaults.OverflowIndicator(menuState) },
) {
    clickableItem(
        onClick = {},
        label = "Edit",
        icon = { Icon(Icons.Rounded.Edit, contentDescription = null) },
    )
    toggleableItem(
        checked = starred,
        label = "Star",
        onCheckedChange = { starred = it },
        icon = { Icon(Icons.Rounded.Star, contentDescription = null) },
    )
    clickableItem(
        onClick = {},
        label = "Share",
        icon = { Icon(Icons.Rounded.Share, contentDescription = null) },
    )
    clickableItem(
        onClick = {},
        label = "Delete",
        icon = { Icon(Icons.Rounded.Delete, contentDescription = null) },
    )
}

Parameters

NameTypeDefaultDescription
overflowIndicator@Composable (ButtonGroupMenuState) -> UnitShown when items do not fit. Use ButtonGroupDefaults.OverflowIndicator.
modifierModifierModifierConstrain the width to control when overflow happens.
expandedRatioFloat0.15fHow much a pressed item grows.
horizontalArrangementArrangement.HorizontalButtonGroupDefaults.HorizontalArrangementSpacing between items.
verticalAlignmentAlignment.VerticalAlignment.TopCross axis alignment of items.
contentButtonGroupScope.() -> UnitDeclare items with clickableItem, toggleableItem and customItem.

Guidelines

Do:

Don't:

Accessibility

Related components