Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@radix-ui/react-menu

Package Overview
Dependencies
Maintainers
8
Versions
262
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@radix-ui/react-menu

  • 0.1.1-rc.11
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.7M
decreased by-7.52%
Maintainers
8
Weekly downloads
 
Created

What is @radix-ui/react-menu?

@radix-ui/react-menu is a set of accessible, unstyled components for building menus in React applications. It provides a flexible and customizable way to create dropdown menus, context menus, and other types of menu interfaces.

What are @radix-ui/react-menu's main functionalities?

Basic Menu

This code demonstrates a basic menu with three items. When an item is selected, an alert is shown.

import { Menu, MenuTrigger, MenuContent, MenuItem } from '@radix-ui/react-menu';

function BasicMenu() {
  return (
    <Menu>
      <MenuTrigger>Open Menu</MenuTrigger>
      <MenuContent>
        <MenuItem onSelect={() => alert('Item 1 selected')}>Item 1</MenuItem>
        <MenuItem onSelect={() => alert('Item 2 selected')}>Item 2</MenuItem>
        <MenuItem onSelect={() => alert('Item 3 selected')}>Item 3</MenuItem>
      </MenuContent>
    </Menu>
  );
}

Submenu

This code demonstrates a menu with a submenu. The submenu contains two items, and selecting any item triggers an alert.

import { Menu, MenuTrigger, MenuContent, MenuItem, MenuSub, MenuSubTrigger, MenuSubContent } from '@radix-ui/react-menu';

function Submenu() {
  return (
    <Menu>
      <MenuTrigger>Open Menu</MenuTrigger>
      <MenuContent>
        <MenuItem onSelect={() => alert('Item 1 selected')}>Item 1</MenuItem>
        <MenuSub>
          <MenuSubTrigger>Submenu</MenuSubTrigger>
          <MenuSubContent>
            <MenuItem onSelect={() => alert('Subitem 1 selected')}>Subitem 1</MenuItem>
            <MenuItem onSelect={() => alert('Subitem 2 selected')}>Subitem 2</MenuItem>
          </MenuSubContent>
        </MenuSub>
        <MenuItem onSelect={() => alert('Item 2 selected')}>Item 2</MenuItem>
      </MenuContent>
    </Menu>
  );
}

Context Menu

This code demonstrates a context menu that appears on right-click. The menu contains two items, and selecting any item triggers an alert.

import { Menu, MenuTrigger, MenuContent, MenuItem } from '@radix-ui/react-menu';

function ContextMenu() {
  return (
    <div onContextMenu={(e) => { e.preventDefault(); document.getElementById('context-menu-trigger').click(); }}>
      Right-click here
      <Menu>
        <MenuTrigger id='context-menu-trigger' style={{ display: 'none' }} />
        <MenuContent>
          <MenuItem onSelect={() => alert('Context Item 1 selected')}>Context Item 1</MenuItem>
          <MenuItem onSelect={() => alert('Context Item 2 selected')}>Context Item 2</MenuItem>
        </MenuContent>
      </Menu>
    </div>
  );
}

Other packages similar to @radix-ui/react-menu

FAQs

Package last updated on 29 Sep 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc