androidx.compose.material3
ModalWideNavigationRailSince 1.9
Composable function
One of the types and parts. It works like WideNavigationRail. Only the parameters that differ are described here.
A wide rail that opens over the content, with a dim layer, like a modal drawer. Set hideOnCollapse = true to hide it fully when closed.

var selected by remember { mutableIntStateOf(0) }
// Open only for this picture. Normally: rememberWideNavigationRailState()
val state = rememberWideNavigationRailState(WideNavigationRailValue.Expanded)
val items = listOf("Home" to Icons.Filled.Home, "Favorites" to Icons.Filled.Favorite, "Settings" to Icons.Filled.Settings)
Box(Modifier.size(400.dp, 320.dp)) {
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { Text("Content") }
ModalWideNavigationRail(state = state, hideOnCollapse = true) {
items.forEachIndexed { index, (label, icon) ->
WideNavigationRailItem(
railExpanded = true,
selected = selected == index,
onClick = { selected = index },
icon = { Icon(icon, contentDescription = null) },
label = { Text(label) },
)
}
}
}
Parameters
@Composable
fun ModalWideNavigationRail(
modifier: Modifier = Modifier,
state: WideNavigationRailState = rememberWideNavigationRailState(),
hideOnCollapse: Boolean = false,
collapsedShape: Shape = WideNavigationRailDefaults.modalCollapsedShape,
expandedShape: Shape = WideNavigationRailDefaults.modalExpandedShape,
colors: WideNavigationRailColors = WideNavigationRailDefaults.colors(),
header: @Composable (() -> Unit)? = null,
expandedHeaderTopPadding: Dp = 0.dp,
windowInsets: WindowInsets = WideNavigationRailDefaults.windowInsets,
arrangement: Arrangement.Vertical = WideNavigationRailDefaults.arrangement,
expandedProperties: ModalWideNavigationRailProperties = WideNavigationRailDefaults.ModalExpandedProperties,
contentPadding: PaddingValues = WideNavigationRailDefaults.ContentPadding,
content: @Composable () -> Unit,
)
hideOnCollapse: BooleanOptional
hideOnCollapse: BooleanOptionalDefault: false
Set to true for a modal rail that hides completely when collapsed.
collapsedShape: ShapeOptional
collapsedShape: ShapeOptionalDefault: WideNavigationRailDefaults.modalCollapsedShape
The outline of a modal rail while collapsed.
expandedShape: ShapeOptional
expandedShape: ShapeOptionalDefault: WideNavigationRailDefaults.modalExpandedShape
The outline of a modal rail while expanded.
expandedHeaderTopPadding: DpOptional
expandedHeaderTopPadding: DpOptionalDefault: 0.dp
Extra space above the header while a modal rail is expanded.
expandedProperties: ModalWideNavigationRailPropertiesOptional
expandedProperties: ModalWideNavigationRailPropertiesOptionalDefault: WideNavigationRailDefaults.ModalExpandedProperties
Window options for the expanded modal rail, like whether back collapses it.
Same as in WideNavigationRail: modifier, state, colors, header, windowInsets, arrangement, contentPadding, content.
Types and parts
WideNavigationRailModalWideNavigationRailWideNavigationRailItem
See also
WideNavigationRailDefaults: default values and helper functions forModalWideNavigationRail.