Skip to main content

Menu

A menu shows a list of choices on a temporary surface, anchored to the control that opened it. It follows the Material Design 3 Menu specification.

Menu renders through Portal, so wrap your app in a PortalHost once at the root. It claims the PORTAL_LAYERS.menu layer, which puts it above bottom sheets, dialogs, and snackbars. A menu can open from any of them.

Usage​

Pass the trigger as anchor and the choices as children. With no visible prop, Menu manages its own open state. It hooks the press of the anchor to open, and closes on an outside press, an item press, or the Android back button.

import { IconButton, Menu, PortalHost } from '@rootnative/components'
import { mdiResolver } from '@rootnative/components/mdi'
import { ThemeProvider } from '@rootnative/core'
import { SafeAreaProvider } from 'react-native-safe-area-context'
import { useState } from 'react'
import { Text, View } from 'react-native'

function Screen() {
const [last, setLast] = useState('nothing yet')
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center', gap: 16 }}>
<Text>Last action: {last}</Text>
<Menu
align="end"
anchor={<IconButton icon="dots-vertical" accessibilityLabel="More actions" />}
>
<Menu.Item label="Edit" leadingIcon="pencil-outline" onPress={() => setLast('Edit')} />
<Menu.Item label="Duplicate" leadingIcon="content-copy" onPress={() => setLast('Duplicate')} />
<Menu.Item label="Delete" leadingIcon="trash-can-outline" onPress={() => setLast('Delete')} />
</Menu>
</View>
)
}

export default function App() {
return (
<SafeAreaProvider>
<ThemeProvider iconResolver={mdiResolver}>
<PortalHost>
<Screen />
</PortalHost>
</ThemeProvider>
</SafeAreaProvider>
)
}

The anchor renders where the <Menu> sits in your tree, wrapped in a measuring View. In self-managing mode it must be a single element that accepts onPress. Every Root Native pressable does. Its own onPress still fires.

Controlled​

Pass visible and onDismiss to drive the visibility yourself. Menu then never toggles itself. You wire the press of the anchor, and onDismiss fires for an outside press, an item press, and Android back.

import { Button, Divider, Menu, PortalHost } from '@rootnative/components'
import { mdiResolver } from '@rootnative/components/mdi'
import { ThemeProvider } from '@rootnative/core'
import { SafeAreaProvider } from 'react-native-safe-area-context'
import { useState } from 'react'
import { View } from 'react-native'

const SORTS = ['Name', 'Date modified', 'Size']

function Screen() {
const [open, setOpen] = useState(false)
const [sort, setSort] = useState('Name')
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Menu
visible={open}
onDismiss={() => setOpen(false)}
anchor={
<Button variant="outlined" trailingIcon="chevron-down" onPress={() => setOpen(true)}>
{`Sort: ${sort}`}
</Button>
}
>
{SORTS.map((option) => (
<Menu.Item
key={option}
label={option}
selected={option === sort}
leadingIcon={option === sort ? 'check' : undefined}
closeOnPress={false}
onPress={() => setSort(option)}
/>
))}
<Divider />
<Menu.Item label="Done" onPress={() => setOpen(false)} />
</Menu>
</View>
)
}

export default function App() {
return (
<SafeAreaProvider>
<ThemeProvider iconResolver={mdiResolver}>
<PortalHost>
<Screen />
</PortalHost>
</ThemeProvider>
</SafeAreaProvider>
)
}

Items​

Menu.Item renders a leading icon, a label, trailing text, and a trailing icon. All are optional except the label. Anything else you put in a Menu renders as given. That is how a Divider groups items.

PropRenders
labellabelLarge / onSurface, truncated to one line
leadingIcon24dp / onSurfaceVariant
trailingTextlabelLarge / onSurfaceVariant: a keyboard shortcut or a short status
trailingIcon24dp / onSurfaceVariant
disabledThe label and both icons dim together at 38% opacity, and keep their own colors. The item stops responding
selectedOne choice of a single-choice group. true gives the item a secondaryContainer background, and onSecondaryContainer for the label, the icons, and the trailing text. A vertical menu uses its own colors
checkedAn on/off setting. The same colors as selected
supportingTextA second line under the label. Vertical menu only
selectedLeadingIconThe leading icon while the item is selected or checked. Vertical menu only

An item press closes the menu. Set closeOnPress={false} on an item that toggles something and must stay open, such as a sort choice or a "show hidden files" switch.

