This is an illustration of Menu component.
<Menu
placement="top"
trigger={({ ...triggerProps }) => {
return (
<Button {...triggerProps}>
<ButtonText>Menu</ButtonText>
</Button>
)
}}
>
<MenuItem key="Community" textValue="Community">
<Icon as={GlobeIcon} size="sm" mr="$2" />
<MenuItemLabel size="sm">Community</MenuItemLabel>
</MenuItem>
<MenuItem key="Plugins" textValue="Plugins">
{/* PuzzleIcon is imported from 'lucide-react-native' */}
<Icon as={PuzzleIcon} size="sm" mr="$2" />
<MenuItemLabel size="sm">Plugins</MenuItemLabel>
</MenuItem>
<MenuItem key="Theme" textValue="Theme">
{/* PaintBucket is imported from 'lucide-react-native' */}
<Icon as={PaintBucket} size="sm" mr="$2" />
<MenuItemLabel size="sm">Theme</MenuItemLabel>
</MenuItem>
<MenuItem key="Settings" textValue="Settings">
<Icon as={SettingsIcon} size="sm" mr="$2" />
<MenuItemLabel size="sm">Settings</MenuItemLabel>
</MenuItem>
<MenuItem key="Add account" textValue="Add account">
<Icon as={AddIcon} size="sm" mr="$2" />
<MenuItemLabel size="sm">Add account</MenuItemLabel>
</MenuItem>
</Menu>

API Reference

Import

To use this component in your project, include the following import statement in your file.
import { Menu } from "@gluestack-ui/themed"

Anatomy

The structure provided below can help you identify and understand a Menu component's various parts.
export default () => (
<Menu>
<MenuItem>
<MenuItemLabel />
</MenuItem>
</Menu>
)

Component Props

This section provides a comprehensive reference list for the component props, detailing descriptions, properties, types, and default behavior for easy project integration.
Contains all menu related layout style props and actions. It inherits all the properties of React Native's View component.
Prop
Type
Default
Description
trigger
(_props: any, state: { open: boolean; }) => Element
-
Function that returns a React Element. This element will be used as a Trigger for the Menu
placement
"bottom" | "top" | "right" | "left" | "top left" | "top right" | "bottom left" | "bottom right" | "right top" | "right bottom" | "left top" | "left bottom"
bottom left
menu placement
defaultIsOpen
boolean
false
If true, the menu will be opened by default.
onOpen
() => void
true
This function will be invoked when the menu is opened.
onClose
() => void
-
This function will be invoked when menu is closed. It will also be called when the user attempts to close the menu via Escape key or backdrop press.
isOpen
boolean
false
Whether the menu is opened. Useful for controlling the open state.
offset
number
-
The additional offset applied along the main axis between the element and its trigger element.
crossOffset
number
-
The additional offset applied along the cross axis between the element and its trigger element.
disabledKeys
string []
-
Item keys in this collection will be disabled.
closeOnSelect
boolean
true
This prop determine whether menu is closed after option is selected.
selectedKeys
'all' | Iterable<Key>
-
The currently selected keys in the collection (controlled).
selectionMode
'none'| 'single' | 'multiple'
-
The type of selection that is allowed in the collection.
onSelectionChange
(keys: 'all' | Iterable<Key>) => void
-
Handler that is called when the selection changes.
Contains all button related layout style props and actions. It inherits all the properties of React Native's Pressable component.
Prop
Type
Default
Description
closeOnSelect
boolean
true
This prop determine whether menu is closed after option is selected.
Descendants Styling Props Props to style child components.
Sx Prop
Description
_text
Prop to style MenuItemLabel Component
Contains all text related layout style props and actions. It inherits all the properties of React Native's Text component.

Features

  • Keyboard support for actions.
  • Support for hover, focus and active states.

Accessibility

We have outlined the various features that ensure the Menu component is accessible to all users, including those with disabilities. These features help ensure that your application is inclusive and meets accessibility standards.

Examples

The Examples section provides visual representations of the different variants of the component, allowing you to quickly and easily determine which one best fits your needs. Simply copy the code and integrate it into your project.
Menu Component provides different placement options, allowing you to position it dynamically based on user interaction or layout requirements.
placement
<Menu
placement="top"
trigger={({ ...triggerProps }) => {
return (
<Button {...triggerProps}>
<ButtonText>Menu</ButtonText>
</Button>
)
}}
>
<MenuItem key="Community" textValue="Community">
<Icon as={GlobeIcon} size="sm" mr="$2" />
<MenuItemLabel size="sm">Community</MenuItemLabel>
</MenuItem>
<MenuItem key="Plugins" textValue="Plugins">
{/* PuzzleIcon is imported from 'lucide-react-native' */}
<Icon as={PuzzleIcon} size="sm" mr="$2" />
<MenuItemLabel size="sm">Plugins</MenuItemLabel>
</MenuItem>
<MenuItem key="Theme" textValue="Theme">
{/* PaintBucket is imported from 'lucide-react-native' */}
<Icon as={PaintBucket} size="sm" mr="$2" />
<MenuItemLabel size="sm">Theme</MenuItemLabel>
</MenuItem>
<MenuItem key="Settings" textValue="Settings">
<Icon as={SettingsIcon} size="sm" mr="$2" />
<MenuItemLabel size="sm">Settings</MenuItemLabel>
</MenuItem>
<MenuItem key="Add account" textValue="Add account">
<Icon as={AddIcon} size="sm" mr="$2" />
<MenuItemLabel size="sm">Add account</MenuItemLabel>
</MenuItem>
</Menu>

