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 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-mui-searchbox

v1.0.2

Published

A powerful, feature-rich search component for React applications built with Material UI. Perfect for implementing search functionality, autocomplete, filtering, and advanced selection capabilities in your React applications.

Downloads

8

Readme

npm version

MUI Search Component

A powerful, feature-rich search component for React applications built with Material UI. Perfect for implementing search functionality, autocomplete, filtering, and advanced selection capabilities in your React applications.

Features

  • Customizable styling - Complete control over colors, sizes, and appearance
  • Performance optimized - Built-in debounce and throttling capabilities
  • Fuzzy search - Powered by Fuse.js for intelligent search results
  • Autocomplete - Show suggestions as you type
  • Multiple selection mode - Support for multiple selections with chip display
  • Success state handling - Custom rendering after successful selection
  • Advanced filtering - Case-sensitive options, nested property access
  • Accessibility focused - Built on MUI components with accessibility in mind
  • Loading states - Built-in loading indicators
  • Static filtering method - Use filtering logic outside the component

📦 Installation

npm install react-mui-searchbox
# or
yarn add react-mui-searchbox

🔨 Quick Start

import React from 'react';
import { SearchBox } from 'react-mui-searchbox';
import PersonIcon from '@mui/icons-material/Person';

function App() {
  const data = [
    { id: 1, name: 'John Doe', email: '[email protected]' },
    { id: 2, name: 'Jane Smith', email: '[email protected]' },
    { id: 3, name: 'Robert Johnson', email: '[email protected]' },
    // More data...
  ];

  return (
    <div style={{ maxWidth: '500px', margin: '0 auto' }}>
      <h2>Search Users</h2>
      <SearchBox
        placeholder="Search users..."
        data={data}
        filterKeys={['name', 'email']}
        leftIcon={<PersonIcon />}
        onSelect={(item) => console.log('Selected:', item)}
        onChange={(value) => console.log('Search value:', value)}
        debounce={true}
        throttleTime={300}
        autoComplete={true}
        successComponent={(item) => (
          <div>Successfully selected: {item.name}</div>
        )}
      />
    </div>
  );
}

export default App;

📚 Props API

Input Props

| Prop | Type | Default | Description | |------|------|---------|-------------| | placeholder | string | 'Search...' | Placeholder text for the input | | value | string | '' | Initial value of the input | | autoFocus | boolean | false | Focus the input on mount | | className | string | '' | Additional CSS class | | type | string | 'text' | Input type |

Data Props

| Prop | Type | Default | Description | |------|------|---------|-------------| | data | array | [] | Array of objects to search through | | filterKeys | array | [] | Object keys to search within |

Style Props

| Prop | Type | Default | Description | |------|------|---------|-------------| | inputFontColor | string | 'inherit' | Color of input text | | inputBorderColor | string | 'primary.main' | Border color of input | | inputFontSize | number | 16 | Font size of input text | | inputHeight | number | 56 | Height of input field | | inputBackgroundColor | string | 'background.paper' | Background color of input | | dropDownHoverColor | string | 'action.hover' | Hover color for dropdown items | | dropDownBorderColor | string | 'divider' | Border color for dropdown | | chipColor | string | 'primary' | Color for selection chips in multiple selection mode |

Icon Props

| Prop | Type | Default | Description | |------|------|---------|-------------| | showSearchIcon | boolean | true | Show the search icon | | leftIcon | element | null | Custom icon to show on the left | | iconBoxSize | number | 24 | Size of the icon |

Function Props

| Prop | Type | Default | Description | |------|------|---------|-------------| | onChange | function | () => {} | Called when input value changes | | onSelect | function | () => {} | Called when an item is selected | | onFocus | function | () => {} | Called when input is focused | | onSuccess | function | () => {} | Called on successful selection |

Feature Flags

| Prop | Type | Default | Description | |------|------|---------|-------------| | debounce | boolean | true | Enable/disable debounce | | throttleTime | number | 200 | Debounce time in milliseconds | | caseSensitive | boolean | false | Enable case-sensitive search | | fuzzy | boolean | false | Enable fuzzy search | | sortResults | boolean | false | Sort results by relevance (fuzzy search only) | | clearOnSelect | boolean | false | Clear input after selection | | autoComplete | boolean | true | Show dropdown on focus | | multipleChip | boolean | false | Enable multiple selection with chips |

Other Props

| Prop | Type | Default | Description | |------|------|---------|-------------| | successComponent | function | null | Component to render after selection | | fuseConfigs | object | {} | Additional Fuse.js configurations |

📋 Advanced Usage

Multiple Selection with Chips

<SearchBox
  placeholder="Select multiple users..."
  data={users}
  filterKeys={['name', 'email']}
  multipleChip={true}
  chipColor="success"
  onSelect={(selectedItems) => console.log('Selected items:', selectedItems)}
/>

Custom Styling

<SearchBox
  placeholder="Search products..."
  data={products}
  filterKeys={['name', 'description', 'category.name']}
  inputBorderColor="secondary.main"
  inputFontSize={14}
  inputHeight={48}
  inputBackgroundColor="#f5f5f5"
  dropDownHoverColor="#e0e0e0"
/>

Fuzzy Search with Custom Configuration

<SearchBox
  placeholder="Search documents..."
  data={documents}
  filterKeys={['title', 'content', 'tags']}
  fuzzy={true}
  sortResults={true}
  fuseConfigs={{
    threshold: 0.3,
    distance: 100,
    useExtendedSearch: true
  }}
/>

Success State Handling

<SearchBox
  placeholder="Select a country..."
  data={countries}
  filterKeys={['name']}
  successComponent={(country) => (
    <div className="selected-country">
      <h3>{country.name}</h3>
      <p>Capital: {country.capital}</p>
      <p>Population: {country.population.toLocaleString()}</p>
    </div>
  )}
/>

Static Methods

SearchBox.filter(searchTerm, keys, options)

Returns a function that can be used to filter an array outside the component.

const filterFunc = SearchBox.filter('john', ['name', 'email'], { 
  fuzzy: true, 
  caseSensitive: false 
});

const filteredData = filterFunc(data);

License

MIT

🤝 Contributing

Contributions, issues and feature requests are welcome! Feel free to check issues page.