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

@radix-ui/react-dropdown-menu

Package Overview
Dependencies
Maintainers
8
Versions
264
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@radix-ui/react-dropdown-menu

  • 0.1.5-rc.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.2M
decreased by-16.94%
Maintainers
8
Weekly downloads
 
Created

What is @radix-ui/react-dropdown-menu?

The @radix-ui/react-dropdown-menu package is a set of low-level, unstyled UI primitives for building accessible dropdown and context menus in React applications. It provides the core functionality for dropdown menus without enforcing specific styling, allowing developers to customize the appearance as needed.

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

Triggering a Dropdown Menu

This code sample shows how to create a basic dropdown menu with a trigger and several items. The `DropdownMenu.Root` component wraps the entire menu, `DropdownMenu.Trigger` is used to open the menu, and `DropdownMenu.Content` contains the menu items.

{"import * as DropdownMenu from '@radix-ui/react-dropdown-menu';\n\nexport default function Example() {\n  return (\n    <DropdownMenu.Root>\n      <DropdownMenu.Trigger>Actions</DropdownMenu.Trigger>\n      <DropdownMenu.Content>\n        <DropdownMenu.Item>Item 1</DropdownMenu.Item>\n        <DropdownMenu.Item>Item 2</DropdownMenu.Item>\n        <DropdownMenu.Item>Item 3</DropdownMenu.Item>\n      </DropdownMenu.Content>\n    </DropdownMenu.Root>\n  );\n}"}

Creating Submenus

This code demonstrates how to create a submenu within a dropdown menu. The `DropdownMenu.Sub` component is used to wrap the submenu, with `DropdownMenu.SubTrigger` to open the submenu and `DropdownMenu.SubContent` to contain the submenu items.

{"import * as DropdownMenu from '@radix-ui/react-dropdown-menu';\n\nexport default function Example() {\n  return (\n    <DropdownMenu.Root>\n      <DropdownMenu.Trigger>Actions</DropdownMenu.Trigger>\n      <DropdownMenu.Content>\n        <DropdownMenu.Item>Item 1</DropdownMenu.Item>\n        <DropdownMenu.Sub>\n          <DropdownMenu.SubTrigger>More Options</DropdownMenu.SubTrigger>\n          <DropdownMenu.SubContent>\n            <DropdownMenu.Item>Sub Item 1</DropdownMenu.Item>\n          </DropdownMenu.SubContent>\n        </DropdownMenu.Sub>\n      </DropdownMenu.Content>\n    </DropdownMenu.Root>\n  );\n}"}

Customizing Menu Items

This code snippet illustrates how to customize the appearance of dropdown menu items using CSS-in-JS with the `styled` function from a library like `@stitches/react`. The `StyledItem` component is a styled version of `DropdownMenu.Item` with custom padding, border radius, and focus styles.

{"import * as DropdownMenu from '@radix-ui/react-dropdown-menu';\nimport { styled } from '@stitches/react';\n\nconst StyledItem = styled(DropdownMenu.Item, {\n  padding: '10px 20px',\n  borderRadius: '3px',\n  '&:focus': {\n    backgroundColor: 'blue',\n    color: 'white'\n  }\n});\n\nexport default function Example() {\n  return (\n    <DropdownMenu.Root>\n      <DropdownMenu.Trigger>Actions</DropdownMenu.Trigger>\n      <DropdownMenu.Content>\n        <StyledItem>Custom Item 1</StyledItem>\n        <StyledItem>Custom Item 2</StyledItem>\n      </DropdownMenu.Content>\n    </DropdownMenu.Root>\n  );\n}"}

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

FAQs

Package last updated on 12 Jan 2022

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