Selected and checked items​

Use selected for a choice, such as a sort order, and checked for an on/off setting. An item takes one of the two. The type rejects both together. Both are controlled only: the items unmount when the menu closes, so you keep the state and change it in onPress.

{SORTS.map((option) => (
<Menu.Item
key={option}
label={option}
selected={option === sort}
closeOnPress={false}
onPress={() => setSort(option)}
/>
))}
<Divider />
<Menu.Item
label="Show hidden files"
checked={showHidden}
closeOnPress={false}
onPress={() => setShowHidden(!showHidden)}
/>

Set selected on every item of a group, false on the others, so a screen reader hears each one as a choice. The selected colors are the only mark that MD3 draws. Add a check icon when the difference must not rest on color alone.

A disabled selected or checked item keeps the plain colors at 38% opacity, on a 12% onSurface background, and a screen reader still hears its state.

Vertical menu​

variant="vertical" gives the MD3 Expressive vertical menu. The default, 'baseline', is the original MD3 menu.

<Menu variant="vertical" anchor={anchor}>
<Menu.Item label="Edit" leadingIcon="pencil-outline" onPress={edit} />
<Menu.Item label="Duplicate" leadingIcon="content-copy" onPress={duplicate} />
<Menu.Item label="Delete" leadingIcon="trash-can-outline" onPress={remove} />
</Menu>
PartBaselineVertical
ContainersurfaceContainer, corner 4dpsurfaceContainerLow, corner 16dp
Block padding8dp2dp
ItemSpans the full width, 48dp minimum height4dp in from each side, 44dp minimum height
Item cornersNone12dp on the outer corners of the first and the last item, 4dp on the others
LabellabelLargebodyLarge
Leading / trailing icon24dp20dp
Trailing textlabelLargelabelSmall
Selected or checked itemsecondaryContainer, onSecondaryContainer contenttertiaryContainer, onTertiaryContainer content, 12dp corners on every side
Disabled selected itemPlain colors at 38% on 12% onSurfacetertiaryContainer and onTertiaryContainer, both at 38%
Disabled item contentIts own colors at 38%onSurface at 38%

The menu finds the place of each item to set its corners. It sees an item that is a direct child, in an array from .map, or in a fragment. An item inside a component of your own takes the 4dp corners.

When an item becomes selected, its corners morph to 12dp on springFastSpatial. Reduced motion cuts the morph.

Supporting text and a selected icon​

A vertical item takes two more props:

  • supportingText puts a second line under the label, in bodyMedium and onSurfaceVariant. It wraps when it's longer than the menu is wide, and the item sits 2dp more in from the group edge at the top and the bottom.
  • selectedLeadingIcon is the leading icon while the item is selected or checked. With a leadingIcon, it replaces that icon while the item is selected. With no leadingIcon, it grows in from 0 to 20dp on springFastSpatial and fades in on springFastEffects. The gap after it grows too, so an item that isn't selected lines up with an item that has no icon. Reduced motion cuts both.
<Menu variant="vertical" anchor={anchor}>
<Menu.Group label="Sort by">
<Menu.Item label="Name" selected={sort === 'name'} selectedLeadingIcon="check" onPress={() => setSort('name')} />
<Menu.Item label="Size" selected={sort === 'size'} selectedLeadingIcon="check" onPress={() => setSort('size')} />
</Menu.Group>
<Menu.Group>
<Menu.Item label="Archive" leadingIcon="archive-outline" supportingText="Hide it from the list" onPress={archive} />
</Menu.Group>
</Menu>

The supporting text takes the content color of the item: onTertiaryContainer on a selected item, and the vibrant colors in a vibrant menu. contentColor replaces it, and labelStyle doesn't reach it.

Both props work in a vertical menu only. The MD3 baseline menu item has neither, so a baseline menu ignores them and warns in development.

Groups​

Menu.Group splits a vertical menu into groups. A group takes an optional label.

<Menu variant="vertical" anchor={anchor}>
<Menu.Group label="Sort by">
<Menu.Item label="Name" selected={sort === 'name'} onPress={() => setSort('name')} />
<Menu.Item label="Size" selected={sort === 'size'} onPress={() => setSort('size')} />
</Menu.Group>
<Menu.Group>
<Menu.Item label="Show hidden files" checked={showHidden} onPress={toggleHidden} />
</Menu.Group>
</Menu>
PartValue
GroupsurfaceContainerLow, elevation level 2, 2dp block padding
Gap between groups2dp
First group16dp top corners, 8dp bottom corners
Middle group8dp corners
Last group8dp top corners, 16dp bottom corners
LabellabelLarge / onSurface, 32dp minimum height, 12dp start and 4dp end padding

