Navigation rail

A vertical rail that collapses to icons or expands to full labels.

When to use

The wide navigation rail replaces the baseline rail and the standard drawer on medium and larger windows. One component covers both: collapsed it shows icons with small labels, expanded it shows icons beside full labels.

Toggle it from a menu button in the header. Pass railExpanded to every item so they lay out for the current state.

Examples

Collapsible rail

Use the menu button to expand and collapse.

val state = rememberWideNavigationRailState()
val scope = rememberCoroutineScope()
var selected by rememberSaveable { mutableIntStateOf(0) }
val expanded = state.targetValue == WideNavigationRailValue.Expanded

Box(Modifier.fillMaxWidth().height(380.dp)) {
    WideNavigationRail(
        state = state,
        header = {
            IconButton(
                modifier = Modifier.padding(start = 24.dp),
                onClick = { scope.launch { state.toggle() } },
            ) {
                Icon(
                    imageVector = if (expanded) Icons.Rounded.Close else Icons.Rounded.Menu,
                    contentDescription = if (expanded) "Collapse rail" else "Expand rail",
                )
            }
        },
    ) {
        NavDestinations.take(4).forEachIndexed { index, (icon, label) ->
            WideNavigationRailItem(
                selected = selected == index,
                onClick = { selected = index },
                icon = { Icon(icon, contentDescription = null) },
                label = { Text(label) },
                railExpanded = expanded,
            )
        }
    }
}

Parameters

NameTypeDefaultDescription
stateWideNavigationRailStaterememberWideNavigationRailState()Holds Collapsed or Expanded and animates between them.
header@Composable (() -> Unit)?nullSlot for a menu button or a FAB.
railExpandedBooleanItem parameter. Must match the rail state.
arrangementArrangement.VerticalWideNavigationRailDefaults.arrangementVertical placement of the items.

Guidelines

Do:

Don't:

Accessibility

Related components