Skip to content

NavigationRail

NavigationRail is a side navigation component in Miuix, suitable for wide screens. It displays items as icon-above-label and can optionally expand to a wide icon-beside-label layout via NavigationRailState.

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

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
}

Expandable Rail

Pass a NavigationRailState (created with rememberNavigationRailState) to make the rail expandable. A built-in toggle button appears at the top-left; tapping it animates the rail between its collapsed width and expandedWidth. When expanded, each item switches to a horizontal icon-and-label layout with a highlighted pill behind the selected item.

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

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

You can also drive the state programmatically via railState.expand(), railState.collapse() or railState.toggle(). When state is left as null (the default), the rail keeps its classic non-expandable layout with no toggle button.

Properties

Property NameTypeDescriptionDefault ValueRequired
modifierModifierModifier applied to the railModifierNo
stateNavigationRailState?Expand/collapse state; non-null makes the rail expandablenullNo
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
expandContentDescriptionStringAccessible description of the toggle while collapsedNavigationRailDefaults.ExpandContentDescriptionNo
collapseContentDescriptionStringAccessible description of the toggle while expandedNavigationRailDefaults.CollapseContentDescriptionNo
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