Light Dark System

Menu

<p-menu> | PMenu
Since 1.0 stable

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.

Undo Redo Cut Copy Paste Delete
<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>
);

Examples

In Dropdowns

Menus work really well when used inside dropdowns.

Edit Cut Copy Paste
<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>
);

To create a submenu, nest an <p-menu slot="submenu"> in any menu item.

Undo Redo Cut Copy Paste Find Find… Find Next Find Previous Transformations Make uppercase Make lowercase Capitalize
<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>
);

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.

Script Import Bundler React

To import this component from the CDN using a script tag:

<script type="module" src="https://cdn.jsdelivr.net/npm/pure-uikit@1.2.15/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.2.15/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.