Skip to content

Dropdown Menu Primitive

Shows a menu with options or actions when a user clicks the trigger button.

Installation

Install the component via your command line.

Terminal window
npx expo install @rn-primitives/dropdown-menu

Usage

import * as React from 'react';
import * as DropdownMenuPrimitive from '@rn-primitives/dropdown-menu';
import { Text } from 'react-native';
function Example() {
const [checkboxValue, setCheckboxValue] = React.useState(false);
const [subCheckboxValue, setSubCheckboxValue] = React.useState(false);
const [radioValue, setRadioValue] = React.useState('pedro');
return (
<DropdownMenu.Root>
<DropdownMenu.Trigger>
<Text>
Open Dropdown Menu
</Text>
</DropdownMenu.Trigger>
<DropdownMenuPrimitive.Portal>
<DropdownMenuPrimitive.Overlay>
<DropdownMenu.Content>
<DropdownMenu.Item>
<Text>Back</Text>
</DropdownMenu.Item>
<DropdownMenu.Item>
<Text>Forward</Text>
</DropdownMenu.Item>
<DropdownMenu.Item>
<Text>Reload</Text>
</DropdownMenu.Item>
<DropdownMenu.Sub>
<DropdownMenu.SubTrigger>
<Text>More Tools</Text>
</DropdownMenu.SubTrigger>
<DropdownMenu.SubContent>
<DropdownMenu.Item>
<Text>Save Page As...</Text>
</DropdownMenu.Item>
<DropdownMenu.Item>
<Text>Create Shortcut...</Text>
</DropdownMenu.Item>
<DropdownMenu.Separator />
<DropdownMenu.Item>
<Text>Developer Tools</Text>
</DropdownMenu.Item>
</DropdownMenuSubContent>
</DropdownMenuSub>
<DropdownMenu.Separator />
<DropdownMenu.CheckboxItem
checked={checkboxValue}
onCheckedChange={setCheckboxValue}
closeOnPress={false}
>
<Text>Show Bookmarks Bar</Text>
</DropdownMenu.CheckboxItem>
<DropdownMenu.CheckboxItem
checked={subCheckboxValue}
onCheckedChange={setSubCheckboxValue}
closeOnPress={false}
>
<Text>Show Full URLs</Text>
</DropdownMenu.CheckboxItem>
<DropdownMenu.Separator />
<DropdownMenu.RadioGroup value={radioValue} onValueChange={setRadioValue}>
<DropdownMenu.Label>People</DropdownMenu.Label>
<DropdownMenu.Separator />
<DropdownMenu.RadioItem value='pedro' closeOnPress={false}>
<Text>Elmer Fudd</Text>
</DropdownMenu.RadioItem>
<DropdownMenu.RadioItem value='colm' closeOnPress={false}>
<Text>Foghorn Leghorn</Text>
</DropdownMenu.RadioItem>
</DropdownMenu.RadioGroup>
</DropdownMenu.Content>
</DropdownMenuPrimitive.Overlay>
</DropdownMenuPrimitive.Portal>
</DropdownMenu.Root>
);
}

Props

Root

Extends View props

PropTypeNote
onOpenChange(open: boolean) => void(optional)

Trigger

Extends Pressable props

PropTypeNote
asChildboolean(optional)

TYPE: DropdownMenuTriggerRef

MethodsargsNote
openopens the dropdown menu
closecloses the dropdown menu

Portal

PropTypeNote
children*React.ReactNode
forceMounttrue | undefined(optional)
hostNamestringWeb Only (optional)
containerHTMLElement | null | undefinedWeb Only (optional)

Overlay

Extends Pressable props

PropTypeNote
asChildboolean(optional)
forceMounttrue | undefined;(optional)

Content

Extends View props

PropTypeNote
asChildboolean(optional)
forceMounttrue | undefined(optional)
alignOffsetnumber(optional)
insetsInsets(optional)
avoidCollisionsboolean(optional)
align’start’ | ‘center’ | ‘end’(optional)
side’top’ | ‘bottom’(optional)
sideOffsetnumber(optional)
disablePositioningStylebooleanNative Only (optional)
loopbooleanWeb Only (optional)
onCloseAutoFocus(event: Event) => voidWeb Only (optional)
onEscapeKeyDown(event: KeyboardEvent) => voidWeb Only (optional)
onPointerDownOutside(event: PointerDownOutsideEvent) => voidWeb Only (optional)
onFocusOutside(event: FocusOutsideEvent) => voidWeb Only (optional)
onInteractOutsidePointerDownOutsideEvent | FocusOutsideEventWeb Only (optional)
collisionBoundaryElement | null | Array<Element | null>Web Only (optional)
sticky’partial’ | ‘always’Web Only (optional)
hideWhenDetachedbooleanWeb Only (optional)

Group

Extends Text props

PropTypeNote
asChildboolean(optional)

Label

Extends Text props

PropTypeNote
asChildboolean(optional)

Item

Extends Pressable props

PropTypeNote
asChildboolean(optional)
textValueboolean(optional)
closeOnPressboolean(optional)

CheckboxItem

Extends Pressable props

PropTypeNote
checked*boolean
onCheckedChange*(value: boolean) => void
textValue*string
asChildboolean(optional)
closeOnPressbooleanNative Only_(optional)_

RadioGroup

Extends View props

PropTypeNote
value*boolean
onValueChange*(value: boolean) => void
asChildboolean(optional)

RadioItem

Extends Pressable props

PropTypeNote
value*boolean
onCheckedChange*(value: boolean) => void
asChildboolean(optional)
closeOnPressbooleanNative Only_(optional)_

ItemIndicator

Extends View props

PropTypeNote
asChildboolean(optional)
forceMounttrue /undefined

Separator

Extends View props

PropTypeNote
asChildboolean(optional)
decorativeboolean(optional)

Sub

Extends View props

PropTypeNote
asChildboolean(optional)
defaultOpenboolean(optional)
openboolean(optional)
onOpenChange(value: boolean) => void(optional)

SubTrigger

Extends Pressable props

PropTypeNote
textValuestring(optional)
asChildboolean(optional)

SubContent

Extends Pressable props

PropTypeNote
asChildboolean(optional)
forceMounttrue /undefined

useRootContext

Must be used within a Root component. It provides the following values from the dropdown menu: open, and onOpenChange.

useSubContext

Must be used within a Sub component. It provides the following values from the dropdown menu: open, and onOpenChange.