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

selectra-react

v0.0.2

Published

A powerful, searchable multi-select dropdown component with tag support for React

Readme

Selectra React

A powerful, searchable multi-select dropdown component with tag support for React.

Created by Sayed Abdul Karim

npm version npm downloads license

Demo

Check out the live playground: https://selectra-playground-production.up.railway.app/

Features

  • Searchable dropdown with real-time filtering
  • Multi-select with tag/chip display
  • Nested/hierarchical options with expand/collapse
  • Keyboard navigation (Arrow keys, Enter, Escape, Backspace)
  • Fully accessible (ARIA attributes)
  • Grouped options support
  • Maximum selection limit
  • Customizable styling with CSS variables
  • Dark mode support
  • TypeScript support
  • Lightweight with zero dependencies

Installation

npm install selectra-react
yarn add selectra-react
pnpm add selectra-react

Quick Start

import { Selectra } from 'selectra-react'
import 'selectra-react/styles.css'

const options = [
  { value: 'apple', label: 'Apple' },
  { value: 'banana', label: 'Banana' },
  { value: 'cherry', label: 'Cherry' },
]

function App() {
  const [selected, setSelected] = useState([])

  return (
    <Selectra
      options={options}
      value={selected}
      onChange={setSelected}
      placeholder="Select fruits..."
    />
  )
}

Props

| Prop | Type | Default | Description | |------|------|---------|-------------| | options | SelectraOption[] | required | Array of options to display | | value | SelectraOption[] | - | Controlled selected values | | defaultValue | SelectraOption[] | [] | Initial selected values (uncontrolled) | | onChange | (selected: SelectraOption[]) => void | - | Called when selection changes | | placeholder | string | "Select..." | Placeholder text when empty | | searchPlaceholder | string | "Search..." | Placeholder for search input | | searchable | boolean | true | Enable search functionality | | clearable | boolean | true | Show clear all button | | disabled | boolean | false | Disable the component | | loading | boolean | false | Show loading state | | maxSelected | number | - | Maximum number of selections | | groupBy | boolean | false | Group options by group property | | nested | boolean | false | Enable nested/hierarchical options | | expandAllByDefault | boolean | false | Expand all nested options initially | | defaultExpandedKeys | string[] | [] | Keys of options to expand by default | | closeOnSelect | boolean | false | Close dropdown after selection | | noOptionsMessage | string | "No options found" | Message when no options match | | loadingMessage | string | "Loading..." | Message during loading | | className | string | - | Class for container | | dropdownClassName | string | - | Class for dropdown | | tagClassName | string | - | Class for tags | | renderOption | (option, isSelected) => ReactNode | - | Custom option renderer | | renderTag | (option, onRemove) => ReactNode | - | Custom tag renderer | | onSearch | (query: string) => void | - | Called on search input change | | onOpen | () => void | - | Called when dropdown opens | | onClose | () => void | - | Called when dropdown closes |

Option Type

interface SelectraOption {
  value: string
  label: string
  disabled?: boolean
  group?: string              // Used with groupBy prop
  children?: SelectraOption[] // Used with nested prop
  icon?: React.ReactNode      // Optional icon
}

Examples

Nested/Hierarchical Options

const categories = [
  {
    value: 'electronics',
    label: 'Electronics',
    children: [
      {
        value: 'phones',
        label: 'Phones',
        children: [
          { value: 'iphone', label: 'iPhone' },
          { value: 'samsung', label: 'Samsung Galaxy' },
        ],
      },
      { value: 'laptops', label: 'Laptops' },
    ],
  },
  { value: 'clothing', label: 'Clothing' },
]

<Selectra options={categories} nested expandAllByDefault />

Grouped Options

const options = [
  { value: 'react', label: 'React', group: 'Frontend' },
  { value: 'vue', label: 'Vue.js', group: 'Frontend' },
  { value: 'node', label: 'Node.js', group: 'Backend' },
  { value: 'python', label: 'Python', group: 'Backend' },
]

<Selectra options={options} groupBy />

Maximum Selection

<Selectra
  options={options}
  maxSelected={3}
  placeholder="Select up to 3..."
/>

Disabled Options

const options = [
  { value: 'available', label: 'Available' },
  { value: 'unavailable', label: 'Unavailable', disabled: true },
]

<Selectra options={options} />

Custom Rendering

<Selectra
  options={options}
  renderOption={(option) => (
    <div className="custom-option">
      <span className="icon">{option.icon}</span>
      <span>{option.label}</span>
    </div>
  )}
  renderTag={(option, onRemove) => (
    <span className="custom-tag">
      {option.label}
      <button onClick={onRemove}>×</button>
    </span>
  )}
/>

Styling

Selectra uses CSS variables for easy customization:

.selectra {
  --selectra-primary: #3b82f6;
  --selectra-primary-light: #eff6ff;
  --selectra-border: #d1d5db;
  --selectra-border-focus: #3b82f6;
  --selectra-bg: #ffffff;
  --selectra-bg-hover: #f3f4f6;
  --selectra-bg-highlighted: #eff6ff;
  --selectra-text: #111827;
  --selectra-text-muted: #6b7280;
  --selectra-tag-bg: #e5e7eb;
  --selectra-tag-text: #374151;
  --selectra-radius: 8px;
}

Dark Mode

Selectra automatically supports dark mode via prefers-color-scheme. You can also force a theme:

// Force dark mode
<Selectra className="selectra-dark" options={options} />

// Force light mode
<Selectra className="selectra-light" options={options} />

Keyboard Navigation

| Key | Action | |-----|--------| | | Open dropdown / Move to next option | | | Move to previous option | | | Expand nested option (when using nested prop) | | | Collapse nested option (when using nested prop) | | Enter | Select highlighted option / Toggle expand for parent nodes | | Escape | Close dropdown | | Backspace | Remove last selected tag (when search is empty) | | Tab | Close dropdown and move focus |

Hook Usage

For advanced use cases, you can use the useSelectra hook directly:

import { useSelectra } from 'selectra-react'

function CustomSelect(props) {
  const {
    state,
    refs,
    filteredOptions,
    flattenedOptions,
    actions,
  } = useSelectra(props)

  // Build your own UI
}

Author

Sayed Abdul Karim

License

MIT © Sayed Abdul Karim