New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-multi-select-advanced

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-multi-select-advanced

React multi select filter input with advanced features

  • 1.2.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
61
increased by3.39%
Maintainers
1
Weekly downloads
 
Created
Source

react-multi-select-advanced

Open Source Top Language MIT License Issues Minified Size Downloads Storybook

Description

The React Multi-select Advanced component is a powerful tool that can handle massive data sets without any struggle. It comes with various customizable features that make it very easy to use, so you can tailor it to your specific needs. Now it supports server side search.

Like Beyoncé once said, If you liked it, then you should a put a ⭐ on it. ➽ Stars

Features

  • Typescript: Types included, ensuring compatibility with your project.
  • Zero dependency: No need to worry about other libraries.
  • Powerful: Handles massive data sets without problem.
  • Responsive: Ensures that the component fit all device resolutions depending on parent component.
  • Customizable: Allow you to add custom class and change button, icons as components.
  • Auto direction: Ensures that list items open in the correct direction based on their placement on the page.
  • Localization: Easy to integrate any language.
  • Keyboard navigation: Supports keyboard arrows and tab.
  • Highlight keywords: Highlights entered text on list results.
  • Match priority: If label starts with keyword, shows first.
  • Server side search: Supports server side search.
  • Storybook : Document and test playground.

Getting Started

1. Installation

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

2. Basic Usage


import { useState } from 'react'

// Import component / and types if need it.
import MultiSelectAdvanced, { MultiSelectAdvancedOption } from 'react-multi-select-advanced'

// Mock data
const options = [
 { label: 'Istanbul', value: 'Istanbul' },
 { label: 'Paris', value: 'Paris' },
 { label: 'London', value: 'London' },
 { label: 'Buenos Aires', value: 'Buenos Aires' },
 { label: 'Canberra', value: 'Canberra' },
 { label: 'Havana', value: 'Havana' },
 { label: 'Helsinki', value: 'Helsinki', disabled: true },
 { label: 'Tokyo', value: 'Tokyo' },
 { label: 'Amsterdam', value: 'Amsterdam' },
 { label: 'Moscow', value: 'Moscow' },
 { label: 'Stockholm', value: 'Stockholm', disabled: true },
 { label: 'Singapore', value: 'Singapore' },
 { label: 'Lisbon', value: 'Lisbon' },
 { label: 'Oslo', value: 'Oslo' },
 { label: 'Reykjavík', value: 'Reykjavík' }
]

// Mock pre selected data
const selectedValues = [
 { label: 'London', value: 'London' },
 { label: 'Tokyo', value: 'Tokyo' }
]

// App
function App() {

 // Pre-select or not
 const [selectedItems, setSelectedItems] = useState(selectedValues as MultiSelectAdvancedOption[])

 // Onchange handler
 const handleChange = (items: MultiSelectAdvancedOption[]) => setSelectedItems(items)

 return (
  <div className="App">

   <MultiSelectAdvanced options={options} selectedValues={selectedItems} onChange={handleChange} />

  </div>
 )
}

export default App



import { useState } from 'react'

// Import component / and types if need it.
import MultiSelectAdvanced, { MultiSelectAdvancedOption } from 'react-multi-select-advanced'

// Mock data
const options = [
 { label: 'Istanbul', value: 'Istanbul' },
 { label: 'Paris', value: 'Paris' },
 { label: 'London', value: 'London' },
 { label: 'Buenos Aires', value: 'Buenos Aires' },
 { label: 'Canberra', value: 'Canberra' },
 { label: 'Havana', value: 'Havana' },
 { label: 'Helsinki', value: 'Helsinki', disabled: true },
 { label: 'Tokyo', value: 'Tokyo' },
 { label: 'Amsterdam', value: 'Amsterdam' },
 { label: 'Moscow', value: 'Moscow' },
 { label: 'Stockholm', value: 'Stockholm', disabled: true },
 { label: 'Singapore', value: 'Singapore' },
 { label: 'Lisbon', value: 'Lisbon' },
 { label: 'Oslo', value: 'Oslo' },
 { label: 'Reykjavík', value: 'Reykjavík' }
]

// App
function App() {

 // Pre-select or not
 const [selectedItems, setSelectedItems] = useState([] as MultiSelectAdvancedOption[])

 // Onchange handler
 const handleChange = (items: MultiSelectAdvancedOption[]) => setSelectedItems(items)

// Server side search function
const searchOnServer = async (keyword:string) => {
	try {
		// Before return the data make sure structure is matching with array of MultiSelectAdvancedOption
		return await search(keyword)
	} catch (error){
		return error
	}
}

// Mock server response
const search = async (keyword:string) => {
	return new Promise(resolve => {
		const filteredData = options.cities.filter(city => city.label.toLowerCase().includes(keyword.toLowerCase()))
		return setTimeout(() => resolve(filteredData), 500)
	})
}

 return (
  <div className="App">

   <MultiSelectAdvanced isServerSide={true} selectedValues={selectedItems} onChange={handleChange} onKeywordChange={keyword => searchOnServer(keyword)} />

  </div>
 )
}

export default App


4. Props

PropTypeDefaultDescription
classNamestringOptions data.
optionsarray[]Options data.
selectedValuesarray[]Pre-selected options.
Input
namestringautoinput name.
idstringautoinput id.
labelstringAdd label to top of input.
disabledbooleanDisables input and all actions.
invalidbooleanIf true border color turns to red.
inputDelaynumber1000Input delay (ms).
placeholderstringInput placeholder.
Filter
filterShowLoadingbooleantrueShow/hide loading indicator or component.
filterLimitnumberMaximum dropdown display limit.
filterHighlightKeywordbooleanfalseHighlights matching keyword. Suggested to use with filterLimit because of performance.
filterOrderByMatchRankbooleanfalseGives match score if label starts with search keyword. Suggested to use with filterLimit because of performance.
Selected Items
selectionLimitnumberLimits selected items.
hideInputOnSelectionLimitbooleanfalseHides input when selection limit reached
selectionMaxVisibleItemsnumberLimits selected display items and adds 'x more..' or MoreItemsComponent after items.
selectionLabelMaxWidthnumber100Limits max width (px) of display label and wrap with ellipsis.
selectionShowClearbooleanfalseShows clear all button after selected items if selected count more than 2.
selectionShowDeleteButtonbooleantrueShows remove button inside the selected items.
Language
languageOverwriteobjectPlease see 4. Localization.
Custom components
LoadingComponentJSX.ElementCustom loading indicator.
ClearButtonComponentJSX.ElementCustom clear all button.
DeleteButtonComponentJSX.ElementCustom delete button.
MoreItemsComponentJSX.ElementCustom more items.
Callback Type
isServerSidebooleanfalseEnables server side search.
Callback
onChangefunctionCallback function will invoked on selected options are changed.
onKeywordChangefunctionCallback function to pass keyword and accept data on return.

5. Localization

Easy to localize component by passing object to prop languageOverwrite. Default values are as below.

{
 selectionLimitReached : 'Max selection limit reached.',
 selectionShowClearTitle: 'Clear All',
 selectionDeleteTitle: 'Remove',
 moreItemsText: '{{count}} more items...'
}

6. License

MIT Licensed. Copyright © Lifetoweb 2022.


Happy coding 😊

Keywords

FAQs

Package last updated on 20 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc