Menu
A menu display a set of selectable actions or options.
Basic
Source Code
import {
Button,
ListItemText,
Menu,
MenuBody,
MenuFooter,
MenuHeader,
MenuItem,
MenuList,
} from '@ocean-network-express/magenta-ui/react';
import { ListItems } from '../../utils/Menu/Menu.helpers';Grouped menu
- You can group
MenuItemin aMenuListby addingListSubheader. - You can show multiple
MenuListin aMenuby putting them inMenuBody. - You can show multiple
MenuListin a horizontal direction by setting thecolumnsprop totrueforMenu.
Source Code
import {
ListItemText,
ListSubheader,
Menu,
MenuBody,
MenuHeader,
MenuItem,
MenuList,
} from '@ocean-network-express/magenta-ui/react';
import { ListItems } from '../../utils/Menu/Menu.helpers';
Sizes
- Menu supports 4 sizes
sm,md,lgandresponsiveand can be changed by passing thesizeprop. - Default
sizeislg.
Source Code
import {
ListItemText,
Menu,
MenuBody,
MenuHeader,
MenuItem,
MenuList,
} from '@ocean-network-express/magenta-ui/react';
import { ListItems } from '../../utils/Menu/Menu.helpers';
export const Sizes = () => {- With size
responsive, the component will be responsive to the viewport.
Screen prefix | Screen width | Component size |
|---|---|---|
xs → xl | 0px → 1279px | sm |
xl → 3xl | 1280px → 1919px | md |
3xl → ∞ | 1920px → ∞ | lg |
Source Code
import {
ListItemText,
Menu,
MenuBody,
MenuHeader,
MenuItem,
MenuList,
} from '@ocean-network-express/magenta-ui/react';
import { ListItems } from '../../utils/Menu/Menu.helpers';
export const SizeResponsive = () => {Nested-Collapsible Menu
Basic
- You can create a collapsible menu by using
CollapsibleMenuItemcomponent. CollapsibleMenuItemcan be controlled open state byopenandonOpenChangeprops.CollapsibleMenuItemrequiredlabelprop to render the inMenuItemas a trigger ofCollapsecomponent.
Source Code
import {
CollapsibleMenuItem,
ListItemText,
Menu,
MenuBody,
MenuHeader,
MenuItem,
MenuList,
} from '@ocean-network-express/magenta-ui/react';
export const BasicCollapsibleMenu = () => {
return (Nested Collapsible Menu
- You can create a nested collapsible menu by using
CollapsibleMenuItemcomponent recursively.
Source Code
import {
CollapsibleMenuItem,
ListItemText,
Menu,
MenuBody,
MenuHeader,
MenuItem,
MenuList,
MenuOption,
} from '@ocean-network-express/magenta-ui/react';
import { CollapsibleMenuItems } from '../../utils/Menu/Menu.helpers';Menu Collapse Icon
- Collapse Icon can be changed by passing
collapseIconprop toCollapsibleMenuItem. - Default
collapseIconisChevronRightOutline.
Nested Collapsible Menu with Checkbox
Source Code
import { CaretRightFill } from '@ocean-network-express/magenta-ui/icons';
import {
Checkbox,
CollapsibleMenuItem,
ListItemIcon,
ListItemText,
Menu,
MenuBody,
MenuHeader,
MenuItem,
MenuList,
MenuOption,Dropdown Menu
- Menu can be used as a drop-down menu by wrapping
MenuinDropdownMenucomponent and provide trigger button inDropdownMenuTriggerto toggle the menu.
Source Code
import {
Button,
DropdownMenu,
DropdownMenuTrigger,
ListItemText,
Menu,
MenuBody,
MenuHeader,
MenuItem,
MenuList,
} from '@ocean-network-express/magenta-ui/react';
Controlled open state
- You can control
Menustate withopenandonOpenChangeprops:
Source Code
import {
Button,
DropdownMenu,
DropdownMenuTrigger,
ListItemText,
Menu,
MenuBody,
MenuFooter,
MenuHeader,
MenuItem,
MenuList,
} from '@ocean-network-express/magenta-ui/react';DropdownConfig
The dropdownConfig props allow you to set the CSS of the dropdown list.
Strategy
- The
strategyprop allows you to control the positioning strategy of the popover. - The available strategies are
absoluteandfixed. - The default strategy is
absolute. - View more details: Fixed position scrolling example.
Placement
- If you want to place the drop-down menu anywhere relative to the button, use the
dropdownConfig.placementprop. - The available base directions are
top,right,bottom,left. - Each of these base placements has an alignment in the form [direction]-start and [direction]-end. For example,
right-start, orbottom-end. These allow you to align the tooltip to the edges of the button, rather than centering it. - The default placement is
bottom.
Note: The standalone
placementprop is deprecated. UsedropdownConfig.placementinstead. Theplacementprop will be removed in the next major version.
Source Code
import {
Button,
DropdownMenu,
DropdownMenuTrigger,
ListItemText,
Menu,
MenuBody,
MenuHeader,
MenuItem,
MenuList,
} from '@ocean-network-express/magenta-ui/react';
Branched menu
- A branched menu can be triggered from a drop-down menu by wrapping the current
MenuItemin anotherDropdownMenuas aDropdownMenuTrigger. - The branched menu will be toggled from parent menu by hovering or pressing
Right Arrow|Left Arrowon theMenuTrigger.
Source Code
import { ChevronRightOutline } from '@ocean-network-express/magenta-ui/icons';
import {
Button,
DropdownMenu,
DropdownMenuTrigger,
ListItemIcon,
ListItemText,
Menu,
MenuBody,
MenuHeader,
MenuItem,
MenuList,Caret menu
- You can show a caret icon on the drop-down menu by setting the
caretprop totrueinDropdownMenu.
Source Code
import { ChevronRightOutline } from '@ocean-network-express/magenta-ui/icons';
import {
Button,
DropdownMenu,
DropdownMenuTrigger,
ListItemIcon,
ListItemText,
Menu,
MenuBody,
MenuHeader,
MenuItem,
MenuList,DropdownMenuTrigger children
DropdownMenuTriggerallow user to pass any element as the trigger.- We recommend using a
buttonas a trigger so the menu can work correctly and ensure accessibility.
MenuItem click behavior
- The
MenuItemclicked event can be handled by theonItemClickcallback prop ofMenuor theonClickfunction ofMenuItem.
Source Code
import {
ListItemText,
Menu,
MenuBody,
MenuHeader,
MenuItem,
MenuList,
} from '@ocean-network-express/magenta-ui/react';
import * as React from 'react';
import { ListItems } from '../../utils/Menu/Menu.helpers';
- In the
DropdownMenucomponent, theMenuItemclicked event will trigger a close drop-down menu. You can prevent this behavior by setting thecloseOnItemClickprop ofDropdownMenutofalse.
Source Code
import {
Button,
Checkbox,
DropdownMenu,
DropdownMenuTrigger,
ListItemIcon,
ListItemText,
Menu,
MenuBody,
MenuHeader,
MenuItem,
MenuList,MenuItem active behavior
- The
MenuItemcould be set toactiveby passing theactiveprop toMenuItem.
Source Code
import { AddCircleOutline } from '@ocean-network-express/magenta-ui/icons';
import {
ListItemIcon,
ListItemText,
Menu,
MenuBody,
MenuHeader,
MenuItem,
MenuList,
} from '@ocean-network-express/magenta-ui/react';
import * as React from 'react';
Scrolling long content
- If the menu items exceed the available height or defined max-height of the menu, the
MenuBodywill be scrollable.
Source Code
import {
Avatar,
Button,
ListItemIcon,
ListItemText,
Menu,
MenuBody,
MenuFooter,
MenuHeader,
MenuItem,
MenuList,
} from '@ocean-network-express/magenta-ui/react';Source Code
// app/_components/ShowCase/Menu/Scrollable.tsx
// --------------------------------------------------
// Scrollable menu example with many items.
// Shows automatic scrolling behavior for long menus with Avatar and ListItemText.
import {
Avatar,
Button,
DropdownMenu,
DropdownMenuTrigger,
ListItemIcon,
ListItemText,Searchable menu
Basic
Source Code
// app/_components/ShowCase/Menu/Searchable.tsx
// --------------------------------------------------
// Searchable menu with filtering capability.
// Demonstrates dynamic menu item filtering based on search input.
import { FilterOutline, SearchOutline } from '@ocean-network-express/magenta-ui/icons';
import {
Button,
Checkbox,
DropdownMenu,
DropdownMenuTrigger,
Indicator,Searchable Menu with Select All
Source Code
import './style.css';
import { FilterOutline, SearchOutline } from '@ocean-network-express/magenta-ui/icons';
import {
Button,
Checkbox,
DropdownMenu,
DropdownMenuTrigger,
Indicator,
Input,
ListEmpty,
ListItemIcon,Accessibility
Menu, DropdownMenu follows WAI-ARIA recommendations:
Roles and properties
DropdownMenuTriggerhasrole="button",aria-haspopup="true",aria-expanded,aria-controls="dropdown-id"attributesMenuhasrole="menu"attributeMenuItemhasrole="menuitem"attribute
Keyboard navigation
Dropdown Menu Trigger
Key | Description |
|---|---|
Down ArrowSpaceEnterUp Arrow | Opens menu and moves focus to first menuitem |
Right Arrow | Opens branched menu and moves focus to first menuitem |
Left Arrow | Closes branched and moves focus to trigger menuitem |
MenuList
Key | Description |
|---|---|
Down Arrow | Moves focus to the next menu item. If focus is on the last menu item, moves focus to the first menu item. |
Up Arrow | Moves focus to the previous menu item. If focus is on the first menu item, moves focus to the last menu item. |
Home | Moves focus to the first menu item. |
End | Moves focus to the last menu item. |
Space/Enter | Trigger MenuItem clicked event. |
A-Za-z | Moves focus to the next menu item with a label that starts with the typed character if such an menu item exists. Otherwise, focus does not move. |
Escape | Closes the drop-down menu. Sets focus to the menu button. |
Was this page helpful?
Dropdown Menu
DropdownMenu
DropdownMenuTrigger
MenuList
MenuItem
CollapsibleMenuItem
MenuOption
MenuBody
ListSubheader