PeakUI

Dropdown

Dropdown menu triggered by a button

Usage

import {Dropdown} from "@peakui/react";

Anatomy

import {Button, Description, Dropdown, Kbd, Label, Separator} from "@peakui/react";

export default () => (
  <Dropdown>
    <Button>Actions</Button>
    <Dropdown.Popover>
      <Dropdown.Menu>
        <Dropdown.Item>
          <Label />
          <Description />
          <Kbd slot="keyboard" />
          <Dropdown.ItemIndicator />
        </Dropdown.Item>
        <Separator />
        <Dropdown.Section>
          <Dropdown.Item />
        </Dropdown.Section>
        <Dropdown.SubmenuTrigger>
          <Dropdown.Item>
            <Label />
            <Dropdown.SubmenuIndicator />
          </Dropdown.Item>
          <Dropdown.Popover>
            <Dropdown.Menu>
              <Dropdown.Item />
            </Dropdown.Menu>
          </Dropdown.Popover>
        </Dropdown.SubmenuTrigger>
      </Dropdown.Menu>
    </Dropdown.Popover>
  </Dropdown>
);

Examples

With Icons

With Descriptions

With Disabled Items

With Sections

With Single Selection

Single With Custom Indicator

With Multiple Selection

With Section Level Selection

With Keyboard Shortcuts

With Submenus

With Custom Submenu Indicator

Custom Trigger

Long Press Trigger

Controlled

Controlled Open State

Customization

Tailwind CSS

Global CSS

@layer components {
  .dropdown {
    @apply flex flex-col gap-1;
  }

  .dropdown__trigger {
    @apply outline-none;
  }

  .dropdown__popover {
    @apply rounded-lg border border-border bg-overlay p-2;
  }

  .dropdown__menu {
    @apply flex flex-col gap-1;
  }
}

Styling Reference

PeakUI follows the BEM methodology, so variants and states are plain class names you can target.

CSS Classes

The Dropdown component uses these CSS classes (view source styles):

Base Classes

  • .dropdown - Base dropdown container
  • .dropdown__trigger - The trigger rendered by Dropdown.Trigger
  • .dropdown__popover - The popover that holds the open menu
  • .dropdown__menu - The menu container inside the popover

Slots

  • [data-slot="dropdown-trigger"]
  • [data-slot="dropdown-popover"]
  • [data-slot="dropdown-menu"]
  • [data-slot="dropdown-submenu-trigger"]

Interactive States

The component supports both CSS pseudo-classes and data attributes:

  • Focus: :focus-visible or [data-focus-visible="true"] on the trigger
  • Disabled: :disabled or [aria-disabled="true"] on the trigger
  • Pending: [data-pending="true"] on the trigger
  • Pressed: :active or [data-pressed="true"] on the trigger
  • Entering: [data-entering="true"] on the popover
  • Exiting: [data-exiting="true"] on the popover

API Reference

PropTypeDefaultDescription
isOpenboolean-Sets the open state of the menu (controlled)
defaultOpenboolean-Sets the default open state of the menu (uncontrolled)
onOpenChange(isOpen: boolean) => void-Handler called when the open state changes
trigger"press" | "longPress""press"The type of interaction that triggers the menu
classNamestring-Additional CSS classes
childrenReactNode-Dropdown content
...restMenuTriggerProps-React Aria MenuTrigger attributes
PropTypeDefaultDescription
classNamestring-Additional CSS classes
childrenReactNode | RenderFunction-Trigger content or render function
...restButtonProps-React Aria Button attributes
PropTypeDefaultDescription
placement"bottom" | "bottom left" | "bottom right" | "bottom start" | "bottom end" | "top" | "top left" | "top right" | "top start" | "top end" | "left" | "left top" | "left bottom" | "start" | "start top" | "start bottom" | "right" | "right top" | "right bottom" | "end" | "end top" | "end bottom""bottom"Placement of the popover relative to the trigger
classNamestring-Additional CSS classes
childrenReactNode-Popover content
...restPopoverProps-React Aria Popover attributes
PropTypeDefaultDescription
selectionMode"single" | "multiple" | "none""none"Whether single or multiple selection is enabled
selectedKeysIterable<Key>-The currently selected keys (controlled)
defaultSelectedKeysIterable<Key>-The initial selected keys (uncontrolled)
onSelectionChange(keys: Selection) => void-Handler called when the selection changes
disabledKeysIterable<Key>-Keys of disabled items
onAction(key: Key) => void-Handler called when an item is activated
classNamestring-Additional CSS classes
childrenReactNode-Menu content
...restMenuProps<T>-React Aria Menu attributes
PropTypeDefaultDescription
selectionMode"single" | "multiple"-Selection mode for items within this section
selectedKeysIterable<Key>-The currently selected keys (controlled)
defaultSelectedKeysIterable<Key>-The initial selected keys (uncontrolled)
onSelectionChange(keys: Selection) => void-Handler called when the selection changes
disabledKeysIterable<Key>-Keys of disabled items
classNamestring-Additional CSS classes
childrenReactNode-Section content
...restMenuSectionProps-React Aria MenuSection attributes
PropTypeDefaultDescription
idKey-Unique identifier for the item
textValuestring-Text content of the item for typeahead
variant"default" | "danger""default"Visual variant of the item
isDisabledboolean-Whether the item is disabled
hrefstring-Renders the item as a link to this URL
classNamestring-Additional CSS classes
childrenReactNode | RenderFunction-Item content or render function
...restMenuItemProps-React Aria MenuItem attributes
PropTypeDefaultDescription
type"checkmark" | "dot""checkmark"Type of indicator to display
classNamestring-Additional CSS classes
childrenReactNode | RenderFunction-Custom indicator content or render function
PropTypeDefaultDescription
classNamestring-Additional CSS classes
childrenReactNode-Custom indicator content
PropTypeDefaultDescription
classNamestring-Additional CSS classes
childrenReactNode-Submenu trigger content
...restSubmenuTriggerProps-React Aria SubmenuTrigger attributes

Render Props

When using render functions with Dropdown.Item, these values are provided:

PropTypeDescription
isSelectedbooleanWhether the item is selected
isFocusedbooleanWhether the item is focused
isDisabledbooleanWhether the item is disabled
isPressedbooleanWhether the item is being pressed
hasSubmenubooleanWhether the item opens a submenu

When using render functions with Dropdown.ItemIndicator, these values are provided:

PropTypeDescription
isSelectedbooleanWhether the item is selected
isIndeterminatebooleanWhether the item is in an indeterminate state

On this page