With two or more groups, each group draws its own surface, and the menu surface is a clear column. With one group, the menu surface is the group. The items of each group get their corners from their place in that group.

The menu sees a group that is a direct child, in an array, or in a fragment. Children outside a Menu.Group form a group of their own, so each item is on a group surface.

Menu.Group works in a vertical menu only. The MD3 baseline menu has no groups, so a baseline menu renders the children of a group with no label, and warns in development.

Color styles​

colorStyle sets the colors of a vertical menu: standard, the default, or vibrant, for more emphasis.

<Menu variant="vertical" colorStyle="vibrant" anchor={anchor}>
<Menu.Item label="Edit" leadingIcon="pencil-outline" onPress={edit} />
<Menu.Item label="Pin" leadingIcon="pin-outline" checked={pinned} onPress={togglePin} />
</Menu>
Partstandardvibrant
Container and groupssurfaceContainerLowtertiaryContainer
Label and group labelonSurfaceonTertiaryContainer
Icons and trailing textonSurfaceVariantonTertiaryContainer
Selected or checked itemtertiaryContainer, onTertiaryContainer contenttertiary, onTertiary content
Disabled item contentonSurface at 38%onTertiaryContainer at 38%
Disabled selected itemtertiaryContainer and onTertiaryContainer, both at 38%tertiary and onTertiary, both at 38%

containerColor replaces the container of both styles. colorStyle works in a vertical menu only: a baseline menu ignores it and warns in development.

Placement​

side and align are preferences, not commands.

PropValuesDefaultMeaning
side'bottom' | 'top''bottom'Which side of the anchor the menu prefers
align'start' | 'center' | 'end''start'Cross-axis alignment against the anchor
offsetnumber0Gap between the anchor edge and the menu, in dp
screenMarginnumber8Minimum distance the menu keeps from every screen edge. The edges are inside the safe-area insets
maxHeightnumber—Caps the height of the menu in dp. The menu scrolls past it

align is logical: 'start' is the left edge of the anchor in LTR and its right edge in RTL.

A menu that doesn't fit on its preferred side flips to the other side, but only when that side has more room. A flip into a side with the same room only moves the clipping. Horizontally, the menu shifts back inside the margin instead of a flip. When neither side has room for the whole menu, it caps at the available height and scrolls.

The menu positions itself from the window coordinates of the anchor, measured when it opens. It doesn't follow the anchor while a scroll view moves under it. A close and a reopen measure again.

Height​

A menu never exceeds the space available on the side it resolved to. Anything past that would put items where nobody can see them. When the items don't fit, the menu caps at that space and scrolls.

maxHeight caps it sooner. It is a cap, not an override. It only ever makes the menu shorter, and the menu ignores a value larger than the available space.

{/* 30 items with room for all of them is a wall of text; 280dp reads better */}
<Menu maxHeight={280} anchor={anchor}>
{options.map((option) => (
<Menu.Item key={option} label={option} onPress={() => select(option)} />
))}
</Menu>

The placement decision includes the cap, and doesn't apply it after. So a menu that fits below the anchor once capped stays below it, and doesn't flip above because of its uncapped height.

The menu is confined to its PortalHost​

You can see a menu only inside the overlay layer it renders into, so the menu fits itself to that layer, not to the window. A PortalHost mounted inside a screen, below an app bar or above a bottom navigation, gives a layer shorter than the window. A tall menu then caps at the edge of the layer, and doesn't reach past it into a region that the layer would clip.

That is why the root of your app is the right place for PortalHost. It gives a menu the whole window. If you mount one per screen, a menu near the bottom of a long list has much less room to open into.

Overrides​

PropTarget
containerColorThe menu surface background. In a vertical menu of two or more groups, the background of each group
styleThe menu surface. In a vertical menu of two or more groups, the clear column that holds the groups
anchorStyleThe View wrapping the anchor
Menu.Group styleThe group. In a menu of two or more groups, the group surface
Menu.Item containerColorThe item background, also on a selected or checked item. The hover, press and focus layers derive from it again
Menu.Item contentColorThe label, both icons, and the trailing text of the item, also on a selected or checked item
Menu.Item labelStyleThe label Text only. It doesn't affect the icons

contentColor on an item is how a destructive choice gets the error color:

<Menu.Item label="Delete" leadingIcon="trash-can-outline" contentColor={theme.colors.error} />

A disabled item always uses the MD3 disabled treatment. Neither override changes that.

Tokens​

TokenValue
ContainersurfaceContainer, corner 4dp (cornerExtraSmall), elevation level 2
WidthAs wide as the widest item, min 112dp, max 280dp
Block padding8dp, inside the scroll area
Item height48dp minimum
Item padding12dp horizontal, 12dp between icon, label, and trailing content
Item labellabelLarge / onSurface
Leading / trailing icon24dp / onSurfaceVariant
Selected or checked itemsecondaryContainer, with onSecondaryContainer for the label and the icons
ScrimNone. An MD3 menu doesn't dim what is behind it

These are the baseline tokens. The vertical menu table gives the other variant.

Motion​

The menu scales in from 80% and fades on springFastSpatial. It grows out of the corner nearest the anchor, through transformOrigin. Under reduced motion, both go to their end values at once; see Motion.

The surface stays invisible for the frame between the mount and the measurement. Its own size decides which side it lands on, so the layout must run before the placement.

Accessibility​

  • The surface reports role="menu", and each item reports role="menuitem".
  • A selected or checked item reports its state through aria-checked. On the web, a selected item is a menuitemradio and a checked item a menuitemcheckbox. Native keeps menuitem, and TalkBack and VoiceOver read the checked state from aria-checked.
  • An item exposes accessibilityState.disabled.
  • On the web, a Menu.Group reports role="group", and its label is the name of the group. The label text itself is hidden from the screen reader, so it isn't read twice. On native, the screen reader reads the label as text before the items of the group.
  • The anchor is annotated for you, in both the controlled and the uncontrolled form: aria-haspopup="menu" plus an aria-expanded that follows the menu. So a screen reader announces the trigger as a control that opens a menu, not as a plain button.
  • On the web, focus moves into the menu when it opens, Arrow Down/Up and Tab move between the items, Escape dismisses, and focus returns to the anchor on close. See Accessibility. The surface is not marked modal on native, on purpose. A modal mark would also take the dismiss region below out of the accessibility tree.
  • The region that catches outside presses announces as a button labelled "Close menu". Override it with dismissAccessibilityLabel. An MD3 menu has no scrim, so this region is transparent. It exists to catch outside presses and to give a screen reader a way out.
  • On the web, an item shows a keyboard focus ring (secondary, 3dp), driven by the same focus-visible state as the rest of the library.

Props​

