@pikas-ui/dropdown-menu

This package contains a dropdown menu component that can be used to create a menu that opens when a user clicks on a trigger element.

This library is based on Radix Ui.

Change Log

Requirements

To use this package, you must install the @pikas-ui/styles package.

Installation

You can install this package using npm, yarn, or pnpm.

npm install @pikas-ui/dropdown-menu
yarn add @pikas-ui/dropdown-menu
pnpm add @pikas-ui/dropdown-menu

Usage

DropdownMenu

The component is used to create a menu that opens when a user clicks on a trigger element.

or
import { DropdownMenu } from '@pikas-ui/dropdown-menu';

const Example: React.FC = () => {
  return (
    <DropdownMenu
      data={[
        {
          label: 'Item 1',
          items: [
            {
              label: 'Item 1-1',
              type: 'item',
              onClick: console.log,
            },
            {
              type: 'checkbox',
              checked: true,
              label: 'Item 1-2',
              onCheckedChange: console.log,
              colorName: 'primary',
            },
            {
              type: 'radio',
              onValueChange: console.log,
              value: '1',
              radios: [
                {
                  label: 'Item 1-3-1',
                  value: '1',
                },
                {
                  label: 'Item 1-3-2',
                  value: '2',
                },
              ],
            },
            {
              type: 'menu',
              label: 'Item 1-4',
              data: [
                {
                  label: 'Item 1-4-1',
                  items: [
                    {
                      label: 'Item 1-4-1-1',
                      type: 'item',
                      onClick: console.log,
                    },
                  ],
                },
              ],
            },
          ],
        },
      ]}
    />
  );
};

Props

PropDescriptionTypeDefault
dataMenu dataMenuData-
cssCSS of dropdown menuDropdownMenuCSS-
triggerContentThe content of the triggerReactNode-
iconColorNameIcon color of trigger contentPikasColors-
iconSizeIcon size of trigger contentnumber24
directionThe direction of the menuDropdownMenuDirection-
modalThe modality of the context menu. When set to true, interaction with outside elements will be disabled and only menu content will be visible to screen readers. This prop is ignored within submenus.booleanfalse
defaultOpenThe default open state of the menubooleanfalse
openThe open state of the menuboolean-
onOpenChangeEvent handler called when the open state of the context menu changes.(open: boolean) => void-
loopWhen true, keyboard navigation will loop from last item to first, and vice versa.booleanfalse
onCloseAutoFocusEvent handler called when focus moves back after closing. It can be prevented by calling event.preventDefault. This prop is ignored within submenus.(event: Event) => void-
onEscapeKeyDownEvent handler called when the escape key is down. It can be prevented by calling event.(event: KeyboardEvent) => void-
onPointerDownOutsideEvent handler called when a pointer event occurs outside the bounds of the component. It can be prevented by calling event.preventDefault.() => void-
onFocusOutsideEvent handler called when focus moves outside the bounds of the component. It can be prevented by calling event.preventDefault.() => void-
onInteractOutsideEvent handler called when focus moves outside the bounds of the component. It can be prevented by calling event.preventDefault.() => void-
sideThe preferred side of the trigger to render against when open. Will be reversed when collisions occur and avoidCollisions is enabled. This prop is ignored within submenus.DropdownMenuSidetrue
sideOffsetThe horizontal distance in pixels from the anchor. This only applies within submenus.number-
alignThe preferred alignment against the trigger. May change when collisions occur. This prop is ignored within submenus.DropdownMenuAlign-
alignOffsetThe vertical distance in pixels from the anchor.number-
avoidCollisionsWhen true, overrides the side andalign preferences to prevent collisions with window edges.booleanfalse
collisionPaddingThe distance in pixels from window edges where collision detection should occur.number-
disabledWhen true, the menu will be disabled.booleanfalse

Contributing

This documentation can be edited on GitHub here