DEV Community

Cover image for React Simple Select: A Lightweight and Customizable Select Component for React
NIXX/DEV
NIXX/DEV

Posted on

React Simple Select: A Lightweight and Customizable Select Component for React

When working on my projects, I often found existing React select components either too bloated, lacking proper accessibility, or difficult to customize. So, I decided to build React Simple Selectβ€”a lightweight, accessible, and highly customizable select component for React. It supports multi-select, async options, and full keyboard navigation. πŸš€

Why I Built This

I wanted a simple yet flexible select component that:

  • Is lightweight and doesn't come with unnecessary dependencies.
  • Supports multi-select without complex configurations.
  • Provides keyboard accessibility out of the box.
  • Can handle async options (e.g., fetching from an API).
  • Is customizable but also works with sensible defaults.

So I decided to create my own! Now, it's available for anyone to use and improve. πŸŽ‰

Features

  • βœ… Single and multi-select support
  • βœ… Async options support
  • βœ… Full keyboard navigation (Arrow keys, Enter, Escape)
  • βœ… Customizable styles and class names
  • βœ… Icon support for options
  • βœ… Click-outside detection to close dropdown

Installation

To start using @nixxy/react-simple-select, install it via npm or yarn:

npm install @nixxy/react-simple-select
# or
yarn add @nixxy/react-simple-select
Enter fullscreen mode Exit fullscreen mode

Usage Example

Here’s how you can use it in your React project:

import SimpleSelect, { Option } from '@nixxy/react-simple-select';
import '@nixxy/react-simple-select/assets/react-simple-select.css';
import { useState } from 'react';

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

export default function App() {
  const [selected, setSelected] = useState<Option | Option[] | null>(null);

  return (
    <div>
      <h2>Single-Select Example</h2>
      <SimpleSelect options={options} onChange={setSelected} placeholder="Choose a fruit..." />

      <h3>Selected:</h3>
      <pre>{JSON.stringify(selected, null, 2)}</pre>
    </div>
  );
}
Enter fullscreen mode Exit fullscreen mode

Multi-Select Example

<SimpleSelect options={options} onChange={setSelected} multiple placeholder="Choose fruits..." />
Enter fullscreen mode Exit fullscreen mode

Async Options Example

You can load options dynamically:

const fetchOptions = async () => {
  const response = await fetch('https://api.example.com/fruits');
  return response.json();
};

<SimpleSelect options={fetchOptions} onChange={setSelected} placeholder="Loading options..." />;
Enter fullscreen mode Exit fullscreen mode

What’s Next?

I plan to add:

  • βœ… Home/End key support to jump to first/last option
  • βœ… Shift + Arrow keys for multi-select

Try It Live!

You can check out the live demo here: Live Demo

Feedback & Contributions

I’d love to hear your thoughts! Try it out, report issues, or contribute on GitHub:

πŸ‘‰ GitHub Repo

If you find this useful, consider giving it a ⭐ on GitHub and sharing your feedback. πŸš€

Top comments (0)