androidx.compose.material3

WideNavigationRailSince 1.9

Composable function

The wide navigation rail is the Expressive version of the NavigationRail. It can collapse to a narrow rail, or expand to a wider panel with labels next to icons, like a drawer.

The rail's state decides if it is expanded. Create it with rememberWideNavigationRailState(), and call expand(), collapse() or toggle() on it from a coroutine, for example from a menu button in the header.

An expanded wide railExpressive theme
An expanded wide rail
var selected by remember { mutableIntStateOf(0) }
val state = rememberWideNavigationRailState(WideNavigationRailValue.Expanded)
val items = listOf("Home" to Icons.Filled.Home, "Favorites" to Icons.Filled.Favorite, "Settings" to Icons.Filled.Settings)
WideNavigationRail(state = state, modifier = Modifier.height(320.dp)) {
    items.forEachIndexed { index, (label, icon) ->
        WideNavigationRailItem(
            railExpanded = state.targetValue == WideNavigationRailValue.Expanded,
            selected = selected == index,
            onClick = { selected = index },
            icon = { Icon(icon, contentDescription = null) },
            label = { Text(label) },
        )
    }
}

ModalWideNavigationRail opens over the content with a dim layer, like a modal drawer. Use it on smaller screens.

Parameters

@Composable
fun WideNavigationRail(
    modifier: Modifier = Modifier,
    state: WideNavigationRailState = rememberWideNavigationRailState(),
    shape: Shape = WideNavigationRailDefaults.shape,
    colors: WideNavigationRailColors = WideNavigationRailDefaults.colors(),
    header: @Composable (() -> Unit)? = null,
    windowInsets: WindowInsets = WideNavigationRailDefaults.windowInsets,
    arrangement: Arrangement.Vertical = WideNavigationRailDefaults.arrangement,
    contentPadding: PaddingValues = WideNavigationRailDefaults.ContentPadding,
    content: @Composable () -> Unit,
)

modifier: ModifierOptional

Default: Modifier

Changes size, padding, or position. See the Modifier guide.

state: WideNavigationRailStateOptional

Default: rememberWideNavigationRailState()

Whether the rail is expanded or collapsed.

shape: ShapeOptional

Default: WideNavigationRailDefaults.shape

Sets the outline of the rail.

colors: WideNavigationRailColorsOptional

Default: WideNavigationRailDefaults.colors()

Sets rail and item colors. Make one with WideNavigationRailDefaults.colors for the rail, or WideNavigationRailItemDefaults.colors() for items.

header: @Composable (() -> Unit)?Optional

Default: null

Something above the items, like a menu button or a FAB.

windowInsets: WindowInsetsOptional

Default: WideNavigationRailDefaults.windowInsets

Space kept free for system bars. The default is usually right.

arrangement: Arrangement.VerticalOptional

Default: WideNavigationRailDefaults.arrangement

Where the items sit: at the top (default) or centered.

contentPadding: PaddingValuesOptionalSince 1.11

Default: WideNavigationRailDefaults.ContentPadding

Space between the edge of the rail and its content.

content: @Composable () -> UnitRequired

The items. Add one WideNavigationRailItem for each destination.

Types and parts

See also