React?程序設計簡單的輕量級自動完成搜索框應用
更新時間:2022年10月25日 15:22:10 作者:Jovie
這篇文章主要為大家介紹了React?程序設計簡單的輕量級自動完成搜索框應用,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
實現(xiàn)效果
一個為React應用程序設計的簡單的輕量級自動完成搜索框。
如何使用它
1.安裝并導入該組件
# Yarn $ yarn add react-search-box # NPM $ npm i react-search-box
import React, { Component } from "react"; import ReactSearchBox from "react-search-box";
2.將ReactSearchBox 組件添加到應用程序中
<ReactSearchBox placeholder="Type Something..." value="ReactScript" data={this.data} callback={(record) => console.log(record)} />
3.定義你的自動建議列表的數(shù)據(jù)
export default class App extends Component { data = [ { key: "react", value: "React Native", }, { key: "vue", value: "Vue Component", }, // ... ]; render() { return ( <ReactSearchBox placeholder="Type Something..." value="ReactScript" data={this.data} callback={(record) => console.log(record)} /> ); } }
4.所有可用的組件道具
/* * The placeholder text for the input box. */ placeholder: string; /* * The name attribute for the input box. */ name?: string; /* * An array of objects which acts as the source of data for the dropdown. This prop is required. */ data: { key: string; value: string }[]; /* * Configs to override default Fuse configs. */ fuseConfigs?: {}; /* * Focus on the input box once the component is mounted. */ autoFocus?: boolean; /* * A function which acts as a callback when any record is selected. It is triggered once a dropdown item is clicked. */ onSelect: (record: Record) => void; /* * A function which acts as a callback when the input is focussed. */ onFocus?: () => void; /* * A function which acts as a callback when the input value is changed. */ onChange: (value: string) => void; /* * Color of the text in the input box. */ inputFontColor?: string; /* * Color of the border of the input box. */ inputBorderColor?: string; /* * Size of the font of the input box. */ inputFontSize?: string; /* * Height of the input box. */ inputHeight?: string; /* * Background color of the input box. */ inputBackgroundColor?: string; /* * Background color on hover of the dropdown list items. */ dropdownHoverColor?: string; /* * Border color of the dropdown. */ dropdownBorderColor?: string; /* * Clear the input value when any record is selected. */ clearOnSelect?: boolean; /* * Icon to be rendered on the left of the input box. */ leftIcon?: ReactNode; /* * The size of the icon (based on the leftIcon prop). */ iconBoxSize?: number | string; /* * The type of the input. */ type?: string;
預覽
The postAutocomplete Search Box For Reactappeared first onReactScript.
以上就是React 程序設計簡單的輕量級自動完成搜索框應用的詳細內(nèi)容,更多關于React 輕量級自動搜索框的資料請關注腳本之家其它相關文章!
相關文章
React創(chuàng)建組件的三種方式及其區(qū)別是什么
在React中,創(chuàng)建組件的三種主要方式是函數(shù)式組件、類組件和使用React Hooks的函數(shù)式組件,本文就詳細的介紹一下如何使用,感興趣的可以了解一下2023-08-08詳解React中傳入組件的props改變時更新組件的幾種實現(xiàn)方法
這篇文章主要介紹了詳解React中傳入組件的props改變時更新組件的幾種實現(xiàn)方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-09-09React immer與Redux Toolkit使用教程詳解
這篇文章主要介紹了React中immer與Redux Toolkit的使用,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習吧2022-10-10ahooks useVirtualList 封裝虛擬滾動列表
這篇文章主要為大家介紹了ahooks useVirtualList 封裝虛擬滾動列表詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-09-09關于antd tree和父子組件之間的傳值問題(react 總結)
這篇文章主要介紹了關于antd tree 和父子組件之間的傳值問題,是小編給大家總結的一些react知識點,本文通過一個項目需求實例代碼詳解給大家介紹的非常詳細,需要的朋友可以參考下2021-06-06