Disabled MenuItem

Our Menu component supports dynamic disabling of menu items, enabling you to control the availability and interaction of specific menu options based on conditions or user permissions.
<Menu
placement={"top"}
disabledKeys={["Theme"]}
trigger={({ ...triggerProps }) => {
return (
<Button {...triggerProps}>
<ButtonText>Menu</ButtonText>
</Button>
)
}}
>
<MenuItem key="Community" textValue="Community">
<Icon as={GlobeIcon} size="sm" mr="$2" />
<MenuItemLabel size="sm">Community</MenuItemLabel>
</MenuItem>
<MenuItem key="Plugins" textValue="Plugins">
{/* PuzzleIcon is imported from 'lucide-react-native' */}
<Icon as={PuzzleIcon} size="sm" mr="$2" />
<MenuItemLabel size="sm">Plugins</MenuItemLabel>
</MenuItem>
<MenuItem key="Theme" textValue="Theme">
{/* PaintBucket is imported from 'lucide-react-native' */}
<Icon as={PaintBucket} size="sm" mr="$2" />
<MenuItemLabel size="sm">Theme</MenuItemLabel>
</MenuItem>
<MenuItem key="Settings" textValue="Settings">
<Icon as={SettingsIcon} size="sm" mr="$2" />
<MenuItemLabel size="sm">Settings</MenuItemLabel>
</MenuItem>
<MenuItem key="Add account" textValue="Add account">
<Icon as={AddIcon} size="sm" mr="$2" />
<MenuItemLabel size="sm">Add account</MenuItemLabel>
</MenuItem>
</Menu>

Selection

Our menu component supports selection mode, logging the selected menu item key to the console when a selection change occurs. Based on the selected key, it prints a corresponding message, indicating a route push for the menu items in the example given below.
function Example() {
const [selected, setSelected] = React.useState(new Set([]))
return (
<Menu
placement="bottom left"
selectionMode="single"
selectedKeys={selected}
onSelectionChange={(keys) => {
console.log("onSelectionChange", keys)
setSelected(keys)
if (keys.currentKey === "Community") {
console.log("Push to", keys.currentKey, "route")
} else if (keys.currentKey === "Plugins") {
console.log("Push to", keys.currentKey, "route")
} else if (keys.currentKey === "Theme") {
console.log("Push to", keys.currentKey, "route")
} else if (keys.currentKey === "Settings") {
console.log("Push to", keys.currentKey, "route")
}
}}
closeOnSelect={true}
trigger={({ ...triggerProps }) => {
return (
<Button {...triggerProps}>
<ButtonText>Menu</ButtonText>
</Button>
)
}}
>
<MenuItem key="Community" textValue="Community">
<Icon as={GlobeIcon} size="sm" mr="$2" />
<MenuItemLabel size="sm">Community</MenuItemLabel>
</MenuItem>
<MenuItem key="Plugins" textValue="Plugins">
{/* PuzzleIcon is imported from 'lucide-react-native' */}
<Icon as={PuzzleIcon} size="sm" mr="$2" />
<MenuItemLabel size="sm">Plugins</MenuItemLabel>
</MenuItem>
<MenuItem key="Theme" textValue="Theme">
{/* PaintBucket is imported from 'lucide-react-native' */}
<Icon as={PaintBucket} size="sm" mr="$2" />
<MenuItemLabel size="sm">Theme</MenuItemLabel>
</MenuItem>
<MenuItem key="Settings" textValue="Settings">
<Icon as={SettingsIcon} size="sm" mr="$2" />
<MenuItemLabel size="sm">Settings</MenuItemLabel>
</MenuItem>
</Menu>
)
}

Unstyled

All the components in gluestack-ui are unstyled by default. To customize your UI using the extendedTheme, please refer to this link. The import names of components serve as keys to customize each component.

Spec Doc

Explore the comprehensive details of the Menu in this document, including its implementation details, checklist, and potential future additions. Dive into the thought process behind the component and gain insights into its development journey.