npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@octavian-tocan/react-dropdown

v1.1.0

Published

A flexible, composable dropdown (select) component system for React with TypeScript support

Readme

@octavian-tocan/react-dropdown

A flexible, composable dropdown (select) component system for React with TypeScript support. Built with accessibility in mind and featuring smooth animations powered by Motion (the latest version of Framer Motion).

Features

  • 🎯 Composable API - Mix and match components or use pre-made convenience components
  • 🔍 Searchable - Built-in search/filter functionality
  • Accessible - Proper ARIA attributes and keyboard navigation
  • 🎨 Customizable - Support for icons, descriptions, sections, and custom styling
  • 📱 Portal Support - Render dropdowns in portals to avoid overflow clipping
  • 🎭 Type-Safe - Full TypeScript support with generics
  • Performant - Optimized with React hooks and memoization

Installation

npm install @octavian-tocan/react-dropdown
# or
pnpm add @octavian-tocan/react-dropdown
# or
yarn add @octavian-tocan/react-dropdown

Peer Dependencies

This package requires:

  • react >= 18
  • react-dom >= 18
  • motion >= 12 (Motion for React - the latest version of Framer Motion)

Quick Start

Pre-made Searchable Dropdown

import Dropdown from '@octavian-tocan/react-dropdown';

function MyComponent() {
  const [selectedLanguage, setSelectedLanguage] = useState(null);

  const languages = [
    { code: 'en', name: 'English' },
    { code: 'es', name: 'Spanish' },
    { code: 'fr', name: 'French' },
  ];

  return (
    <Dropdown.Root
      items={languages}
      selectedItem={selectedLanguage}
      onSelect={setSelectedLanguage}
      getItemKey={(lang) => lang.code}
      getItemDisplay={(lang) => lang.name}
    >
      <Dropdown.Trigger displayValue={selectedLanguage?.name || ''} />
      <Dropdown.Searchable searchPlaceholder="Search languages..." />
    </Dropdown.Root>
  );
}

Simple Dropdown (No Search)

<Dropdown.Root items={priorities} {...config}>
  <Dropdown.Trigger displayValue={priority?.label || ''} />
  <Dropdown.Simple />
</Dropdown.Root>

Action Menu

import Dropdown from '@octavian-tocan/react-dropdown';
import { MoreHorizontal } from 'lucide-react';

function MenuExample() {
  const menuItems = [
    { id: '1', label: 'Edit', icon: <Edit />, onClick: handleEdit },
    { id: '2', label: 'Delete', icon: <Trash />, onClick: handleDelete, showSeparator: true },
  ];

  return (
    <Dropdown.Menu
      items={menuItems}
      trigger={<MoreHorizontal />}
      onSelect={(item) => item.onClick()}
      getItemKey={(item) => item.id}
      getItemDisplay={(item) => item.label}
      getItemIcon={(item) => item.icon}
      getItemSeparator={(item) => item.showSeparator ?? false}
    />
  );
}

API Reference

Compound Components

The package exports a compound component Dropdown with the following sub-components:

  • Dropdown.Root - Provider component that manages all state
  • Dropdown.Trigger - Button that opens/closes the dropdown
  • Dropdown.Content - Container for custom compositions
  • Dropdown.Search - Search input component
  • Dropdown.List - Scrollable list of options
  • Dropdown.Simple - Pre-made dropdown with list only
  • Dropdown.Searchable - Pre-made dropdown with search + list
  • Dropdown.Menu - Action menu variant

Hooks

  • useDropdownContext<T>() - Access dropdown context (throws if used outside Root)
  • useKeyboardNavigation<T>(items, getItemKey, onSelect, closeDropdown) - Keyboard navigation helpers
  • useClickOutside(ref, closeDropdown, isOpen) - Click outside detection

Types

All TypeScript types are exported. Key types include:

  • DropdownRootProps<T>
  • DropdownTriggerProps
  • DropdownListProps<T>
  • DropdownMenuProps<T>
  • DropdownContextValue<T>
  • DropdownSectionMeta
  • DropdownPlacement

Advanced Usage

Custom Composition

Build your own dropdown layout:

<Dropdown.Content>
  <CustomHeader />
  <Dropdown.Search placeholder="Filter..." />
  <Dropdown.List />
  <CustomFooter />
</Dropdown.Content>

Sections and Grouping

Group items into sections with headers:

<Dropdown.Root
  items={items}
  getItemSection={(item) => ({
    key: item.category,
    label: item.category,
    icon: '📁',
  })}
  // ...
>

Icons and Descriptions

Add icons and descriptions to items:

<Dropdown.Root
  items={items}
  getItemIcon={(item) => <Icon name={item.icon} />}
  getItemDescription={(item) => item.description}
  // ...
>

Portal Rendering

Render dropdown in a portal to avoid overflow clipping:

<Dropdown.Root
  items={items}
  usePortal={true}
  triggerRef={triggerRef}
  // ...
>

Placement Control

Control dropdown placement (top or bottom):

<Dropdown.Root
  items={items}
  dropdownPlacement="top"  // or "bottom" (default)
  // ...
>

Hiding Search for Small Lists

Hide search input for small lists:

<Dropdown.Searchable hideSearchThreshold={4} />

When items.length <= hideSearchThreshold, search is hidden.

Examples

See the Storybook stories for comprehensive examples covering:

  • Simple dropdowns
  • Searchable dropdowns
  • Action menus
  • Custom compositions
  • Sections and grouping
  • Icons and descriptions
  • Disabled items
  • Portal rendering
  • Placement options

Development

# Install dependencies
pnpm install

# Build
pnpm build

# Type check
pnpm typecheck

# Run tests
pnpm test

# Watch mode
pnpm dev

License

MIT

Repository

https://github.com/OctavianTocan/react-dropdown