State of Compose 2023 results are in! Click here to learn more

← Back to Wear Material Core

CompactChip

Component
in
Wear Material Core
. Since 1.2.0-rc01

Overview

Code Examples

Video

A compact Wear Material Chip 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.

The CompactChip has a max height designed to take no more than one line of text and/or one icon. This includes a visible chip height of 32.dp and 8.dp of padding above and below the chip in order to meet accessibility guidelines that request a minimum of 48.dp height and width of tappable area.

If a icon is provided then the labels should be "start" aligned, e.g. left aligned in ltr so that the text starts next to the icon.

The items are laid out as follows.

  1. If a label is provided then the chip will be laid out with the optional icon at the start of a row followed by the label.

  2. If only an icon is provided it will be laid out vertically and horizontally centered and the default width of defaultIconOnlyCompactChipWidth

If neither icon nor label is provided then the chip will displayed like an icon only chip but with no contents and background color.

The CompactChip can have different styles with configurable content colors and backgrounds including gradients.

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

For more information, see the Chips(https://developer.android.com/training/wearables/components/chips) guide.

@param onClick Will be called when the user clicks the chip @param background Resolves the background for this chip in different states. @param modifier Modifier to be applied to the chip @param label A slot for providing the chip's main label. The contents are expected to be text which is "start" aligned if there is an icon preset and "center" aligned if not. @param icon A slot for providing the chip's icon. The contents are expected to be a horizontally and vertically aligned icon. @param enabled Controls the enabled state of the chip. When false, this chip will not be clickable @param interactionSource The MutableInteractionSource representing the stream of Interactions for this Chip. You can create and pass in your own remembered MutableInteractionSource if you want to observe Interactions and customize the appearance / behavior of this Chip in different Interactions. @param contentPadding The spacing values to apply internally between the container and the content @param shape 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 @param border Resolves the border for this chip in different states. @param defaultIconOnlyCompactChipWidth The default width of the compact chip if there is no label @param defaultCompactChipTapTargetPadding Default padding to increase the tap target @param defaultIconSpacing Spacing between icon and label, if both are provided @param role Role semantics that accessibility services can use to provide more context to users.

Overloads

CompactChip

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
@Composable
fun CompactChip(
    onClick: () -> Unit,
    background: @Composable (enabled: Boolean) -> State<Painter>,
    modifier: Modifier,
    label: (@Composable RowScope.() -> Unit)?,
    icon: (@Composable BoxScope.() -> Unit)?,
    enabled: Boolean,
    interactionSource: MutableInteractionSource,
    contentPadding: PaddingValues,
    shape: Shape,
    border: @Composable (enabled: Boolean) -> State<BorderStroke?>?,
    defaultIconOnlyCompactChipWidth: Dp,
    defaultCompactChipTapTargetPadding: PaddingValues,
    defaultIconSpacing: Dp,
    role: Role?,
)

Parameters

NameDescription
onClickWill be called when the user clicks the chip
backgroundResolves the background for this chip in different states.
modifierModifier to be applied to the chip
labelA slot for providing the chip's main label. The contents are expected to be text which is "start" aligned if there is an icon preset and "center" aligned if not.
iconA slot for providing the chip's icon. The contents are expected to be a horizontally and vertically aligned icon.
enabledControls the enabled state of the chip. When false, this chip will not be clickable
interactionSourceThe MutableInteractionSource representing the stream of Interactions for this Chip. You can create and pass in your own remembered MutableInteractionSource if you want to observe Interactions and customize the appearance / behavior of this Chip in different Interactions.
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
borderResolves the border for this chip in different states.
defaultIconOnlyCompactChipWidthThe default width of the compact chip if there is no label
defaultCompactChipTapTargetPaddingDefault padding to increase the tap target
defaultIconSpacingSpacing between icon and label, if both are provided
roleRole semantics that accessibility services can use to provide more context to users