React Dropdown Component

1.11.0 · abandoned · verified Sun Apr 19

React Dropdown is a simple, lightweight component designed for creating custom-styled dropdowns in React applications, currently at version 1.11.0. It addresses the styling limitations of native HTML `<select>` elements and supports grouped options, which are not easily achievable with standard HTML. Unlike more feature-rich libraries like `react-select`, this package prioritizes simplicity and customizability for basic dropdown needs, offering granular control over CSS classes for various parts of the component. While it has been stable, development appears to be inactive, with the last publish dating back over four years. It ships with TypeScript types and supports a wide range of React versions via peer dependencies, from 0.14.7 up to 18.0.0.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic usage with both flat and grouped options, state management, and custom class names.

import React, { useState } from 'react';
import Dropdown from 'react-dropdown';
import 'react-dropdown/style.css';

const options = [
  'one', 'two', 'three',
  { type: 'group', name: 'Group 1', items: [
    { value: 'four', label: 'Four' },
    { value: 'five', label: 'Five' }
  ]}
];

function MyDropdownComponent() {
  const [selectedOption, setSelectedOption] = useState(options[0]);

  const _onSelect = (option) => {
    setSelectedOption(option);
    console.log('Selected:', option.value);
  };

  return (
    <div className="dropdown-container">
      <h2>Basic Dropdown Example</h2>
      <Dropdown
        options={options}
        onChange={_onSelect}
        value={selectedOption}
        placeholder="Select an option"
        className="my-custom-dropdown"
        controlClassName="my-custom-control"
        menuClassName="my-custom-menu"
      />
      <p>Current selection: {selectedOption ? selectedOption.label || selectedOption : 'None'}</p>
    </div>
  );
}

export default MyDropdownComponent;

view raw JSON →