Skip to content
Harness Design System Harness Design System Harness Design System

DropdownMenu

The DropdownMenu component provides a way to create dropdown menus with various sub-components for customization.

Usage

import { DropdownMenu } from "@harnessio/ui/components";
//...
return (
<DropdownMenu.Root>
<DropdownMenu.Trigger aria-label="options menu">
<Icon name="menu-dots" />
</DropdownMenu.Trigger>
<DropdownMenu.Content>
<DropdownMenu.Item onSelect={onEdit}>Edit</DropdownMenu.Item>
<DropdownMenu.Item onSelect={onDelete}>Delete</DropdownMenu.Item>
</DropdownMenu.Content>
</DropdownMenu.Root>
)

Anatomy

All parts of the DropdownMenu component can be imported and composed as required.

<DropdownMenu.Root>
<DropdownMenu.Trigger />
<DropdownMenu.Content>
<DropdownMenu.Item />
<DropdownMenu.Item>
<DropdownMenu.Shortcut />
</DropdownMenu.Item>
<DropdownMenu.Group>
<DropdownMenu.Label />
<DropdownMenu.Item />
</DropdownMenu.Group>
<DropdownMenu.Separator />
<DropdownMenu.RadioGroup>
<DropdownMenu.Label />
<DropdownMenu.RadioItem />
</DropdownMenu.RadioGroup>
<DropdownMenu.Sub>
<DropdownMenu.SubTrigger />
<DropdownMenu.SubContent>
<DropdownMenu.Item />
</DropdownMenu.SubContent>
</DropdownMenu.Sub>
</DropdownMenu.Content>
</DropdownMenu.Root>

API Reference

Root

The Root component serves as the main container for all dropdown menu elements. It requires both a Trigger and Content as children. It can be used in either a controlled or uncontrolled manner. When used in a controlled manner, you must pass in the open and onOpenChange props. When used in an uncontrolled manner, the open state is stored internally.

<DropdownMenu.Root
className="my-class" // [OPTIONAL] custom class
open // [OPTIONAL] controlled open state
onOpenChange={onChange} // [OPTIONAL] event handler called when the open state changes
defaultOpen // [OPTIONAL] default open state
modal // [OPTIONAL] when set to true, interaction with outside elements
// will be disabled and only menu content will be
// visible to screen readers.
>
{/* Trigger and Content */}
</DropdownMenu.Root>
PropRequiredDefaultType
classNamefalsestring
openfalsefalseboolean
onOpenChangefalse(open: boolean) => void
defaultOpenfalsefalseboolean
modalfalsetrueboolean
childrentrueReactNode

Trigger

The Trigger component represents the button that triggers the dropdown menu.

<DropdownMenu.Trigger
className="my-class" // [OPTIONAL] custom class
insideSplitButton // [OPTIONAL] whether the trigger is inside a split button
asChild // [OPTIONAL] render the trigger as the child
>
{/* Trigger content */}
</DropdownMenu.Trigger>
PropRequiredDefaultType
classNamefalsestring
insideSplitButtonfalsefalseboolean
asChildfalseboolean
childrentrueReactNode

Content

The Content component represents the dropdown menu content.

<DropdownMenu.Content
className="my-class" // [OPTIONAL] custom class
sideOffset={4} // [OPTIONAL] offset on the side
>
{/* Item, Group, Separator, RadioGroup, Sub */}
</DropdownMenu.Content>
PropRequiredDefaultType
classNamefalsestring
sideOffsetfalse4number
childrentrueReactNode

Item

The Item component represents a dropdown menu item.

<DropdownMenu.Item
className="my-class" // [OPTIONAL] custom class
inset // [OPTIONAL] whether the item is inset
disabled // [OPTIONAL] disable the item
onSelect={onSelect} // [OPTIONAL] event handler called when the item is selected
textValue="text" // [OPTIONAL] text value of the item to be used for when value is not suitable for typeahead search
asChild // [OPTIONAL] render the item as the child
>
{/* Item content */}
</DropdownMenu.Item>
PropRequiredDefaultType
classNamefalsestring
insetfalsefalseboolean
disabledfalseboolean
onSelectfalse(value: string) => void
textValuefalsestring
asChildfalseboolean

