Mantine Contextmenu screenshot

Mantine Contextmenu

Author Avatar Theme by Icflorescu
Updated: 6 Mar 2025
151 Stars

Craft your applications for productivity and meet your users’ expectations by enhancing your Mantine-based UIs with a desktop-grade, lightweight yet fully-featured, dark-theme aware context-menu component, built by the creator of Mantine DataTable.

Categories

Overview

The Mantine ContextMenu is a “dark-theme aware” context-menu for Mantine UI applications. It is built by the creator of Mantine DataTable and offers a lightweight, customizable, and well-documented solution for implementing context menus in Mantine applications.

Features

  • Lightweight: No external dependencies or bloat, ensuring optimal performance.
  • Dark-theme aware: Automatically adapts to the current Mantine theme, providing a seamless user experience.
  • Simple API: Just wrap your application in the ContextMenuProvider component and use the hook-generated function in your code.
  • Custom content support: Allows you to use any Mantine component as context menu content, giving you flexibility in design and functionality.
  • Highly customizable styling: Offers options like className/classNames, style/styles, and sx props to easily customize the appearance of the context menu.
  • Written in Typescript and well-documented: Each exported function and component is accompanied by detailed JSDoc annotations, making it easy to understand and use.
  • Full documentation and examples: Visit the official documentation to explore the full capabilities of Mantine ContextMenu and learn how to use it effectively.

Installation

To install the Mantine ContextMenu, follow these steps:

  1. Install the package and its dependencies:

    npm install @mantine/context-menu
    # or
    yarn add @mantine/context-menu
    
  2. If you’re using Next.js, Vite, CRA, Remix, or Gatsby, you may need to install additional dependencies. Refer to Mantine’s getting started page for more details.

  3. Wrap your application in the ContextMenuProvider component:

    import { ContextMenuProvider } from '@mantine/context-menu';
    
    function App() {
      return (
        <ContextMenuProvider>
          {/* Your application code */}
        </ContextMenuProvider>
      );
    }
    
  4. Use the hook-generated function in your code:

    import { useContextMenu } from '@mantine/context-menu';
    
    function MyComponent() {
      const contextMenu = useContextMenu();
    
      return (
        <div>
          <button onClick={contextMenu.open}>Open Context Menu</button>
        </div>
      );
    }
    

Make sure to refer to the list of usage examples to discover the full potential of Mantine ContextMenu and how to make the most of it in your application.

Summary

The Mantine ContextMenu is a powerful and customizable solution for incorporating context menus into Mantine UI applications. With its lightweight nature, automatic dark-theme adaptation, simple API, and support for custom content, it provides a seamless and tailored user experience. Its extensive documentation and examples make it easy to implement and explore the full capabilities of Mantine ContextMenu in your projects. Consider sponsoring the author’s work to support its development and maintenance.