Tabs

A set of layered sections of content—known as tab panels—that are displayed one at a time.

Tabs combines TabsList and a content callback in one composable. Pass a List<String> for labels and a content lambda that receives the selected tab index. The active tab animates its background and text color over 200 ms.

Usage

Standalone TabsList

Use TabsList alone when you want to manage the content area yourself — for example when the content lives in a LazyColumn or a Pager.

import com.komoui.components.TabsList
 
@Composable
fun Example() {
    var selectedTab by remember { mutableIntStateOf(0) }
    val tabs = listOf("Overview", "Analytics", "Reports")
 
    Column(modifier = Modifier.fillMaxSize().padding(16.dp)) {
        TabsList(
            selectedTabIndex = selectedTab,
            onTabSelected = { selectedTab = it },
            tabs = tabs,
            modifier = Modifier.fillMaxWidth()
        )
        Spacer(modifier = Modifier.height(16.dp))
        when (selectedTab) {
            0 -> Text("Overview content", color = MaterialTheme.styles.foreground)
            1 -> Text("Analytics content", color = MaterialTheme.styles.foreground)
            2 -> Text("Reports content", color = MaterialTheme.styles.foreground)
        }
    }
}

Custom Triggers

Use TabsTrigger directly when you need non-uniform tab widths or a fully custom tab bar layout.

import com.komoui.components.TabsTrigger
 
@Composable
fun Example() {
    var selectedTab by remember { mutableIntStateOf(0) }
    val tabs = listOf("Short", "A Longer Tab", "X")
 
    Row(modifier = Modifier.fillMaxWidth()) {
        tabs.forEachIndexed { index, label ->
            TabsTrigger(
                text = label,
                isSelected = selectedTab == index,
                onClick = { selectedTab = index },
                modifier = Modifier.wrapContentWidth()
            )
        }
    }
}

API Reference

Tabs

ParameterTypeDefaultDescription
selectedTabIndexIntIndex of the currently active tab.
onTabSelected(Int) -> UnitCalled when the user taps a tab, with the new index.
tabsList<String>Ordered list of tab labels rendered in TabsList.
modifierModifierModifierApplied to the outer Column that wraps the list and content.
content@Composable (tabIndex: Int) -> UnitContent lambda. Receives the selected tab index on each recomposition. Wrap with TabsContent for standard top padding.

TabsList

The tab bar without the content area. Use when you need finer control over layout.

ParameterTypeDefaultDescription
selectedTabIndexIntIndex of the currently active tab.
onTabSelected(Int) -> UnitCalled when the user taps a tab.
tabsList<String>Ordered list of tab labels.
modifierModifierModifierApplied to the Box container.

TabsTrigger

An individual animated tab button. Use directly for non-uniform widths or fully custom tab bars.

ParameterTypeDefaultDescription
textStringLabel displayed in the tab.
isSelectedBooleanControls the active background and text color.
onClick() -> UnitCalled when the tab is tapped.
modifierModifierModifierApplied to the tab button container.

TabsContent

A thin wrapper that applies fillMaxWidth() and 8 dp top padding to the content area. Optional — use it for consistent spacing between the tab bar and content.

ParameterTypeDefaultDescription
modifierModifierModifierApplied to the Box content container.
content@Composable () -> UnitThe panel content for the active tab.
Edit this page on GitHub