Navigation
Navigation

Badged tabs

A segmented tab set where each tab carries a small count badge.

All
Unread 4
Flagged 2

Installation

caveui components are copy-paste Jetpack Compose built entirely on Material 3 — there's no caveui dependency to add. Make sure Material 3 is on your classpath (it ships with the Compose BOM), then copy the Usage snippet below into your project.

kotlin
// build.gradle.kts (module)
dependencies {
    implementation(platform("androidx.compose:compose-bom:2025.06.00"))
    implementation("androidx.compose.material3:material3")
}

Usage

kotlin
@Composable
fun BadgedTabs() {
    var selected by remember { mutableStateOf(0) }
    val tabs = listOf("All" to 0, "Unread" to 4, "Flagged" to 2)
    TabRow(selectedTabIndex = selected) {
        tabs.forEachIndexed { i, (label, count) ->
            Tab(
                selected = i == selected,
                onClick = { selected = i },
                text = {
                    Row(verticalAlignment = Alignment.CenterVertically) {
                        Text(label)
                        if (count > 0) {
                            Spacer(Modifier.width(6.dp))
                            Badge { Text("$count") }
                        }
                    }
                },
            )
        }
    }
}