Skip to content

BreadcrumbBar

BreadcrumbBar is a horizontal navigation component in COUI that displays a trail of path segments as capsule-shaped items separated by arrow icons. When the content overflows the available width, it scrolls horizontally instead of collapsing, matching the file-manager convention on mobile devices.

The highlightIndex is decoupled from the items list: the caller may show the full path while highlighting any segment (e.g. the current directory or a parent the user navigated back to). The bar automatically scrolls to keep the highlighted item visible.

Import

kotlin
import io.github.suqi8.coui.kmp.basic.BreadcrumbBar
import io.github.suqi8.coui.kmp.basic.BreadcrumbItem
import io.github.suqi8.coui.kmp.basic.joinToPath

Basic Usage

kotlin
val items = listOf(
    BreadcrumbItem(path = "/storage/emulated/0", text = "Internal storage"),
    BreadcrumbItem(path = "DataBackup"),
    BreadcrumbItem(path = "apps"),
    BreadcrumbItem(path = "com.tencent.mobileqq"),
    BreadcrumbItem(path = "user_0"),
)

BreadcrumbBar(
    items = items,
    onItemClick = { index -> /* Navigate to segment at index */ },
)

Highlight Control

The highlightIndex parameter is decoupled from the items list. You can show the full path while highlighting any segment:

kotlin
var highlightIndex by remember { mutableIntStateOf(items.lastIndex) }

BreadcrumbBar(
    items = items,
    onItemClick = { index -> highlightIndex = index },
    highlightIndex = highlightIndex,
)

Joining Path Segments

Use the joinToPath extension function to reconstruct the full path from a list of BreadcrumbItems:

kotlin
val fullPath = items.joinToPath("/")
// Result: "/storage/emulated/0/DataBackup/apps/com.tencent.mobileqq/user_0"

val windowsPath = items.joinToPath("\\")
// Result: "/storage/emulated/0\\DataBackup\\apps\\com.tencent.mobileqq\\user_0"

Component States

Disabled State

kotlin
BreadcrumbBar(
    items = items,
    onItemClick = {},
    enabled = false,
)

Properties

Property NameTypeDescriptionDefault ValueRequired
itemsList<BreadcrumbItem>The list of breadcrumb items to display-Yes
onItemClick(Int) -> UnitCallback invoked with the index of the clicked item-Yes
modifierModifierModifier applied to the breadcrumb barModifierNo
highlightIndexIntIndex of the highlighted segment; negative to disable highlight and auto-scrollitems.lastIndexNo
enabledBooleanWhether items are clickable; horizontal scrolling remains active when disabledtrueNo
colorsBreadcrumbBarColorsColor configuration for the breadcrumb barBreadcrumbBarDefaults.breadcrumbBarColors()No
insideMarginPaddingValuesInternal padding of the breadcrumb barBreadcrumbBarDefaults.InsideMarginNo
itemMaxWidthDpMaximum width of each capsule-shaped item; text beyond this is truncatedBreadcrumbBarDefaults.ItemMaxWidthNo
scrollStateScrollState?Scroll state for horizontal scrolling; pass an externally hoisted state to preserve scroll position across recompositionsnullNo
interactionSourceMutableInteractionSource?Interaction source for the itemsnullNo
indicationIndication?Indication for click interactionsLocalIndication.currentNo
Property NameTypeDescriptionDefault ValueRequired
pathStringThe path segment, used by joinToPath to reconstruct the full path-Yes
textString?The display text. If null, path is used for displaynullNo

The BreadcrumbBarDefaults object provides default values and color configurations for breadcrumb bar components.

Constants

Constant NameTypeDescriptionDefault Value
InsideMarginPaddingValuesInternal padding of the breadcrumb barPaddingValues(horizontal = 12.dp, vertical = 8.dp)
ItemHeightDpHeight of each capsule-shaped item32.dp
ItemHorizontalPaddingDpHorizontal padding of each item (equals the corner radius for full semicircle ends)10.dp
ItemMaxWidthDpMaximum width of each capsule-shaped item; text beyond this is truncated160.dp

Methods

Method NameTypeDescription
breadcrumbBarColors()BreadcrumbBarColorsCreates color configuration for the breadcrumb bar
Property NameTypeDescription
colorColorText color of normal segments
highlightColorColorText color of the highlighted segment
disabledColorColorText color when disabled
separatorColorColorColor of the arrow separators
backgroundColorColorBackground color of normal segments
highlightBackgroundColorColorBackground color of the highlighted segment
disabledBackgroundColorColorBackground color when disabled

Advanced Usage

Custom Colors

kotlin
BreadcrumbBar(
    items = items,
    onItemClick = { index -> /* Handle click */ },
    colors = BreadcrumbBarDefaults.breadcrumbBarColors(
        color = COUITheme.colorScheme.onBackground.copy(alpha = 0.55f),
        highlightColor = COUITheme.colorScheme.primary,
        backgroundColor = COUITheme.colorScheme.onBackground.copy(alpha = 0.1f),
        highlightBackgroundColor = COUITheme.colorScheme.primary.copy(alpha = 0.2f),
    ),
)

Decoupled Highlight and Navigation

The highlightIndex is independent from the items list, enabling scenarios where you show the full path but highlight a parent segment:

kotlin
// Full path: /storage/emulated/0/DataBackup/apps/com.tencent.mobileqq/user_0
// Highlight on "apps" (index 2) to indicate the user navigated back
BreadcrumbBar(
    items = items,
    onItemClick = { index ->
        // Update items and highlightIndex as needed
        highlightIndex = index
    },
    highlightIndex = 2,
)

Changelog

Released under the Apache-2.0 License