PropTypeDefaultRequiredDescription
anchorReactNode-YesThe trigger. Rendered where the `<Menu>` sits in the tree, wrapped in a measuring `View`. When `visible` is omitted the menu manages its own open state, and it needs to hook the trigger's press: pass a single element that accepts `onPress` (any Root Native pressable does). The element's own `onPress` still fires.
childrenReactNode-No`Menu.Item`s, `Divider`s, or arbitrary content. A vertical menu also takes `Menu.Group`s.
variantenumbaselineNoThe MD3 menu style. `'baseline'` has a 4dp corner, and its items span the full width. `'vertical'`, the MD3 Expressive menu, has a 16dp corner, and its items sit 4dp in from the edge with their own rounded corners. In a vertical menu, the place of a `Menu.Item` sets its corners, and the place of a `Menu.Group` sets the corners of its surface. The menu sees an item or a group that is a direct child, in an array, or in a fragment. An item inside another component of yours takes the middle shape.
colorStyleenum'standard'NoThe colors of a vertical menu. `'standard'` puts the groups on `surfaceContainerLow`, and a selected item on `tertiaryContainer`. `'vibrant'` puts the groups on `tertiaryContainer`, with `onTertiaryContainer` content, and a selected item on `tertiary`. Vertical menu only: a baseline menu ignores it and warns in development.
visibleboolean-NoControlled visibility. Omit to let the menu open itself on an anchor press and close itself on an outside press, an item press, or Android back.
onDismiss() => void-NoCalled when the menu closes — outside press, item press, or Android back. Required to close a controlled menu; optional otherwise.
sideenumbottomNoSide of the anchor the menu prefers. It flips to the other side when it does not fit and that side is roomier.
alignenumstartNoCross-axis alignment against the anchor.
offsetnumber0NoGap between the anchor edge and the menu, in dp.
screenMarginnumber8NoMinimum distance the menu keeps from every screen edge, in dp. The edges are inside the safe-area insets, so the menu stays off the system bars.
maxHeightnumber-NoCap the menu's height in dp, scrolling past it. Only ever makes the menu shorter: the space available on the resolved side still wins, since a menu taller than that would put items where they cannot be seen. Reach for it when a long menu *could* fill the screen but shouldn't — 30 items with room for all of them is a wall of text, and `maxHeight={280}` reads better.
containerColorstring-NoOverride the container (surface) color. The default is `surfaceContainer`, or in the vertical variant `surfaceContainerLow` (`tertiaryContainer` when vibrant). In a vertical menu of two or more groups, it colors each group.
hostNamestring-NoName of the `PortalHost` to render into. Defaults to the root host, which is what puts the menu above every other layer.
styleStyleProp<ViewStyle>-NoStyle applied to the menu surface. In a vertical menu of two or more groups, the surface is a clear column, and each group draws its own.
anchorStyleStyleProp<ViewStyle>-NoStyle applied to the `View` wrapping the anchor.
dismissAccessibilityLabelstringClose menuNoScreen-reader label for the full-screen region that closes the menu on an outside press.
testIDstring-NoTest id applied to the menu surface.
PropTypeDefaultRequiredDescription
labelstring-YesItem text.
leadingIconIconSource-NoLeading icon at 24dp, or 20dp in a vertical menu. Accepts a string name (resolved via the theme's `iconResolver`), a pre-rendered element, or a render function.
trailingIconIconSource-NoTrailing icon at 24dp, or 20dp in a vertical menu. Mutually exclusive with `trailingText` in practice.
trailingTextstring-NoTrailing text — a keyboard shortcut or a short status.
supportingTextstring-NoSupporting text under the label, in `bodyMedium`. It wraps when it is longer than the menu is wide. Vertical menu only: a baseline menu ignores it and warns in development.
selectedLeadingIconIconSource-NoLeading icon at 20dp while the item is selected or checked. With a `leadingIcon`, it replaces that icon while the item is selected. With no `leadingIcon`, it grows in and fades in on selection, and the label moves to make room. Vertical menu only: a baseline menu ignores it and warns in development.
onPress() => void-NoCalled when the item is pressed.
closeOnPressbooleanNoWhether pressing the item closes the menu. Set `false` for an item that toggles something and should stay open.
disabledbooleanNoGreys the item out at 38% and stops it responding.
containerColorstring-NoOverride the item's container background. Hover/press/focus state-layer colors are derived from it automatically. It also replaces the container of a selected or checked item.
contentColorstring-NoOverride every piece of content the item renders — label, both icons, and trailing text — and the state-layer colors derived from it. Defaults are `onSurface` for the label and `onSurfaceVariant` for the rest, or `onTertiaryContainer` for all of it in a vibrant menu. On a selected or checked item, all of it is `onSecondaryContainer`, or `onTertiaryContainer` in a vertical menu (`onTertiary` when vibrant).
labelStyleStyleProp<TextStyle>-NoStyle applied to the label `Text` only — does not affect the icons.
styleStyleProp<ViewStyle>-NoStyle applied to the item container. Static form only — the function form `(state) => style` is not supported because the item drives its background through Reanimated. Use `containerColor` / `contentColor` instead.
testIDstring-NoTest id applied to the item container.
selectedboolean-NoMakes the item one choice of a single-choice group, such as a sort order. `true` draws the MD3 selected item: `secondaryContainer`, or in a vertical menu `tertiaryContainer` (`tertiary` when vibrant) with 12dp corners. A screen reader hears the state through `aria-checked`, and the web renders `role="menuitemradio"`. Set it on every item of the group, `false` on the others.
checkedboolean-NoMakes the item an on/off setting, such as "Show hidden files". `true` draws the same selected item as `selected`. A screen reader hears the state through `aria-checked`, and the web renders `role="menuitemcheckbox"`. Flip it in `onPress`.
PropTypeDefaultRequiredDescription
labelstring-NoThe group label, in `labelLarge`, above the items. A screen reader hears it as the name of the group.
childrenReactNode-NoThe `Menu.Item`s of the group, `Divider`s, or arbitrary content.
styleStyleProp<ViewStyle>-NoStyle applied to the group. In a menu of two or more groups, that is the group surface.
testIDstring-NoTest id applied to the group.