Skip to content

NavigationRail ​

NavigationRail is a side navigation component for wide screens. It supports fixed collapsed, fixed expanded, and state-controlled layouts.

Import ​

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

Basic Usage ​

By default, NavigationRail uses the collapsed layout:

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
}

Layout Modes ​

Use the fixed-layout overload and set expanded to choose its layout:

kotlin
NavigationRail(expanded = true) {
    // NavigationRailItem content
}

Use the stateful overload to show a toggle and animate between layouts:

kotlin
val railState = rememberNavigationRailState()

NavigationRail(state = railState) {
    // NavigationRailItem(...)
}

Use railState.expand(), railState.collapse() or railState.toggle() to control the layout programmatically. Omit both state and expanded for a fixed collapsed rail.

Properties ​

NavigationRail provides two overloads. Use one of them:

Fixed Layout ​

ParameterTypeDescriptionDefaultRequired
expandedBooleanUse the expanded layoutfalseNo

Expandable Layout ​

ParameterTypeDescriptionDefaultRequired
stateNavigationRailStateControls the layout and displays the toggle-Yes
expandContentDescriptionStringToggle description when collapsedNavigationRailDefaults.ExpandContentDescriptionNo
collapseContentDescriptionStringToggle description when expandedNavigationRailDefaults.CollapseContentDescriptionNo

Common NavigationRail Parameters ​

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 (collapsed) width of the railNavigationRailDefaults.MinWidthNo
expandedWidthDpWidth of the rail when expandedNavigationRailDefaults.ExpandedWidthNo
scrollStateScrollStateScroll state of the rail's content columnrememberScrollState()No
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
badge(@Composable () -> Unit)?Optional badge shown on the item's icon, e.g. a BadgenullNo

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

Constants ​

Constant NameTypeDescriptionDefault Value
MinWidthDpMinimum (collapsed) width of the rail80.dp
ExpandedWidthDpWidth of the rail when expanded240.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
ExpandedLabelFontSizeTextUnitLabel font size when expanded16.sp
ExpandedItemHorizontalMarginDpMargin between an expanded item and edges12.dp
ExpandedItemCornerRadiusDpCorner radius of the selected pill16.dp
CollapsedIndicatorVerticalPaddingDpPadding of a collapsed item's indicator around its icon4.dp
ExpandedItemContentHorizontalPaddingDpHorizontal padding inside an expanded item14.dp
ExpandedItemContentVerticalPaddingDpVertical padding inside an expanded item14.dp
ExpandedItemIconTextSpacingDpSpacing between icon and label (expanded)16.dp
ExpandContentDescriptionStringToggle description while collapsed"Expand navigation rail"
CollapseContentDescriptionStringToggle description while expanded"Collapse navigation rail"

Create it with rememberNavigationRailState(initialValue) and pass it to NavigationRail to make the rail expandable.

MemberTypeDescription
currentValueNavigationRailValueThe current expansion value
isExpandedBooleanWhether the rail is currently expanded
expand()funExpands the rail
collapse()funCollapses the rail
toggle()funToggles between collapsed and expanded
ValueDescription
CollapsedThe rail is collapsed to MinWidth.
ExpandedThe rail is expanded to ExpandedWidth.

Changelog

Released under the Apache-2.0 License