Menu
<p-menu> | PMenu
Menus provide a list of options for the user to choose from.
You can use menu items, menu labels, and dividers to compose a menu. Menus support keyboard interactions, including type-to-select an option.
<p-menu style="max-width: 200px;"> <p-menu-item value="undo">Undo</p-menu-item> <p-menu-item value="redo">Redo</p-menu-item> <p-divider></p-divider> <p-menu-item value="cut">Cut</p-menu-item> <p-menu-item value="copy">Copy</p-menu-item> <p-menu-item value="paste">Paste</p-menu-item> <p-menu-item value="delete">Delete</p-menu-item> </p-menu>
import PDivider from 'pure-uikit/dist/react/divider'; import PMenu from 'pure-uikit/dist/react/menu'; import PMenuItem from 'pure-uikit/dist/react/menu-item'; const App = () => ( <PMenu style={{ maxWidth: '200px' }}> <PMenuItem value="undo">Undo</PMenuItem> <PMenuItem value="redo">Redo</PMenuItem> <PDivider /> <PMenuItem value="cut">Cut</PMenuItem> <PMenuItem value="copy">Copy</PMenuItem> <PMenuItem value="paste">Paste</PMenuItem> <PMenuItem value="delete">Delete</PMenuItem> </PMenu> );
Menus are intended for system menus (dropdown menus, select menus, context menus, etc.). They should not
be mistaken for navigation menus which serve a different purpose and have a different semantic meaning. If
you’re building navigation, use <nav>
and <a>
elements instead.
Examples
In Dropdowns
Menus work really well when used inside dropdowns.
<p-dropdown> <p-button slot="trigger" caret>Edit</p-button> <p-menu> <p-menu-item value="cut">Cut</p-menu-item> <p-menu-item value="copy">Copy</p-menu-item> <p-menu-item value="paste">Paste</p-menu-item> </p-menu> </p-dropdown>
import PButton from 'pure-uikit/dist/react/button'; import PDropdown from 'pure-uikit/dist/react/dropdown'; import PMenu from 'pure-uikit/dist/react/menu'; import PMenuItem from 'pure-uikit/dist/react/menu-item'; const App = () => ( <PDropdown> <PButton slot="trigger" caret>Edit</PButton> <PMenu> <PMenuItem value="cut">Cut</PMenuItem> <PMenuItem value="copy">Copy</PMenuItem> <PMenuItem value="paste">Paste</PMenuItem> </PMenu> </PDropdown> );
Submenus
To create a submenu, nest an <p-menu slot="submenu">
in any
menu item.
<p-menu style="max-width: 200px;"> <p-menu-item value="undo">Undo</p-menu-item> <p-menu-item value="redo">Redo</p-menu-item> <p-divider></p-divider> <p-menu-item value="cut">Cut</p-menu-item> <p-menu-item value="copy">Copy</p-menu-item> <p-menu-item value="paste">Paste</p-menu-item> <p-divider></p-divider> <p-menu-item> Find <p-menu slot="submenu"> <p-menu-item value="find">Find…</p-menu-item> <p-menu-item value="find-previous">Find Next</p-menu-item> <p-menu-item value="find-next">Find Previous</p-menu-item> </p-menu> </p-menu-item> <p-menu-item> Transformations <p-menu slot="submenu"> <p-menu-item value="uppercase">Make uppercase</p-menu-item> <p-menu-item value="lowercase">Make lowercase</p-menu-item> <p-menu-item value="capitalize">Capitalize</p-menu-item> </p-menu> </p-menu-item> </p-menu>
import PDivider from 'pure-uikit/dist/react/divider'; import PMenu from 'pure-uikit/dist/react/menu'; import PMenuItem from 'pure-uikit/dist/react/menu-item'; const App = () => ( <PMenu style={{ maxWidth: '200px' }}> <PMenuItem value="undo">Undo</PMenuItem> <PMenuItem value="redo">Redo</PMenuItem> <PDivider /> <PMenuItem value="cut">Cut</PMenuItem> <PMenuItem value="copy">Copy</PMenuItem> <PMenuItem value="paste">Paste</PMenuItem> <PDivider /> <PMenuItem> Find <PMenu slot="submenu"> <PMenuItem value="find">Find…</PMenuItem> <PMenuItem value="find-previous">Find Next</PMenuItem> <PMenuItem value="find-next">Find Previous</PMenuItem> </PMenu> </PMenuItem> <PMenuItem> Transformations <PMenu slot="submenu"> <PMenuItem value="uppercase">Make uppercase</PMenuItem> <PMenuItem value="lowercase">Make lowercase</PMenuItem> <PMenuItem value="capitalize">Capitalize</PMenuItem> </PMenu> </PMenuItem> </PMenu> );
As a UX best practice, avoid using more than one level of submenus when possible.
Importing
If you’re using the autoloader or the traditional loader, you can ignore this section. Otherwise, feel free to use any of the following snippets to cherry pick this component.
To import this component from the CDN using a script tag:
<script type="module" src="https://cdn.jsdelivr.net/npm/pure-uikit@1.3.13/cdn/components/menu/menu.js"></script>
To import this component from the CDN using a JavaScript import:
import 'https://cdn.jsdelivr.net/npm/pure-uikit@1.3.13/cdn/components/menu/menu.js';
To import this component using a bundler:
import 'pure-uikit/dist/components/menu/menu.js';
To import this component as a React component:
import PMenu from 'pure-uikit/dist/react/menu';
Slots
Name | Description |
---|---|
(default) | The menu’s content, including menu items, menu labels, and dividers. |
Learn more about using slots.
Events
Name | React Event | Description | Event Detail |
---|---|---|---|
p-select |
onPSelect |
Emitted when a menu item is selected. |
{ item: PMenuItem }
|
Learn more about events.