当前位置: 首页 > 工具软件 > react-box > 使用案例 >

react搜索框组件 react-search-box

濮阳驰
2023-12-01

react-search-box 组件,实现目录搜索

Installation

# npm 
npm i react-search-box --save
 
# yarn 
yarn add react-search-box

Usage

import React, { Component } from "react";
import ReactSearchBox from "react-search-box";
 
export default class App extends Component {
  data = [
    {
      key: "john",
      value: "John Doe",
    },
    {
      key: "jane",
      value: "Jane Doe",
    },
    {
      key: "mary",
      value: "Mary Phillips",
    },
    {
      key: "robert",
      value: "Robert",
    },
    {
      key: "karius",
      value: "Karius",
    },
  ];
 
  render() {
    return (
      <ReactSearchBox
        placeholder="Placeholder"
        value="Doe"
        data={this.data}
        callback={(record) => console.log(record)}
      />
    );
  }
}

Props

PropDescription
placeholderThe placeholder text for the input box
dataAn array of objects which acts as the source of data for the dropdown. This prop is required
fuseConfigsConfigs to override default Fuse configs
autoFocusFocus on the input box once the component is mounted
clearOnSelectClear the input value when any record is selected
onSelectA function which acts as a callback when any record is selected. It is triggered once a dropdown item is clicked
onFocusA function which acts as a callback when the input is focussed
onChangeA function which acts as a callback when the input value is changed
inputFontColorColor of the text in the input box
inputBorderColorColor of the border of the input box
inputFontSizeSize of the font of the input box
inputHeightHeight of the input box
inputBackgroundColorBackground color of the input box
dropDownHoverColorBackground color on hover of the dropdown list items
dropDownBorderColorBorder color of the dropdown
leftIconIcon to be rendered on the left of the input box
iconBoxSizeThe size of the icon (based on the leftIcon prop)
typeThe type of the input
 类似资料: