Skip to content

TabRow

TabRow is a navigation component in Miuix used to create horizontally scrollable tabs. It provides two variants: standard style and contour style, suitable for content categorization and navigation scenarios.

Import

kotlin
import top.yukonga.miuix.kmp.basic.TabRow // Standard style
import top.yukonga.miuix.kmp.basic.TabRowWithContour // Contour style

Basic Usage

Standard Style

kotlin
val tabs = listOf("Recommended", "Following", "Popular", "Featured")
var selectedTabIndex by remember { mutableStateOf(0) }

TabRow(
    tabs = tabs,
    selectedTabIndex = selectedTabIndex,
    onTabSelected = { selectedTabIndex = it }
)

Contour Style

kotlin
val tabs = listOf("All", "Photos", "Videos", "Documents")
var selectedTabIndex by remember { mutableStateOf(0) }

TabRowWithContour(
    tabs = tabs,
    selectedTabIndex = selectedTabIndex,
    onTabSelected = { selectedTabIndex = it }
)

Properties

TabRow Properties

Property NameTypeDescriptionDefault ValueRequired
tabsList<String>List of tab texts-Yes
selectedTabIndexIntCurrent selected tab index-Yes
modifierModifierModifier for the tab rowModifierNo
colorsTabRowColorsColor configurationTabRowDefaults.tabRowColors()No
minWidthDpMinimum width of each tabTabRowDefaults.TabRowMinWidthNo
heightDpHeight of the tab rowTabRowDefaults.TabRowHeightNo
cornerRadiusDpCorner radius of tabsTabRowDefaults.TabRowCornerRadiusNo
onTabSelected((Int) -> Unit)?Callback when tab is selectednullNo

TabRowWithContour Properties

Property NameTypeDescriptionDefault ValueRequired
tabsList<String>List of tab texts-Yes
selectedTabIndexIntCurrent selected tab index-Yes
modifierModifierModifier for the tab rowModifierNo
colorsTabRowColorsColor configurationTabRowDefaults.tabRowColors()No
minWidthDpMinimum width of each tabTabRowDefaults.TabRowWithContourMinWidthNo
heightDpHeight of the tab rowTabRowDefaults.TabRowHeightNo
cornerRadiusDpCorner radius of tabsTabRowDefaults.TabRowWithContourCornerRadiusNo
onTabSelected((Int) -> Unit)?Callback when tab is selectednullNo

TabRowDefaults Object

The TabRowDefaults object provides default configurations for the TabRow component.

Constants

Constant NameTypeValueDescription
TabRowHeightDp42.dpDefault height of tab row
TabRowCornerRadiusDp8.dpDefault corner radius for standard style
TabRowWithContourCornerRadiusDp10.dpDefault corner radius for contour style
TabRowMinWidthDp76.dpMin width of tabs for standard style
TabRowWithContourMinWidthDp62.dpMin width of tabs for contour style

Methods

Method NameTypeDescription
tabRowColors()TabRowColorsCreate default color configuration

TabRowColors Class

Property NameTypeDescription
backgroundColorColorDefault background color of tabs
contentColorColorDefault content color of tabs
selectedBackgroundColorColorBackground color of selected tab
selectedContentColorColorContent color of selected tab

Advanced Usage

Custom Colors

kotlin
val tabs = listOf("Latest", "Popular", "Following")
var selectedTabIndex by remember { mutableStateOf(0) }

TabRow(
    tabs = tabs,
    selectedTabIndex = selectedTabIndex,
    onTabSelected = { selectedTabIndex = it },
    colors = TabRowDefaults.tabRowColors(
        backgroundColor = Color.LightGray.copy(alpha = 0.5f),
        contentColor = Color.Gray,
        selectedBackgroundColor = MiuixTheme.colorScheme.primary,
        selectedContentColor = Color.White
    )
)

Custom Dimensions

kotlin
val tabs = listOf("Short Videos", "Live", "Articles")
var selectedTabIndex by remember { mutableStateOf(0) }

TabRowWithContour(
    tabs = tabs,
    selectedTabIndex = selectedTabIndex,
    onTabSelected = { selectedTabIndex = it },
    minWidth = 100.dp,
    height = 50.dp,
    cornerRadius = 15.dp
)

Using with Pager

kotlin
val tabs = listOf("Page 1", "Page 2", "Page 3")
val pagerState = rememberPagerState { tabs.size }
var selectedTabIndex by remember { mutableStateOf(0) }

LaunchedEffect(pagerState.currentPage) {
    selectedTabIndex = pagerState.currentPage
}

LaunchedEffect(selectedTabIndex) {
    pagerState.animateScrollToPage(selectedTabIndex)
}

Surface {
    Column {
        TabRow(
            tabs = tabs,
            selectedTabIndex = selectedTabIndex,
            onTabSelected = { selectedTabIndex = it }
        )
        HorizontalPager(
            pagerState = pagerState,
            modifier = Modifier.fillMaxSize()
        ) { page ->
            Box(
                modifier = Modifier.fillMaxSize(),
                contentAlignment = Alignment.Center
            ) {
                Text("Page Content ${page + 1}")
            }
        }
    }
}

Released under the Apache-2.0 License