Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

react-search-box-zn

rtaukir26402MIT1.0.14TypeScript support: included

React search input component that supports search & filter the data of an array of objects.

react, search, search input, react search, input field, filter, search box, react search component, search bar, custom search input

readme

react-search-input-box

A lightweight and customizable React search box component with:

  • ✅ Support for searching list
  • 🔍 Searchable, filterable options
  • ✨ Clean, flexible, and accessible UI

Demo

Demo

Installation

npm install react-search-box-zn
# or with pnpm
pnpm add react-search-box-zn

Import CSS

To apply default styles, import the CSS in your entry/root file:

import "react-search-box-zn/dist/index.css";

Usage in ReactJs

import React, { useState } from "react";
import ReactSearchBox from "react-search-box-zn";
import "react-search-box-zn/dist/index.css";


function App() {
const [data,setData]=useState([
  { name: "mango", price: "200" },
  { name: "apple", price: "160" },
  { name: "banana", price: "120" },
])
  const [result, setResult] = useState([]);

  return (
    <ReactSearchBox
      data={data}
      handleChange={(filteredData) => {
          console.log("Filtered data:", filteredData);
          setResult(filteredData)
        }}
      matchesWith={["name", "price"]}
      //optional
      styles={{
      backgroundColor: "#ddd",
      borderRadius: "50px",
      margin: "0px",
      padding: "10px",
      width: "400px",
    }}
    />
  );
}

export default App;

Props

Prop Type Default Description
data array [] Array of items to search (objects with any structure).
handleChange function null Callback function triggered when a user search.
matchesWith array ["name","price"] Keys in data objects to match user input against (e.g. ["name", "price"]).
searchLabel string "Search" Placeholder text shown in the search input field.
styles object {} Optional inline CSS styles for customizing the input container.