Separator

The Separator component represents a dropdown menu separator.

<DropdownMenu.Separator
className="my-class" // [OPTIONAL] custom class
/>
PropRequiredDefaultType
classNamefalsestring

Sub

The Sub component can be used in a controlled or uncontrolled manner. When used in a controlled manner, you must pass in the open and onOpenChange props. When used in an uncontrolled manner, the open state is stored internally.

<DropdownMenu.Sub
open // [OPTIONAL] controlled open state
onOpenChange={onChange} // [OPTIONAL] event handler called when the open state changes
defaultOpen // [OPTIONAL] default open state
>
{/* SubTrigger and SubContent */}
</DropdownMenu.Sub>
PropRequiredDefaultType
openfalseboolean
onOpenChangefalse(open: boolean) => void
defaultOpenfalseboolean
childrentrueReactNode

SubTrigger

The SubTrigger component has the same props and behavior as the Trigger component above.

SubContent

The SubContent component has the same props and behavior as the Content component above.

Group

The Group component represents a dropdown menu group.

<DropdownMenu.Group
className="my-class" // [OPTIONAL] custom class
>
{/* Label, Item, etc */}
</DropdownMenu.Group>
PropRequiredDefaultType
classNamefalsestring
childrentrueReactNode

Label

The Label component represents a dropdown menu label.

<DropdownMenu.Label
className="my-class" // [OPTIONAL] custom class
>
{/* Label content */}
</DropdownMenu.Label>
PropRequiredDefaultType
classNamefalsestring
childrentrueReactNode

Shortcut

The Shortcut component visually represents the shortcut to press to activate the item.

<DropdownMenu.Item>
{/* Item content */}
<DropdownMenu.Shortcut
className="my-class" // [OPTIONAL] custom class
>
C
</DropdownMenu.Shortcut>
</DropdownMenu.Item>
PropRequiredDefaultType
childrentrueReactNode
classNamefalsestring

CheckboxItem

The CheckboxItem component displays a checkbox next to the item. When the user interacts with the checkbox, the onCheckedChange prop is called. Setting the checked prop will set whether the checkbox is checked.

<DropdownMenu.CheckboxItem
checked // [OPTIONAL] whether the checkbox is checked
onCheckedChange={onChange} // [OPTIONAL] callback called when the checked state changes
className="my-class" // [OPTIONAL] custom class
>
{/* Item content */}
</DropdownMenu.CheckboxItem>
PropRequiredDefaultType
checkedfalsefalseboolean
onCheckedChangefalse(checked: boolean) => void
classNamefalsestring
childrentrueReactNode

RadioGroup

The RadioGroup component groups together RadioItem components and controls the selected radio item.

<DropdownMenu.RadioGroup
value // [OPTIONAL] the selected radio item
onValueChange={onChange} // [OPTIONAL] callback called when the selected radio item changes
className="my-class" // [OPTIONAL] custom class
>
{/* RadioItem */}
</DropdownMenu.RadioGroup>
PropRequiredDefaultType
valuefalsestring
onValueChangefalse(value: string) => void
classNamefalsestring
childrentrueReactNode

RadioItem

The RadioItem component displays a radio button next to the item. When the user interacts with the radio button, the the onValueChange prop of the parent RadioGroup component is called with the value from the clicked RadioItem.

<DropdownMenu.RadioGroup
value={currentItem}
onValueChange={setCurrentItem}
>
<DropdownMenu.RadioItem
value="item-1" // value of the item
className="my-class" // [OPTIONAL] custom class
>
{/* Item content */}
</DropdownMenu.RadioItem>
</DropdownMenu.RadioGroup>
PropRequiredDefaultType
valuetruestring
classNamefalsestring
childrentrueReactNode