New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@pras-ui/popup-menu

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pras-ui/popup-menu

A headless, accessible, and highly customizable multi purpose component(popup menu, context menu) for React.

latest
Source
npmnpm
Version
0.0.1
Version published
Maintainers
1
Created
Source

@pras-ui/popup-menu

A headless, accessible, and highly customizable multi purpose component(popup menu, context menu) for React.

@pras-ui/popup-menu provides the building blocks to create fully-featured popup menu. It handles all the complex logic, like state management, keyboard navigation, accessibility, and positioning, leaving you to focus on styling.

Features

  • Headless & Unstyled: Gives you full control over the appearance.
  • Full Keyboard Navigation: Arrow key navigation and shortcuts are supported out of the box.
  • Context Menu Mode: Can be triggered by right-clicking.
  • Sub-menus: Supports infinitely nested sub-menus.
  • Choice Items: Create radio groups or checkbox groups inside your menu.
  • RTL Support: Adapts automatically to right-to-left languages.
  • Accessible: Follows WAI-ARIA patterns for menus.

Installation

npm install @pras-ui/popup-menu

Usage

Here's how to create a basic popup menu. You can use any styling solution you prefer; this example uses simple class names.

import {
  PopupMenuRoot,
  PopupMenuTrigger,
  PopupMenuContent,
  PopupMenuItem,
  PopupMenuPortal,
} from "@pras-ui/popup-menu";

function MyPopupMenu() {
  return (
    <PopupMenuRoot>
      <PopupMenuTrigger asChild>
        <button className="my-trigger-button">Open Menu</button>
      </PopupMenuTrigger>

      <PopupMenuPortal>
        <PopupMenuContent className="my-menu-content" sideOffset={5}>
          <PopupMenuItem
            className="my-menu-item"
            onSelect={() => alert("New Tab")}
          >
            New Tab
          </PopupMenuItem>
          <PopupMenuItem
            className="my-menu-item"
            onSelect={() => alert("New Window")}
          >
            New Window
          </PopupMenuItem>
          <PopupMenuItem className="my-menu-item" disabled>
            New Incognito Window
          </PopupMenuItem>
        </PopupMenuContent>
      </PopupMenuPortal>
    </PopupMenuRoot>
  );
}

API Reference

PopupMenuRoot

PropTypeDefaultDescription
openbooleanThe controlled open state of the menu.
defaultOpenbooleanfalseThe initial open state when uncontrolled.
onOpenChange(open: boolean) => voidEvent handler called when the open state changes.
mode'default' | 'context''default''context' mode enables right-click triggering.
dir'ltr' | 'rtl'(inherited)The reading direction of the menu.

PopupMenuTrigger

The button or element that toggles the menu. It should be a direct child of PopupMenuRoot. It accepts all props of a standard button element.

AttributesTypeDescription
data-hoveredtrue | undefinedWhether the item is hovered.
data-focusedtrue | undefinedWhether the item is focused.
data-disabledtrue | undefinedWhether the item is disabled.
data-stateopened | closedThe open state of the menu.

PopupMenuPortal

Renders the menu content into a React Portal, ensuring it can overlay other elements. This is recommended to avoid z-index and clipping issues.

PopupMenuContent

PropTypeDefaultDescription
dir'ltr' | 'rtl'(inherited)The reading direction of the menu.
side'top' | 'bottom' | 'left' | 'right''bottom'The preferred side of the trigger to render the content on.
sideOffsetnumber0The distance in pixels from the trigger.
align'start' | 'center' | 'end''start'The preferred alignment of the content relative to the trigger.
alignOffsetnumber0The distance in pixels from the trigger.
collisionBoundaryBoundary | Boundary[]The boundary of the floating element.
collisionPaddingnumber | Record<Side, number>0The padding of the floating element.
sticky'partial' | 'always''partial'Whether to sticky the floating element.
autoHideOnDetachbooleanfalseWhether to auto hide the floating element on detach.
removeScrollbooleantrueWhether to remove scroll on the floating element.
position'absolute' | 'fixed''fixed'The position of the floating element.
updatePositionFrequency'lazy' | 'rapid''lazy'The frequency of the floating element position update.
alwaysRenderbooleanfalseWhether to always render the floating element.
loopbooleantrueWhether keyboard navigation should loop around.
avoidCollisionsbooleantrueWhether to prevent the content from overlapping with the viewport edges.
closeOnScrollbooleantrueWhether the menu should close when scrolling outside of it.
navigationUpKeys[] | Keys[][][]Custom key(s) to trigger upward navigation through menu items.
navigationDownKeys[] | Keys[][][]Custom key(s) to trigger downward navigation through menu items.
onEsc(e: Event) => voidevent handler for the Escape key press.
onOutsideInteraction(e: Event) => voidevent handler for clicks or focus outside the menu.
AttributesTypeDescription
data-stateopened | closedThe open state of the menu.

PopupMenuItem

PropTypeDefaultDescription
disabledbooleanfalsePrevents the item from being selected.
onClick(e: MenuItemClickEvent) => voidEvent handler called when the item is selected via click or keyboard.
closeOnClickbooleantrueWhether the menu should close after the item is selected.
AttributesTypeDescription
data-hoveredtrue | undefinedWhether the item is hovered.
data-focusedtrue | undefinedWhether the item is focused.
data-disabledtrue | undefinedWhether the item is disabled.

PopupSubMenuRoot

PropTypeDefaultDescription
openbooleanThe controlled open state of the sub-menu.
defaultOpenbooleanfalseThe initial open state when uncontrolled.
onOpenChange(open: boolean) => voidEvent handler called when the open state changes.
openStrategy'hover' | 'click' | 'both''both'How the sub-menu should be triggered.
delaynumber0The delay in milliseconds before the sub-menu opens on hover.

PopupSubMenuTrigger

PropTypeDefaultDescription
disabledbooleanfalsePrevents the item from being selected.
onClick(e: MenuItemClickEvent) => voidEvent handler called when the item is selected via click or keyboard.
AttributesTypeDescription
data-hoveredtrue | undefinedWhether the item is hovered.
data-focusedtrue | undefinedWhether the item is focused.
data-disabledtrue | undefinedWhether the item is disabled.

PopupSubMenuContent

The positioned container for the sub-menu's items. It has the same props as PopupMenuContent.

PopupMenuChoice

Used to group a set of PopupMenuChoiceItem components.

PropTypeDefaultDescription
mode'single' | 'multiple''single'Determines if one or multiple items can be selected.
defaultValuestring | string[]The initial value when uncontrolled.
onChange(value: string | string[]) => voidEvent handler called when the value changes.

PopupMenuChoiceItem

A selectable item within a PopupMenuChoice group.

PropTypeDescription
valuestringThe value of the item, used to identify it in the group.
AttributeTypeDescription
data-stateselected | unselectedThe state of the item.

PopupMenuChoiceIndicator

A component that displays a checkmark or other icon when its parent PopupMenuChoiceItem is selected. It will be hidden otherwise.

AttributeTypeDescription
data-stateselected | unselectedThe state of the item.

Other Components

  • PopupMenuArrow: An optional arrow component that can be placed inside PopupMenuContent to point towards the trigger.
  • PopupMenuGroup: A utility component to visually group items together.
  • PopupMenuLabel: A non-interactive label for a PopupMenuGroup.

Keywords

react

FAQs

Package last updated on 09 Oct 2025

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