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.
| Prop | Renders |
|---|---|
label | labelLarge / onSurface, truncated to one line |
leadingIcon | 24dp / onSurfaceVariant |
trailingText | labelLarge / onSurfaceVariant: a keyboard shortcut or a short status |
trailingIcon | 24dp / onSurfaceVariant |
disabled | The label and both icons dim together at 38% opacity, and keep their own colors. The item stops responding |
selected | One 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 |
checked | An on/off setting. The same colors as selected |
supportingText | A second line under the label. Vertical menu only |
selectedLeadingIcon | The 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>
| Part | Baseline | Vertical |
|---|---|---|
| Container | surfaceContainer, corner 4dp | surfaceContainerLow, corner 16dp |
| Block padding | 8dp | 2dp |
| Item | Spans the full width, 48dp minimum height | 4dp in from each side, 44dp minimum height |
| Item corners | None | 12dp on the outer corners of the first and the last item, 4dp on the others |
| Label | labelLarge | bodyLarge |
| Leading / trailing icon | 24dp | 20dp |
| Trailing text | labelLarge | labelSmall |
| Selected or checked item | secondaryContainer, onSecondaryContainer content | tertiaryContainer, onTertiaryContainer content, 12dp corners on every side |
| Disabled selected item | Plain colors at 38% on 12% onSurface | tertiaryContainer and onTertiaryContainer, both at 38% |
| Disabled item content | Its 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:
supportingTextputs a second line under the label, inbodyMediumandonSurfaceVariant. 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.selectedLeadingIconis the leading icon while the item is selected or checked. With aleadingIcon, it replaces that icon while the item is selected. With noleadingIcon, it grows in from 0 to 20dp onspringFastSpatialand fades in onspringFastEffects. 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>
| Part | Value |
|---|---|
| Group | surfaceContainerLow, elevation level 2, 2dp block padding |
| Gap between groups | 2dp |
| First group | 16dp top corners, 8dp bottom corners |
| Middle group | 8dp corners |
| Last group | 8dp top corners, 16dp bottom corners |
| Label | labelLarge / 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>
| Part | standard | vibrant |
|---|---|---|
| Container and groups | surfaceContainerLow | tertiaryContainer |
| Label and group label | onSurface | onTertiaryContainer |
| Icons and trailing text | onSurfaceVariant | onTertiaryContainer |
| Selected or checked item | tertiaryContainer, onTertiaryContainer content | tertiary, onTertiary content |
| Disabled item content | onSurface at 38% | onTertiaryContainer at 38% |
| Disabled selected item | tertiaryContainer 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.
| Prop | Values | Default | Meaning |
|---|---|---|---|
side | 'bottom' | 'top' | 'bottom' | Which side of the anchor the menu prefers |
align | 'start' | 'center' | 'end' | 'start' | Cross-axis alignment against the anchor |
offset | number | 0 | Gap between the anchor edge and the menu, in dp |
screenMargin | number | 8 | Minimum distance the menu keeps from every screen edge. The edges are inside the safe-area insets |
maxHeight | number | — | 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
| Prop | Target |
|---|---|
containerColor | The menu surface background. In a vertical menu of two or more groups, the background of each group |
style | The menu surface. In a vertical menu of two or more groups, the clear column that holds the groups |
anchorStyle | The View wrapping the anchor |
Menu.Group style | The group. In a menu of two or more groups, the group surface |
Menu.Item containerColor | The item background, also on a selected or checked item. The hover, press and focus layers derive from it again |
Menu.Item contentColor | The label, both icons, and the trailing text of the item, also on a selected or checked item |
Menu.Item labelStyle | The 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
| Token | Value |
|---|---|
| Container | surfaceContainer, corner 4dp (cornerExtraSmall), elevation level 2 |
| Width | As wide as the widest item, min 112dp, max 280dp |
| Block padding | 8dp, inside the scroll area |
| Item height | 48dp minimum |
| Item padding | 12dp horizontal, 12dp between icon, label, and trailing content |
| Item label | labelLarge / onSurface |
| Leading / trailing icon | 24dp / onSurfaceVariant |
| Selected or checked item | secondaryContainer, with onSecondaryContainer for the label and the icons |
| Scrim | None. 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 reportsrole="menuitem". - A
selectedorcheckeditem reports its state througharia-checked. On the web, aselecteditem is amenuitemradioand acheckeditem amenuitemcheckbox. Native keepsmenuitem, and TalkBack and VoiceOver read the checked state fromaria-checked. - An item exposes
accessibilityState.disabled. - On the web, a
Menu.Groupreportsrole="group", and itslabelis 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 anaria-expandedthat 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
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
anchor | ReactNode | - | Yes | The 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. |
children | ReactNode | - | No | `Menu.Item`s, `Divider`s, or arbitrary content. A vertical menu also takes `Menu.Group`s. |
variant | enum | baseline | No | The 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. |
colorStyle | enum | 'standard' | No | The 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. |
visible | boolean | - | No | Controlled 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 | - | No | Called when the menu closes — outside press, item press, or Android back. Required to close a controlled menu; optional otherwise. |
side | enum | bottom | No | Side of the anchor the menu prefers. It flips to the other side when it does not fit and that side is roomier. |
align | enum | start | No | Cross-axis alignment against the anchor. |
offset | number | 0 | No | Gap between the anchor edge and the menu, in dp. |
screenMargin | number | 8 | No | Minimum 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. |
maxHeight | number | - | No | Cap 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. |
containerColor | string | - | No | Override 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. |
hostName | string | - | No | Name of the `PortalHost` to render into. Defaults to the root host, which is what puts the menu above every other layer. |
style | StyleProp<ViewStyle> | - | No | Style 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. |
anchorStyle | StyleProp<ViewStyle> | - | No | Style applied to the `View` wrapping the anchor. |
dismissAccessibilityLabel | string | Close menu | No | Screen-reader label for the full-screen region that closes the menu on an outside press. |
testID | string | - | No | Test id applied to the menu surface. |
Menu.Item
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
label | string | - | Yes | Item text. |
leadingIcon | IconSource | - | No | Leading 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. |
trailingIcon | IconSource | - | No | Trailing icon at 24dp, or 20dp in a vertical menu. Mutually exclusive with `trailingText` in practice. |
trailingText | string | - | No | Trailing text — a keyboard shortcut or a short status. |
supportingText | string | - | No | Supporting 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. |
selectedLeadingIcon | IconSource | - | No | Leading 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 | - | No | Called when the item is pressed. |
closeOnPress | boolean | | No | Whether pressing the item closes the menu. Set `false` for an item that toggles something and should stay open. |
disabled | boolean | | No | Greys the item out at 38% and stops it responding. |
containerColor | string | - | No | Override 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. |
contentColor | string | - | No | Override 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). |
labelStyle | StyleProp<TextStyle> | - | No | Style applied to the label `Text` only — does not affect the icons. |
style | StyleProp<ViewStyle> | - | No | Style 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. |
testID | string | - | No | Test id applied to the item container. |
selected | boolean | - | No | Makes 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. |
checked | boolean | - | No | Makes 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`. |
Menu.Group
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
label | string | - | No | The group label, in `labelLarge`, above the items. A screen reader hears it as the name of the group. |
children | ReactNode | - | No | The `Menu.Item`s of the group, `Divider`s, or arbitrary content. |
style | StyleProp<ViewStyle> | - | No | Style applied to the group. In a menu of two or more groups, that is the group surface. |
testID | string | - | No | Test id applied to the group. |