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.

An expanded modal wide rail over the contentExpressive theme
An expanded modal wide rail over the content
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

Default: false

Set to true for a modal rail that hides completely when collapsed.

collapsedShape: ShapeOptional

Default: WideNavigationRailDefaults.modalCollapsedShape

The outline of a modal rail while collapsed.

expandedShape: ShapeOptional

Default: WideNavigationRailDefaults.modalExpandedShape

The outline of a modal rail while expanded.

expandedHeaderTopPadding: DpOptional

Default: 0.dp

Extra space above the header while a modal rail is expanded.

expandedProperties: ModalWideNavigationRailPropertiesOptional

Default: 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

See also