Skip to content

Dropdown Menu

Dropdown Menu Primitive Text Component

Demo


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

Installation

Terminal window
npx @react-native-reusables/cli@latest add dropdown-menu

Usage

import * as React from 'react';
import Animated, { FadeIn } from 'react-native-reanimated';
import { Button } from '~/components/ui/button';
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuGroup,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuShortcut,
DropdownMenuSub,
DropdownMenuSubContent,
DropdownMenuSubTrigger,
DropdownMenuTrigger,
} from '~/components/ui/dropdown-menu';
import { Text } from '~/components/ui/text';
function Example() {
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant='outline'>
<Text>Open</Text>
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent insets={contentInsets} className='w-64 native:w-72'>
<DropdownMenuLabel>My Account</DropdownMenuLabel>
<DropdownMenuSeparator />
<DropdownMenuGroup>
<DropdownMenuItem>
<Text>Team</Text>
</DropdownMenuItem>
<DropdownMenuSub>
<DropdownMenuSubTrigger>
<Text>Invite users</Text>
</DropdownMenuSubTrigger>
<DropdownMenuSubContent>
<Animated.View entering={FadeIn.duration(200)}>
<DropdownMenuItem>
<Text>Email</Text>
</DropdownMenuItem>
<DropdownMenuItem>
<Text>Message</Text>
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem>
<Text>More...</Text>
</DropdownMenuItem>
</Animated.View>
</DropdownMenuSubContent>
</DropdownMenuSub>
<DropdownMenuItem>
<Text>New Team</Text>
<DropdownMenuShortcut>⌘+T</DropdownMenuShortcut>
</DropdownMenuItem>
</DropdownMenuGroup>
<DropdownMenuSeparator />
<DropdownMenuItem>
<Text>GitHub</Text>
</DropdownMenuItem>
<DropdownMenuItem>
<Text>Support</Text>
</DropdownMenuItem>
<DropdownMenuItem disabled>
<Text>API</Text>
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem>
<Text>Log out</Text>
<DropdownMenuShortcut>⇧⌘Q</DropdownMenuShortcut>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
);
}

Props

Extends View props

PropTypeNote
onOpenChange(value: boolean) => void
asChildboolean(optional)
relativeTo’longPress’ | ‘trigger’Native Only (optional)

Extends Pressable props

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

Extends View props

PropTypeNote
asChildboolean(optional)
overlayStyleStyleProp<ViewStyle>(optional)
overlayClassNamestring(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)

Extends Text props

PropTypeNote
asChildboolean(optional)

Extends Text props

PropTypeNote
asChildboolean(optional)

Extends Pressable props

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

Extends Pressable props

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

Extends View props

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

Extends Pressable props

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

Extends View props

PropTypeNote
asChildboolean(optional)
decorativeboolean(optional)

Extends View props

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

Extends Pressable props

PropTypeNote
textValuestring(optional)
asChildboolean(optional)

Extends Pressable props

PropTypeNote
asChildboolean(optional)
forceMounttrue /undefined

Extends Text props