Modal and dismissible drawer

A navigation panel that slides over the content or pushes it aside, and can be closed again.

When to use

The modal drawer dims the content behind a scrim and closes on outside click, swipe or Escape. The dismissible drawer shares the screen with the content and is closed by the menu button.

Control either one with a DrawerState. open and close are suspend functions, so call them from a coroutine.

Playground

The interactive page has a playground with live property controls for this component and generated code.

Examples

Modal drawer

val drawerState = rememberDrawerState(DrawerValue.Closed)
val scope = rememberCoroutineScope()

Box(Modifier.fillMaxWidth().height(300.dp)) {
    ModalNavigationDrawer(
        drawerState = drawerState,
        drawerContent = {
            ModalDrawerSheet {
                Text("Mail", Modifier.padding(24.dp), style = MaterialTheme.typography.titleLarge)
                NavigationDrawerItem(
                    icon = { Icon(Icons.Rounded.Inbox, contentDescription = null) },
                    label = { Text("Inbox") },
                    selected = true,
                    onClick = { scope.launch { drawerState.close() } },
                    modifier = Modifier.padding(horizontal = 12.dp),
                )
            }
        },
    ) {
        Box(Modifier.fillMaxSize().padding(24.dp)) {
            Button(onClick = { scope.launch { drawerState.open() } }) { Text("Open drawer") }
        }
    }
}

Parameters

NameTypeDefaultDescription
drawerStateDrawerStaterememberDrawerState(Closed)Open, close and observe the drawer.
gesturesEnabledBooleantrueSwipe to open and close.
drawerContent@Composable () -> UnitThe sheet with NavigationDrawerItems.
scrimColorColorDrawerDefaults.scrimColorModal drawer only.

Guidelines

Do:

Don't:

Accessibility

Related components