---
title: "CompactButton"
description: "A Wear Material3 `CompactButton` that offers two slots and a specific layout for an icon and
label. Both the icon and label are optional however it is expected that at least one will be
provided."
type: "component"
---

<div class='type'>Composable Component</div>



A Wear Material3 `CompactButton` that offers two slots and a specific layout for an icon and
label. Both the icon and label are optional however it is expected that at least one will be
provided.

<a id='references'></a>

<div class='sourceset sourceset-android'>Android</div>


```kotlin
@Composable
public fun CompactButton(
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    onLongClick: (() -> Unit)? = null,
    onLongClickLabel: String? = null,
    icon: (@Composable BoxScope.() -> Unit)? = null,
    enabled: Boolean = true,
    shape: Shape = CompactButtonDefaults.shape,
    colors: ButtonColors = ButtonDefaults.buttonColors(),
    border: BorderStroke? = null,
    contentPadding: PaddingValues = CompactButtonDefaults.ContentPadding,
    interactionSource: MutableInteractionSource? = null,
    transformation: SurfaceTransformation? = null,
    label: (@Composable RowScope.() -> Unit)? = null,
)
```


#### Parameters

| | |
| --- | --- |
| onClick | Will be called when the user clicks the button |
| modifier | Modifier to be applied to the button |
| onLongClick | Called when this button is long clicked (long-pressed). When this callback is set, `onLongClickLabel` should be set as well. |
| onLongClickLabel | Semantic / accessibility label for the `onLongClick` action. |
| icon | A slot for providing the button's icon. The contents are expected to be a horizontally and vertically aligned icon of size `ButtonDefaults.ExtraSmallIconSize` when used with a label or `ButtonDefaults.SmallIconSize` when used as the only content in the button. |
| enabled | Controls the enabled state of the button. When `false`, this button will not be clickable. |
| shape | Defines the button's shape. It is strongly recommended to use the default as this shape is a key characteristic of the Wear Material3 Theme |
| colors | `ButtonColors` that will be used to resolve the background and content color for this button in different states. See `ButtonDefaults.buttonColors`. |
| border | Optional `BorderStroke` that will be used to resolve the border for this button in different states. |
| contentPadding | The spacing values to apply internally between the container and the content |
| interactionSource | an optional hoisted `MutableInteractionSource` for observing and emitting `Interaction`s for this button. You can use this to change the button's appearance or preview the button in different states. Note that if `null` is provided, interactions will still happen internally. |
| transformation | Transformation to be used when button appears inside a container that needs to dynamically change its content separately from the background. |
| label | A slot for providing the button's main label. The contents are expected to be a single line of text which is "start" aligned if there is an icon preset and "center" aligned if not. |






## Code Examples
### CompactButtonSample
```kotlin
@Composable
fun CompactButtonSample(modifier: Modifier = Modifier) {
    CompactButton(
        onClick = { /* Do something */ },
        icon = {
            Icon(
                painter = painterResource(R.drawable.ic_favorite_rounded),
                contentDescription = "Favorite icon",
                modifier = Modifier.size(ButtonDefaults.ExtraSmallIconSize),
            )
        },
        modifier = modifier,
    ) {
        Text("Compact Button", maxLines = 1, overflow = TextOverflow.Ellipsis)
    }
}
```
### CompactButtonWithOnLongClickSample
```kotlin
@Composable
fun CompactButtonWithOnLongClickSample(
    onClickHandler: () -> Unit,
    onLongClickHandler: () -> Unit,
    modifier: Modifier = Modifier,
) {
    CompactButton(
        onClick = onClickHandler,
        onLongClick = onLongClickHandler,
        onLongClickLabel = "Long click",
        label = { Text("Long clickable") },
        modifier =
            modifier.semantics {
                // Also override the 'click label' to say 'Double tap to press' instead of
                // the usual 'Double tap to activate'.
                onClick("press") { false }
            },
    )
}
```
### FilledTonalCompactButtonSample
```kotlin
@Composable
fun FilledTonalCompactButtonSample(modifier: Modifier = Modifier) {
    CompactButton(
        onClick = { /* Do something */ },
        icon = {
            Icon(
                painter = painterResource(R.drawable.ic_favorite_rounded),
                contentDescription = "Favorite icon",
                modifier = Modifier.size(ButtonDefaults.ExtraSmallIconSize),
            )
        },
        colors = ButtonDefaults.filledTonalButtonColors(),
        modifier = modifier,
    ) {
        Text("Filled Tonal Compact Button", maxLines = 1, overflow = TextOverflow.Ellipsis)
    }
}
```
### OutlinedCompactButtonSample
```kotlin
@Composable
fun OutlinedCompactButtonSample(modifier: Modifier = Modifier) {
    Column(horizontalAlignment = Alignment.CenterHorizontally) {
        var expanded by remember { mutableStateOf(false) }
        if (expanded) {
            Text("A multiline string showing two lines")
        } else {
            Text("One line text")
        }
        Spacer(Modifier.height(ButtonDefaults.IconSpacing))
        CompactButton(
            onClick = { expanded = !expanded },
            colors = ButtonDefaults.outlinedButtonColors(),
            border = ButtonDefaults.outlinedButtonBorder(enabled = true),
            modifier = modifier,
        ) {
            if (expanded) {
                Text("Show Less", maxLines = 1, overflow = TextOverflow.Ellipsis)
            } else {
                Text("Show More", maxLines = 1, overflow = TextOverflow.Ellipsis)
            }
            Spacer(Modifier.width(ButtonDefaults.IconSpacing))
            if (expanded) {
                Icon(
                    Icons.Filled.KeyboardArrowUp,
                    contentDescription = "Collapse",
                    modifier = Modifier.size(ButtonDefaults.ExtraSmallIconSize),
                )
            } else {
                Icon(
                    Icons.Filled.KeyboardArrowDown,
                    contentDescription = "Expand",
                    modifier = Modifier.size(ButtonDefaults.ExtraSmallIconSize),
                )
            }
        }
    }
}
```

