react搜索框组件 react-search-box

这篇博客介绍了如何在React应用中使用react-search-box组件来实现目录搜索功能。通过安装并导入组件,配置数据源,设置回调函数等步骤,可以创建一个具有占位符、自动聚焦、清除选择等功能的搜索框。示例代码展示了如何渲染组件并定义不同属性,如输入框样式和选中项的回调处理。

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值