Skip to content

NavigationRail

NavigationRail is a side navigation component in Miuix, suitable for wide screens. It offers different display modes (icon only, text only, icon and text, icon with selected label).

Import

kotlin
import top.yukonga.miuix.kmp.basic.NavigationRail
import top.yukonga.miuix.kmp.basic.NavigationRailItem
import top.yukonga.miuix.kmp.basic.NavigationRailDisplayMode

Basic Usage

The NavigationRail component can be used to create side navigation menus:

kotlin
var selectedIndex by remember { mutableStateOf(0) }
val items = listOf("Home", "Profile", "Settings")
val icons = listOf(MiuixIcons.VerticalSplit, MiuixIcons.Contacts, MiuixIcons.Settings)

Row {
    NavigationRail {
        items.forEachIndexed { index, label ->
            NavigationRailItem(
                selected = selectedIndex == index,
                onClick = { selectedIndex = index },
                icon = icons[index],
                label = label
            )
        }
    }
    // Content area
}

Component States

Selected State

NavigationRailItem automatically handles the visual style of the selected item, displaying it with bold text and highlighting the icon/text.

Properties

Property NameTypeDescriptionDefault ValueRequired
modifierModifierModifier applied to the railModifierNo
header@Composable (ColumnScope.() -> Unit)?Header content (e.g. FAB or Logo)nullNo
colorColorBackground color of the railMiuixTheme.colorScheme.surfaceNo
showDividerBooleanShow divider line between rail and contenttrueNo
defaultWindowInsetsPaddingBooleanApply default window insets paddingtrueNo
minWidthDpMinimum width of the railNavigationRailDefaults.MinWidthNo
modeNavigationRailDisplayModeDisplay mode for itemsNavigationRailDisplayMode.IconAndTextNo
content@Composable ColumnScope.()The content of the rail-Yes
Property NameTypeDescriptionDefault ValueRequired
selectedBooleanWhether the item is selected-Yes
onClick() -> UnitCallback when the item is clicked-Yes
iconImageVectorIcon of the item-Yes
labelStringLabel of the item-Yes
modifierModifierModifier applied to the itemModifierNo
enabledBooleanWhether the item is enabledtrueNo

The NavigationRailDefaults object provides default values for NavigationRail and NavigationRailItem components.

Constants

Constant NameTypeDescriptionDefault Value
MinWidthDpMinimum width of the rail80.dp
VerticalPaddingDpVertical padding of the content24.dp
HeaderSpacingDpSpacing after the header24.dp
IconSizeDpIcon size28.dp
IconTextSpacingDpSpacing between icon and text4.dp
ItemVerticalPaddingDpVertical padding for each item12.dp
LabelFontSizeTextUnitLabel font size12.sp
TextOnlyFontSizeTextUnitFont size in TextOnly mode14.sp
TextOnlyVerticalPaddingDpVertical padding in TextOnly mode4.dp
SelectedPressedAlphaFloatAlpha for selected pressed item0.5f
UnselectedPressedAlphaFloatAlpha for unselected pressed item0.6f
UnselectedAlphaFloatAlpha for unselected item0.4f
ValueDescription
IconAndTextDisplay both icon and text.
IconOnlyDisplay only icon.
TextOnlyDisplay only text.
IconWithSelectedLabelDisplay icon always, and text only when selected.

Changelog

Released under the Apache-2.0 License