Skip to main content

Dropdown

A floating container which will appear on clicking the dropdown button.

import { Dropdown } from "rizzui";

Default

A simple dropdown with component Dropdown.

import { Dropdown, Button } from "rizzui";

export default function App() {
return (
<Dropdown>
<Dropdown.Trigger>
<Button
as="span"
variant="outline"
>
Settings <ChevronDownIcon className="ml-2 w-5" />
</Button>
</Dropdown.Trigger>
<Dropdown.Menu>
<Dropdown.Item>Account Settings</Dropdown.Item>
<Dropdown.Item>Support</Dropdown.Item>
<Dropdown.Item>License</Dropdown.Item>
<Dropdown.Item>Sign Out</Dropdown.Item>
</Dropdown.Menu>
</Dropdown>
);
}

With Icons

You can use placement and icon.

import { Dropdown, Button, cn, ActionIcon } from "rizzui";
import {
AdjustmentsHorizontalIcon,
PencilIcon,
DocumentDuplicateIcon,
ArchiveBoxIcon,
ArrowRightCircleIcon,
ShareIcon,
HeartIcon,
TrashIcon,
} from "@heroicons/react/24/outline";

export default function App() {
return (
<Dropdown placement="bottom-end">
<Dropdown.Trigger>
<ActionIcon
variant="outline"
rounded="full"
>
<AdjustmentsHorizontalIcon className="h-5 w-5" />
</ActionIcon>
</Dropdown.Trigger>
<Dropdown.Menu className="divide-y">
<div className="mb-2">
<Dropdown.Item>
<PencilIcon className="mr-2 h-4 w-4" />
Edit
</Dropdown.Item>
<Dropdown.Item>
<DocumentDuplicateIcon className="mr-2 h-4 w-4" />
Duplicate
</Dropdown.Item>
</div>
<div className="mb-2 pt-2">
<Dropdown.Item>
<ArchiveBoxIcon className="mr-2 h-4 w-4" />
Archive
</Dropdown.Item>
<Dropdown.Item>
<ArrowRightCircleIcon className="mr-2 h-4 w-4" />
Move
</Dropdown.Item>
</div>
<div className="mb-2 pt-2">
<Dropdown.Item>
<ShareIcon className="mr-2 h-4 w-4" />
Share
</Dropdown.Item>
<Dropdown.Item>
<HeartIcon className="mr-2 h-4 w-4" />
Add to Favourite
</Dropdown.Item>
</div>
<div className="mt-2 pt-2">
<Dropdown.Item>
<TrashIcon className="mr-2 h-4 w-4" />
Delete
</Dropdown.Item>
</div>
</Dropdown.Menu>
</Dropdown>
);
}

With Avatar

The variation is limitless. You can style your Dropdown as you want to do.

import { Dropdown, Text, Avatar } from "rizzui";

export default function App() {
return (
<Dropdown placement="bottom-end">
<Dropdown.Trigger>
<Avatar
name="John Doe"
src="https://randomuser.me/api/portraits/women/40.jpg"
className="cursor-pointer"
/>
</Dropdown.Trigger>
<Dropdown.Menu className="w-56 divide-y text-gray-600">
<Dropdown.Item className="hover:bg-transparent">
<Avatar
name="John Doe"
src="https://randomuser.me/api/portraits/women/40.jpg"
/>
<span className="ml-2 text-start">
<Text className="text-gray-900 font-medium leading-tight">Mary Hoops</Text>
<Text>maryhe@demo.io</Text>
</span>
</Dropdown.Item>
<div className="mt-3 mb-2 pt-2">
<Dropdown.Item className="hover:bg-gray-900 hover:text-gray-50">
Account Settings
</Dropdown.Item>
<Dropdown.Item className="hover:bg-gray-900 hover:text-gray-50">Support</Dropdown.Item>
<Dropdown.Item className="hover:bg-gray-900 hover:text-gray-50">License</Dropdown.Item>
</div>
<div className="mt-2 pt-2">
<Dropdown.Item className="hover:bg-gray-900 hover:text-gray-50">Sign Out</Dropdown.Item>
</div>
</Dropdown.Menu>
</Dropdown>
);
}

API Reference


Here is the API documentation of the Dropdown component. You can use the following props to create a Dropdown.

PropsTypeDescriptionDefault
children__Use Dropdown.Trigger & Dropdown.Menu as childrens__
roundedDropdownRoundedThe rounded variants supported by this component are:"md"
shadowDropdownShadowsThe shadow variants supported by this component are:"md"
placementDropdownPlacementThe dropdown menu placements. Won't work if inPortal prop is false."bottom-start"
inPortalbooleanWhether the Dropdown.Menu is rendered on the portal or not"true"
modalbooleanWhether the body scrollbar is hidden or not when dropdown is visible."false"
gapnumberSets the gap between trigger and dropdown if portal is true"6"
classNamestringAdd classes to the main wrapper of this component__
PropsTypeDescriptionDefault
asdiv or buttonUse as to convert Dropdown.Trigger component to render as div or buttondiv
ref__Use ref prop to access DOM nodes of Dropdown.Trigger__
childrenReactNodeUse any valid React element or string__
classNamestringAdd classes to the Dropdown.Trigger wrapper__
...ButtonHTMLAttributes or HTMLAttributesnative props like onClick, title, aria-label ...__
PropsTypeDescriptionDefault
asdiv or ulUse as to convert Dropdown.Menu component to render as div or uldiv
childrenReactNodeUse Dropdown.Item and any valid React element__
classNamestringAdd classes to the Dropdown.Menu wrapper__
PropsTypeDescriptionDefault
asbutton or liUse as to convert Dropdown.Item component to render as button or libutton
childrenReactNodeUse any valid React element or sting__
disabledbooleanThis item will be skipped by keyboard navigationfalse
activeClassNamestringTo style active state of the Dropdown.Item__
disabledClassNamestringTo style disbale state of the Dropdown.Item__
classNamestringAdd classes to the Dropdown.Item__
...ButtonHTMLAttributes or HTMLAttributesnative props like onClick, title, aria-label ...__
type DropdownRounded = "sm" | "md" | "lg" | "xl" | "none";
type DropdownShadows = "sm" | "md" | "lg" | "xl" | "none";
type DropdownPlacements =
| "left"
| "right"
| "top"
| "bottom"
| "left-start"
| "left-end"
| "right-start"
| "right-end"
| "top-start"
| "top-end"
| "bottom-start"
| "bottom-end";