ContextMenu exposes multiple compound components that you can use to create a list of items, item sections and sub-menus.
<ContextMenu>
<View
height={50}
width={50}
backgroundColor="neutral-faded"
borderRadius="medium"
justify="center"
align="center"
/>
<ContextMenu.Content>
<ContextMenu.Item>Action 1</ContextMenu.Item>
<ContextMenu.Item>Action 2</ContextMenu.Item>
</ContextMenu.Content>
</ContextMenu>
ContextMenu itself serves as the root wrapper for the component.
ContextMenu supports most of the properties DropdownMenu does, allowing you to use its event handlers or position it differently. It will automatically try to fit into the viewport, using the position you pass as a default.
ContextMenu supports separating items into sections using the ContextMenu.Section component.
<ContextMenu>
<View
height={50}
width={50}
backgroundColor="neutral-faded"
borderRadius="medium"
justify="center"
align="center"
/>
<ContextMenu.Content>
<ContextMenu.Section>
<ContextMenu.Item>Action 1</ContextMenu.Item>
<ContextMenu.Item>Action 2</ContextMenu.Item>
</ContextMenu.Section>
<ContextMenu.Section>
<ContextMenu.Item>Action 3</ContextMenu.Item>
<ContextMenu.Item>Action 4</ContextMenu.Item>
</ContextMenu.Section>
</ContextMenu.Content>
</ContextMenu>
You can create one or multiple submenus inside your ContextMenu using ContextMenu.SubMenu and ContextMenu.SubTrigger. It automatically handles focus trapping for multiple levels of nesting.
<ContextMenu>
<View
height={50}
width={50}
backgroundColor="neutral-faded"
borderRadius="medium"
justify="center"
align="center"
/>
<ContextMenu.Content>
<ContextMenu.Item>Action 1</ContextMenu.Item>
<ContextMenu.Item>Action 2</ContextMenu.Item>
<ContextMenu.SubMenu>
<ContextMenu.SubTrigger>Action 3</ContextMenu.SubTrigger>
<ContextMenu.Content>
<ContextMenu.Item onClick={() => {}}>Sub-action 1</ContextMenu.Item>
<ContextMenu.Item onClick={() => {}}>Sub-action 2</ContextMenu.Item>
</ContextMenu.Content>
</ContextMenu.SubMenu>
</ContextMenu.Content>
</ContextMenu>