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 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-multi-search-select

v1.5.0

Published

A fully tested Typescript React component that shows a multi select searchable dropdown

Downloads

143

Readme

React Multi Search Select

A fully tested Typescript React component that shows a multi select searchable dropdown.

Installation

yarn add react-multi-search-select
npm install react-multi-search-select

Usage

import React, { FC, ReactElement } from 'react';
import { ReactMultiSearchSelect } from 'react-multi-search-select';
import "~react-multi-search-select/dist/index.css";

export const Component: FC = (): ReactElement => {
  const onChange = (selectedOptions: SelectedOption[]): void => {
    console.log(selectedOptions);
  };
  
  return (
    <>
      <ReactMultiSearchSelect options={["test", "test2", "test3"]} onChange={onChange} />

      <ReactMultiSearchSelect
        options={[{id: 1, name: "test"}, {id: 2, name: "test2"}, {id: 3, name: "test3"}]}
        optionsObject={{key: "id", value: "name"}}
        onChange={onChange}
      />
    </>
  );
}

Ref

React Multi Search Select has its own internal state. If you wish to update this internal state to match your own state, you can pass through a ref and call the setOptions() function.

import React, { FC, ReactElement } from 'react';
import { ReactMultiSearchSelect } from 'react-multi-search-select';
import "~react-multi-search-select/dist/index.css";

export const Component: FC = (): ReactElement => {
  const ref = useRef<ReactMultiSearchSelectRef>();

  const clear = (): void => ref.current.setOptions([]);

  return (
    <>
      <button onClick={clear}>Clear All Options</button>
      <ReactMultiSearchSelect
        options={["test", "test2", "test3"]}
        defaultValues={["test", "test2", "test3"]}
        ref={ref}
      />
    </>
  );
}

Props

| Prop | Type | Default | Description | |:--------- | :---- | :---- |:---- | | options | array (string or key value pair) | Required | Can either be an array of strings: ["test", "test2"] or an array of objects: [{ id: 1, name: "test}, { id: 2, name: "test2}]| | defaultValues | number[] or string[] | null | Default options when first loaded. This is either an array of strings or numbers that matches the key if using optionsObject| | optionsObject | object | null | The key and value to show when using an array of objects for options. For example: {key: "id", value: "name"}| | onChange | function | null | Function to call when the selected options are changed. Returns an array of either string or number defined by key if using optionsObject| | disabled | boolean | false | Disables search input| | loading | boolean | false | Disables search input and shows loading spinner| | selectionLimit | number | null | The amount of selected options before the search input is disabled and no more can be selected| | placeholderText | string | Select | Place holder text| | noOptionsText | string | There are no options | No options text| | caseSensitiveSearch | boolean | false | Sets if search is case sensitive| | ref | ReactMultiSearchSelectRef | null | Allows calling some functions to update the internal state|


Styling

You can override each class as needed. The names are "name spaced" so that they do not affect any of your styling. These are all the classes and what they do:

| Class | Description| |:--------- | :----| | react-multi-search-select-container | Container for the whole component| | react-multi-search-select-search-wrapper | Wrapper for the search input| | react-multi-search-select-loading | Container for loading elements| | react-multi-search-select-loading > span | Loading text| | react-multi-search-select-container input | Search input| | react-multi-search-select-container input:focus | Search input focus| | react-multi-search-select-selected-option | Selected options next to the search input| | react-multi-search-select-selected-option:hover | Selected options hover| | react-multi-search-select-options-container | List for options to select| | react-multi-search-select-options-container.hide | List when its inactive| | react-multi-search-select-options-container li | Option to select| | react-multi-search-select-options-container li:not(.no-hover):hover | No options text (for no hover effect)|


Licence

MIT