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

react-bs-searchable-select

v1.0.0

Published

A searchable select dropdown component for React with Bootstrap styling — supports filtering, custom values, imperative methods, and full styling customization.

Readme

react-bs-searchable-select

A flexible, searchable dropdown select component for React with Bootstrap styling. Supports filtering, custom values, imperative methods, and full styling customization.

React Bootstrap License

Features

  • Search & Filter — Type to filter options (case-insensitive, matches anywhere in label)
  • Custom Values — Optionally allow users to enter values not in the list
  • Clearable — One-click clear button with optional disable
  • Imperative API — Programmatically get/set values, add/remove options via ref
  • Styling — Inline color props, CSS class overrides, or automatic Bootstrap theme integration
  • Validation — Built-in isInvalid prop for Bootstrap form validation

Installation

npm install react-bs-searchable-select

Peer Dependencies

This component requires the following packages (typically already in a React + Bootstrap project):

npm install react react-dom react-bootstrap react-icons

Quick Start

import { useState } from 'react';
import SearchableSelect from 'react-bs-searchable-select';

function App() {
  const [value, setValue] = useState(null);

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

  return (
    <SearchableSelect
      options={options}
      value={value}
      onChange={(val) => setValue(val)}
      placeholder="Select a fruit..."
    />
  );
}

Props

| Prop | Type | Default | Description | |------|------|---------|-------------| | options | Array<{ value: any, label: string }> | [] | Array of selectable options | | value | any | — | Currently selected value (controlled) | | onChange | (value, option) => void | — | Called on selection change; receives (null, null) when cleared | | placeholder | string | 'Select...' | Placeholder text | | maxDropdownHeight | number | 200 | Max dropdown height in pixels | | allowCustomValue | boolean | false | Allow values not in the options list | | isDisabled | boolean | false | Disable the component | | isClearable | boolean | true | Show/hide the clear (×) button | | isInvalid | boolean | false | Apply Bootstrap invalid styling | | activeBackgroundColor | string | var(--bs-primary, #0d6efd) | Background color of the selected item | | activeTextColor | string | #fff | Text color of the selected item | | activeClassName | string | — | CSS class for the selected item (overrides inline styles) | | inactiveBackgroundColor | string | — | Background color for unselected items | | inactiveTextColor | string | — | Text color for unselected items | | inactiveClassName | string | — | CSS class for unselected items (overrides inline styles) |

Imperative Methods

Access methods via a React ref:

import { useRef } from 'react';

const selectRef = useRef();

<SearchableSelect ref={selectRef} options={options} value={value} onChange={setValue} />

selectRef.current.setValue('apple');       // Select a value programmatically
selectRef.current.getValue();              // Get current value (selected or custom)
selectRef.current.isCustomValue();         // true if the value is custom text
selectRef.current.getInputText();          // Get raw input text
selectRef.current.clearSelection();        // Clear the selection
selectRef.current.addOption({ value: 'new', label: 'New Option' });  // Add option
selectRef.current.removeOption('apple');   // Remove option by value

| Method | Returns | Description | |--------|---------|-------------| | setValue(value) | void | Select a value from options (or set custom if allowCustomValue) | | getValue() | any | Returns selected value or custom text | | isCustomValue() | boolean | true if the value is not from the options list | | getInputText() | string | Returns current raw input text | | clearSelection() | void | Clears the selection | | addOption(option) | void | Adds { value, label } to options (ignores duplicates) | | removeOption(value) | void | Removes an option; clears selection if it was active |

Examples

Custom Values

const selectRef = useRef();

<SearchableSelect
  ref={selectRef}
  options={options}
  value={value}
  onChange={(val) => setValue(val)}
  allowCustomValue
  placeholder="Select or type a custom value..."
/>

// On form submit:
const currentValue = selectRef.current.getValue();
const isCustom = selectRef.current.isCustomValue();

Styling with Inline Colors

<SearchableSelect
  options={options}
  value={value}
  onChange={setValue}
  activeBackgroundColor="#28a745"
  activeTextColor="#fff"
  inactiveBackgroundColor="#f8f9fa"
  inactiveTextColor="#333"
/>

Styling with CSS Classes

<SearchableSelect
  options={options}
  value={value}
  onChange={setValue}
  activeClassName="my-active-item"
  inactiveClassName="my-inactive-item"
/>
.my-active-item {
  background-color: #6f42c1 !important;
  color: #fff !important;
  border-left: 3px solid #4a2a8a;
}
.my-inactive-item:hover {
  background-color: #e9ecef;
}

Form Validation

<SearchableSelect
  options={options}
  value={value}
  onChange={setValue}
  isInvalid={!!errors.field}
/>
{errors.field && (
  <Form.Control.Feedback type="invalid" style={{ display: 'block' }}>
    {errors.field}
  </Form.Control.Feedback>
)}

Non-Clearable Select

<SearchableSelect
  options={options}
  value={value}
  onChange={setValue}
  isClearable={false}
/>

Disabled State

<SearchableSelect
  options={options}
  value={value}
  onChange={setValue}
  isDisabled
/>

Bootstrap Theme Integration

The active item uses Bootstrap's primary color via CSS variable by default:

var(--bs-primary, #0d6efd)

If you customize $primary in your Bootstrap SCSS, the component picks it up automatically. No --bs-primary? It falls back to Bootstrap's default blue.

License

MIT © Hussein Al Bayati