UI Logo

UI

Dropdown

A dropdown menu component for selecting options.

'use client';

import React from 'react';
import * as DropdownMenu from '@radix-ui/react-dropdown-menu';
import { ChevronDownIcon } from '@radix-ui/react-icons';

const DropdownMenuDemo = () => (
  <DropdownMenu.Root>
    <DropdownMenu.Trigger className="DropdownMenuTrigger">
      Homeschool Resources
      <ChevronDownIcon className="DropdownMenuChevron" aria-hidden />
    </DropdownMenu.Trigger>

    <DropdownMenu.Content className="DropdownMenuContent">
      <DropdownMenuItem>Math Resources</DropdownMenuItem>
      <DropdownMenuItem>Science Projects</DropdownMenuItem>
      <DropdownMenuItem>History Lessons</DropdownMenuItem>
    </DropdownMenu.Content>
  </DropdownMenu.Root>
);

interface DropdownMenuItemProps extends React.ComponentPropsWithoutRef<typeof DropdownMenu.Item> {
  children: React.ReactNode;
  className?: string;
}

const DropdownMenuItem = React.forwardRef<HTMLDivElement, DropdownMenuItemProps>(
  ({ children, className, ...props }, forwardedRef) => (
    <DropdownMenu.Item
      className={`DropdownMenuItem ${className || ''}`}
      {...props}
      ref={forwardedRef}
    >
      {children}
    </DropdownMenu.Item>
  )
);

export default DropdownMenuDemo;

Installation

Copy and paste the following code into your project.

Update the import paths to match your project setup.

Anatomy

Import all parts and piece them together.

import Dropdown from "@/components/ui/dropdown"
<Dropdown options={[{ value: '1', label: 'One' }]} onChange={() => {}} />

Props

Options

Options

  • Array of options

Placeholder

Placeholder

  • string